From: erik Date: Fri, 4 Apr 2008 19:06:35 +0000 (+0000) Subject: ProvidedInterfaceDescriptor no longer extends InterfaceDescriptor. X-Git-Tag: wamblee-utils-0.2~1^2~203 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=d75feb16e2143660c69bcf8073fcd8a83cf49f5b;p=utils ProvidedInterfaceDescriptor no longer extends InterfaceDescriptor. --- diff --git a/system/general/src/main/java/org/wamblee/system/AbstractInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/AbstractProvidedInterfaceDescriptor.java similarity index 77% rename from system/general/src/main/java/org/wamblee/system/AbstractInterfaceDescriptor.java rename to system/general/src/main/java/org/wamblee/system/AbstractProvidedInterfaceDescriptor.java index 361cd2ec..2d60e34e 100644 --- a/system/general/src/main/java/org/wamblee/system/AbstractInterfaceDescriptor.java +++ b/system/general/src/main/java/org/wamblee/system/AbstractProvidedInterfaceDescriptor.java @@ -7,7 +7,7 @@ import java.util.Arrays; * * @author Erik Brakkee */ -public abstract class AbstractInterfaceDescriptor implements InterfaceDescriptor { +public class AbstractProvidedInterfaceDescriptor implements ProvidedInterfaceDescriptor { private String _name; private Class[] _interfaces; @@ -16,12 +16,12 @@ public abstract class AbstractInterfaceDescriptor implements InterfaceDescriptor * Constructs the descriptor. * @param aInterface Type of service. */ - public AbstractInterfaceDescriptor(String aName, Class aInterface) { + public AbstractProvidedInterfaceDescriptor(String aName, Class aInterface) { _name = aName; _interfaces = new Class[] { aInterface }; } - public AbstractInterfaceDescriptor(String aName, Class[] aInterfaces) { + public AbstractProvidedInterfaceDescriptor(String aName, Class[] aInterfaces) { _name = aName; _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length); } @@ -38,10 +38,10 @@ public abstract class AbstractInterfaceDescriptor implements InterfaceDescriptor @Override public boolean equals(Object obj) { - if ( !(obj instanceof AbstractInterfaceDescriptor)) { + if ( !(obj instanceof AbstractProvidedInterfaceDescriptor)) { return false; } - AbstractInterfaceDescriptor descr = (AbstractInterfaceDescriptor)obj; + AbstractProvidedInterfaceDescriptor descr = (AbstractProvidedInterfaceDescriptor)obj; if ( _interfaces.length != descr._interfaces.length ) { return false; } diff --git a/system/general/src/main/java/org/wamblee/system/Container.java b/system/general/src/main/java/org/wamblee/system/Container.java index 158c0a06..ee3a0535 100644 --- a/system/general/src/main/java/org/wamblee/system/Container.java +++ b/system/general/src/main/java/org/wamblee/system/Container.java @@ -52,7 +52,7 @@ public class Container extends AbstractComponent { required.addAll(Arrays.asList(system.getRequiredServices())); } - for (InterfaceDescriptor service : getProvidedServices()) { + for (ProvidedInterfaceDescriptor service : getProvidedServices()) { if (!(provided.contains(service))) { throw new SystemAssemblyException(getName() + ": Service '" + service + "' is not provided by any of the subsystems"); diff --git a/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java deleted file mode 100644 index 97e62da6..00000000 --- a/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.wamblee.system; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - - -public class DefaultProvidedInterfaceDescriptor extends AbstractInterfaceDescriptor implements - ProvidedInterfaceDescriptor { - - public DefaultProvidedInterfaceDescriptor(String aName, Class aInterface) { - super(aName, aInterface); - } - - public DefaultProvidedInterfaceDescriptor(String aName, Class[] aInterface) { - super(aName, aInterface); - } - -} diff --git a/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java index fbee3155..a6e85bc5 100644 --- a/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java +++ b/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java @@ -1,6 +1,6 @@ package org.wamblee.system; -public class DefaultRequiredInterfaceDescriptor extends AbstractInterfaceDescriptor +public class DefaultRequiredInterfaceDescriptor extends AbstractProvidedInterfaceDescriptor implements RequiredInterfaceDescriptor { public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) { diff --git a/system/general/src/main/java/org/wamblee/system/InterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/InterfaceDescriptor.java deleted file mode 100644 index 987a8595..00000000 --- a/system/general/src/main/java/org/wamblee/system/InterfaceDescriptor.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.wamblee.system; - -/** - * Service descriptor providing a description and characteristics - * of the provided service. - * - * NOTE: The current implemention only stores the type of the - * descriptor but his can be extended towards more complex rules - * for matching services. - * - * Implementations must implement {@link #equals(Object)} and {@link #hashCode()}. - * - * @author Erik Brakkee - */ -public interface InterfaceDescriptor { - - /** - * Symbolic name for the service as used by the subsystem. - * @return Service name. - */ - String getName(); - - /** - * Returns the service type. - * @return Service type. - */ - Class[] getInterfaceTypes(); -} diff --git a/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java b/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java index 1af949c9..9afe3752 100644 --- a/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java +++ b/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java @@ -2,6 +2,22 @@ package org.wamblee.system; import java.util.Collection; -public interface ProvidedInterfaceDescriptor extends InterfaceDescriptor { - // Empty +/** + * Represents an interface provided by a component. + * + * @author Erik Brakkee + */ +public interface ProvidedInterfaceDescriptor { + + /** + * Symbolic name for the service as used by the subsystem. + * @return Service name. + */ + String getName(); + + /** + * Returns the service type. + * @return Service type. + */ + Class[] getInterfaceTypes(); } diff --git a/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java b/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java index dd3451db..7f9dc933 100644 --- a/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java +++ b/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java @@ -7,25 +7,25 @@ import junit.framework.TestCase; public class DefaultInterfaceDescriptorTest extends TestCase { public void testOneRequiredOneProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class); + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", String.class); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedMatchSubClass() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class); + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", Integer.class); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedNoMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class); + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", String.class); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class); assertFalse(required.implementedBy(provided)); } public void testOneRequiredMultipleProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", new Class[] { String.class, Integer.class} ); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class); assertTrue(required.implementedBy(provided)); @@ -39,7 +39,7 @@ public class DefaultInterfaceDescriptorTest extends TestCase { } public void testMultipleRequiredOneProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", MyMultiple.class ); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", new Class[] {Runnable.class, Serializable.class} ); @@ -47,7 +47,7 @@ public class DefaultInterfaceDescriptorTest extends TestCase { } public void testMultipleRequiredOneProvidedNoMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", MyMultiple.class ); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", new Class[] { String.class, Runnable.class} ); @@ -55,7 +55,7 @@ public class DefaultInterfaceDescriptorTest extends TestCase { } public void testMultipleRequiredMultipleProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", new Class[] { Runnable.class, Serializable.class, String.class} ); RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", new Class[] {Runnable.class, Serializable.class} ); diff --git a/system/general/src/test/java/org/wamblee/system/Environment.java b/system/general/src/test/java/org/wamblee/system/Environment.java index ebc43265..6c9512ca 100644 --- a/system/general/src/test/java/org/wamblee/system/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/Environment.java @@ -7,8 +7,8 @@ public class Environment extends AbstractComponent { private static final ProvidedInterfaceDescriptor[] PROVIDED = new ProvidedInterfaceDescriptor[] { - new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class), - new DefaultProvidedInterfaceDescriptor("integer", Integer.class) + new AbstractProvidedInterfaceDescriptor("datasource", DataSource.class), + new AbstractProvidedInterfaceDescriptor("integer", Integer.class) }; public Environment(ServiceRegistry aRegistry) { diff --git a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java index 7b3ea273..810ff4c7 100644 --- a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java +++ b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java @@ -31,11 +31,11 @@ public class SystemAssemblerTest extends TestCase { "name", Runnable.class); RequiredInterfaceDescriptor req2 = new DefaultRequiredInterfaceDescriptor( "name", Serializable.class); - ProvidedInterfaceDescriptor prov1 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterfaceDescriptor prov1 = new AbstractProvidedInterfaceDescriptor( "name", Runnable.class); - ProvidedInterfaceDescriptor prov2 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterfaceDescriptor prov2 = new AbstractProvidedInterfaceDescriptor( "name", Serializable.class); - ProvidedInterfaceDescriptor prov3 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterfaceDescriptor prov3 = new AbstractProvidedInterfaceDescriptor( "name", MyMultiple.class); AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 }, @@ -109,7 +109,7 @@ public class SystemAssemblerTest extends TestCase { system.start("root", new Service[0]); RequiredInterfaceDescriptor[] required = system.getRequiredServices(); assertEquals(0, required.length); - InterfaceDescriptor[] provided = system.getProvidedServices(); + ProvidedInterfaceDescriptor[] provided = system.getProvidedServices(); assertEquals(0, provided.length); assertEquals(Status.RUNNING, environment.getStatus()); assertEquals(Status.RUNNING, application.getStatus()); @@ -129,7 +129,7 @@ public class SystemAssemblerTest extends TestCase { "all", _registry, new Component[] { environment, application }, - new ProvidedInterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor( + new ProvidedInterfaceDescriptor[] { new AbstractProvidedInterfaceDescriptor( "string", String.class) }, new DefaultRequiredInterfaceDescriptor[0]); } catch (SystemAssemblyException e) { diff --git a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java index dc7a5845..c02f951a 100644 --- a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java +++ b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java @@ -8,8 +8,8 @@ import java.util.Properties; import junit.framework.TestCase; import org.wamblee.io.ClassPathResource; -import org.wamblee.system.AbstractInterfaceDescriptor; -import org.wamblee.system.DefaultProvidedInterfaceDescriptor; +import org.wamblee.system.AbstractProvidedInterfaceDescriptor; +import org.wamblee.system.AbstractProvidedInterfaceDescriptor; import org.wamblee.system.DefaultRequiredInterfaceDescriptor; import org.wamblee.system.DefaultServiceRegistry; import org.wamblee.system.ProvidedInterfaceDescriptor; @@ -48,7 +48,7 @@ public class SpringComponentTest extends TestCase { public void testOneProvidedService() { Map provided = new HashMap(); - provided.put("helloService", new DefaultProvidedInterfaceDescriptor( + provided.put("helloService", new AbstractProvidedInterfaceDescriptor( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", _registry, @@ -65,7 +65,7 @@ public class SpringComponentTest extends TestCase { public void testWithProperties() throws IOException { Map provided = new HashMap(); - provided.put("helloService", new DefaultProvidedInterfaceDescriptor( + provided.put("helloService", new AbstractProvidedInterfaceDescriptor( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML }, @@ -103,7 +103,7 @@ public class SpringComponentTest extends TestCase { new HashMap(), required); HelloService helloObject = new HelloService("ladida"); - Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject); + Service helloService = _registry.register(new AbstractProvidedInterfaceDescriptor("hello", HelloService.class), helloObject); system.start("Bla", new Service[] { helloService } ); system.stop(); } @@ -113,7 +113,7 @@ public class SpringComponentTest extends TestCase { required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class), "helloService"); Map provided = new HashMap(); - provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla", + provided.put("blaService", new AbstractProvidedInterfaceDescriptor("bla", BlaService.class)); SpringComponent system = new SpringComponent("system", _registry, @@ -121,7 +121,7 @@ public class SpringComponentTest extends TestCase { provided, required); HelloService helloObject = new HelloService("ladida"); - Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject); + Service helloService = _registry.register(new AbstractProvidedInterfaceDescriptor("hello", HelloService.class), helloObject); Service[] services = system.start("Bla", new Service[] { helloService } ); assertEquals(1, services.length);