From: erik Date: Fri, 4 Apr 2008 19:09:48 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2@603~198 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=a3174838834580b0e66e103597562c68b0ebf38b;p=utils --- diff --git a/trunk/system/general/src/main/java/org/wamblee/system/AbstractComponent.java b/trunk/system/general/src/main/java/org/wamblee/system/AbstractComponent.java index 885cad6e..a78b46f1 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/AbstractComponent.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/AbstractComponent.java @@ -21,9 +21,9 @@ public abstract class AbstractComponent implements Component { private Status _status; private String _name; private ServiceRegistry _registry; - private List _provided; - private List _required; - private Map _running; + private List _provided; + private List _required; + private Map _running; /** * Constructs the subsystem. @@ -37,16 +37,16 @@ public abstract class AbstractComponent implements Component { * @param aRequired * Required services. */ - protected AbstractComponent(String aName, ServiceRegistry aRegistry, ProvidedInterfaceDescriptor[] aProvided, - RequiredInterfaceDescriptor[] aRequired) { + protected AbstractComponent(String aName, ServiceRegistry aRegistry, ProvidedInterface[] aProvided, + RequiredInterface[] aRequired) { _status = Status.NOT_STARTED; _name = aName; _registry = aRegistry; - _provided = new ArrayList(); + _provided = new ArrayList(); _provided.addAll(Arrays.asList(aProvided)); - _required = new ArrayList(); + _required = new ArrayList(); _required.addAll(Arrays.asList(aRequired)); - _running = new HashMap(); + _running = new HashMap(); } @Override @@ -64,13 +64,13 @@ public abstract class AbstractComponent implements Component { } @Override - public final ProvidedInterfaceDescriptor[] getProvidedServices() { - return _provided.toArray(new ProvidedInterfaceDescriptor[0]); + public final ProvidedInterface[] getProvidedServices() { + return _provided.toArray(new ProvidedInterface[0]); } @Override - public final RequiredInterfaceDescriptor[] getRequiredServices() { - return _required.toArray(new RequiredInterfaceDescriptor[0]); + public final RequiredInterface[] getRequiredServices() { + return _required.toArray(new RequiredInterface[0]); } @Override @@ -102,7 +102,7 @@ public abstract class AbstractComponent implements Component { * Service. */ protected final void addService(String aContext, - ProvidedInterfaceDescriptor aDescriptor, Object aService) { + ProvidedInterface aDescriptor, Object aService) { LOG.info(aContext + ": service '" + aService + "' started."); Service svc = getRegistry().register(aDescriptor, aService); _running.put(svc.getDescriptor(), svc); diff --git a/trunk/system/general/src/main/java/org/wamblee/system/Component.java b/trunk/system/general/src/main/java/org/wamblee/system/Component.java index afbed94c..e72dd7f0 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/Component.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/Component.java @@ -28,13 +28,13 @@ public interface Component { * Gets a description of the provided interfaces. * @return Provided interfaces. */ - ProvidedInterfaceDescriptor[] getProvidedServices(); + ProvidedInterface[] getProvidedServices(); /** * Gets a description of the required interfaces. * @return Required interfaces. */ - RequiredInterfaceDescriptor[] getRequiredServices(); + RequiredInterface[] getRequiredServices(); /** diff --git a/trunk/system/general/src/main/java/org/wamblee/system/Container.java b/trunk/system/general/src/main/java/org/wamblee/system/Container.java index ee3a0535..a23a7373 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/Container.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/Container.java @@ -29,7 +29,7 @@ public class Container extends AbstractComponent { * @param aRequired Required services by the system. */ public Container(String aName, ServiceRegistry aRegistry, Component[] aSystems, - ProvidedInterfaceDescriptor[] aProvided, RequiredInterfaceDescriptor[] aRequired) { + ProvidedInterface[] aProvided, RequiredInterface[] aRequired) { super(aName, aRegistry, aProvided, aRequired); _systems = aSystems; validate(); @@ -42,24 +42,24 @@ public class Container extends AbstractComponent { * Also logs a warning in case of superfluous requirements. */ private void validate() { - List provided = new ArrayList(); + List provided = new ArrayList(); for (Component system : _systems) { provided.addAll(Arrays.asList(system.getProvidedServices())); } - List required = new ArrayList(); + List required = new ArrayList(); for (Component system : _systems) { required.addAll(Arrays.asList(system.getRequiredServices())); } - for (ProvidedInterfaceDescriptor service : getProvidedServices()) { + for (ProvidedInterface service : getProvidedServices()) { if (!(provided.contains(service))) { throw new SystemAssemblyException(getName() + ": Service '" + service + "' is not provided by any of the subsystems"); } } - for (RequiredInterfaceDescriptor service : getRequiredServices()) { + for (RequiredInterface service : getRequiredServices()) { if (!(required.contains(service))) { info("Service '" + service @@ -67,16 +67,16 @@ public class Container extends AbstractComponent { } } - List reallyRequired = new ArrayList( + List reallyRequired = new ArrayList( required); - for (ProvidedInterfaceDescriptor service : provided) { + for (ProvidedInterface service : provided) { reallyRequired.remove(service); } - for (RequiredInterfaceDescriptor service: getRequiredServices()) { + for (RequiredInterface service: getRequiredServices()) { reallyRequired.remove(service); } String missingRequired = ""; - for (RequiredInterfaceDescriptor service: reallyRequired) { + for (RequiredInterface service: reallyRequired) { missingRequired += service + "\n"; } if ( missingRequired.length() > 0 ) { @@ -86,12 +86,12 @@ public class Container extends AbstractComponent { @Override protected void doStart(String aContext, Service[] aRequiredServices) { - List descriptors = new ArrayList(); + List descriptors = new ArrayList(); for (Service service : aRequiredServices) { descriptors.add(service.getDescriptor()); } SystemAssembler assembler = new SystemAssembler(aContext + "." + getName(), _systems, - descriptors.toArray(new ProvidedInterfaceDescriptor[0])); + descriptors.toArray(new ProvidedInterface[0])); assembler.start(getRegistry(), aRequiredServices); } diff --git a/trunk/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java b/trunk/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java index 31eb64bb..2b51c60a 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/DefaultProvidedInterfaceDescriptor.java @@ -7,7 +7,7 @@ import java.util.Arrays; * * @author Erik Brakkee */ -public class DefaultProvidedInterfaceDescriptor implements ProvidedInterfaceDescriptor { +public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface { private String _name; private Class[] _interfaces; diff --git a/trunk/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java b/trunk/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java index 08411f90..9e434c08 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/DefaultRequiredInterfaceDescriptor.java @@ -1,7 +1,7 @@ package org.wamblee.system; public class DefaultRequiredInterfaceDescriptor extends DefaultProvidedInterfaceDescriptor - implements RequiredInterfaceDescriptor { + implements RequiredInterface { public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) { super(aName, aInterface); @@ -12,7 +12,7 @@ public class DefaultRequiredInterfaceDescriptor extends DefaultProvidedInterface } @Override - public boolean implementedBy(ProvidedInterfaceDescriptor aDescriptor) { + public boolean implementedBy(ProvidedInterface aDescriptor) { Class[] provided = aDescriptor.getInterfaceTypes(); for (Class required : getInterfaceTypes()) { if ( !serviceProvided(required, provided)) { diff --git a/trunk/system/general/src/main/java/org/wamblee/system/DefaultService.java b/trunk/system/general/src/main/java/org/wamblee/system/DefaultService.java index dc266223..a8a2692e 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/DefaultService.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/DefaultService.java @@ -8,7 +8,7 @@ package org.wamblee.system; public class DefaultService implements Service { private String _id; - private ProvidedInterfaceDescriptor _descriptor; + private ProvidedInterface _descriptor; private Object _service; /** @@ -19,7 +19,7 @@ public class DefaultService implements Service { * @param aService * Service. */ - public DefaultService(String aId, ProvidedInterfaceDescriptor aDescriptor, + public DefaultService(String aId, ProvidedInterface aDescriptor, Object aService) { _id = aId; _descriptor = aDescriptor; @@ -32,7 +32,7 @@ public class DefaultService implements Service { } @Override - public ProvidedInterfaceDescriptor getDescriptor() { + public ProvidedInterface getDescriptor() { return _descriptor; } diff --git a/trunk/system/general/src/main/java/org/wamblee/system/DefaultServiceRegistry.java b/trunk/system/general/src/main/java/org/wamblee/system/DefaultServiceRegistry.java index ae3f8b32..27d576e5 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/DefaultServiceRegistry.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/DefaultServiceRegistry.java @@ -15,7 +15,7 @@ public class DefaultServiceRegistry implements ServiceRegistry { } @Override - public synchronized Service register(ProvidedInterfaceDescriptor aDescriptor, + public synchronized Service register(ProvidedInterface aDescriptor, Object aService) { _count++; String id = "" + _count; diff --git a/trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java b/trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterface.java similarity index 88% rename from trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java rename to trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterface.java index 9afe3752..11b56646 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterfaceDescriptor.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/ProvidedInterface.java @@ -7,7 +7,7 @@ import java.util.Collection; * * @author Erik Brakkee */ -public interface ProvidedInterfaceDescriptor { +public interface ProvidedInterface { /** * Symbolic name for the service as used by the subsystem. diff --git a/trunk/system/general/src/main/java/org/wamblee/system/RequiredInterfaceDescriptor.java b/trunk/system/general/src/main/java/org/wamblee/system/RequiredInterface.java similarity index 67% rename from trunk/system/general/src/main/java/org/wamblee/system/RequiredInterfaceDescriptor.java rename to trunk/system/general/src/main/java/org/wamblee/system/RequiredInterface.java index 9e86767a..fd607403 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/RequiredInterfaceDescriptor.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/RequiredInterface.java @@ -1,6 +1,6 @@ package org.wamblee.system; -public interface RequiredInterfaceDescriptor { +public interface RequiredInterface { /** * Name for the interface. @@ -12,5 +12,5 @@ public interface RequiredInterfaceDescriptor { * @param aInterface Provided interface. * @return */ - boolean implementedBy(ProvidedInterfaceDescriptor aInterface); + boolean implementedBy(ProvidedInterface aInterface); } diff --git a/trunk/system/general/src/main/java/org/wamblee/system/Service.java b/trunk/system/general/src/main/java/org/wamblee/system/Service.java index 63988f08..8624c0cc 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/Service.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/Service.java @@ -17,7 +17,7 @@ public interface Service { * Gets the descriptor of the service. * @return Descriptor. */ - ProvidedInterfaceDescriptor getDescriptor(); + ProvidedInterface getDescriptor(); /** * Returns a reference to the running service. diff --git a/trunk/system/general/src/main/java/org/wamblee/system/ServiceRegistry.java b/trunk/system/general/src/main/java/org/wamblee/system/ServiceRegistry.java index 17294bbb..7fe35063 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/ServiceRegistry.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/ServiceRegistry.java @@ -2,7 +2,7 @@ package org.wamblee.system; public interface ServiceRegistry { - Service register(ProvidedInterfaceDescriptor aDescriptor, Object aService); + Service register(ProvidedInterface aDescriptor, Object aService); void remove(Service aService); diff --git a/trunk/system/general/src/main/java/org/wamblee/system/SystemAssembler.java b/trunk/system/general/src/main/java/org/wamblee/system/SystemAssembler.java index 561e3f95..5cdb3890 100644 --- a/trunk/system/general/src/main/java/org/wamblee/system/SystemAssembler.java +++ b/trunk/system/general/src/main/java/org/wamblee/system/SystemAssembler.java @@ -24,28 +24,28 @@ public class SystemAssembler { private String _context; private Component[] _systems; - public static RequiredInterfaceDescriptor[] filterRequiredServices( - ProvidedInterfaceDescriptor aProvided, - Collection aDescriptors) { - List required = new ArrayList(); - for (RequiredInterfaceDescriptor descriptor : aDescriptors) { + public static RequiredInterface[] filterRequiredServices( + ProvidedInterface aProvided, + Collection aDescriptors) { + List required = new ArrayList(); + for (RequiredInterface descriptor : aDescriptors) { if (descriptor.implementedBy(aProvided)) { required.add(descriptor); } } - return required.toArray(new RequiredInterfaceDescriptor[0]); + return required.toArray(new RequiredInterface[0]); } - public static ProvidedInterfaceDescriptor[] filterProvidedServices( - RequiredInterfaceDescriptor aRequired, - Collection aProvided) { - List provided = new ArrayList(); - for (ProvidedInterfaceDescriptor descriptor : aProvided) { + public static ProvidedInterface[] filterProvidedServices( + RequiredInterface aRequired, + Collection aProvided) { + List provided = new ArrayList(); + for (ProvidedInterface descriptor : aProvided) { if (aRequired.implementedBy(descriptor)) { provided.add(descriptor); } } - return provided.toArray(new ProvidedInterfaceDescriptor[0]); + return provided.toArray(new ProvidedInterface[0]); } /** @@ -58,7 +58,7 @@ public class SystemAssembler { * that this assembler manages. */ public SystemAssembler(Component[] aSystems, - ProvidedInterfaceDescriptor[] aAvailableServices) { + ProvidedInterface[] aAvailableServices) { this(ROOT_CONTEXT_NAME, aSystems, aAvailableServices); } @@ -74,7 +74,7 @@ public class SystemAssembler { * that this assembler manages. */ public SystemAssembler(String aContext, Component[] aSystems, - ProvidedInterfaceDescriptor[] aAvailableServices) { + ProvidedInterface[] aAvailableServices) { _context = aContext; _systems = aSystems; validate(aAvailableServices); @@ -84,20 +84,20 @@ public class SystemAssembler { * Determines if the systems are ordered appropriately so that all * dependencies are met. */ - private void validate(ProvidedInterfaceDescriptor[] aDescriptors) + private void validate(ProvidedInterface[] aDescriptors) throws SystemAssemblyException { - List allProvided = new ArrayList(); - for (ProvidedInterfaceDescriptor descriptor : aDescriptors) { + List allProvided = new ArrayList(); + for (ProvidedInterface descriptor : aDescriptors) { allProvided.add(descriptor); } for (Component system : _systems) { // Check if all required services are already provided by earlier // systems. - RequiredInterfaceDescriptor[] required = system.getRequiredServices(); + RequiredInterface[] required = system.getRequiredServices(); - for (RequiredInterfaceDescriptor descriptor : required) { - ProvidedInterfaceDescriptor[] filtered = filterProvidedServices( + for (RequiredInterface descriptor : required) { + ProvidedInterface[] filtered = filterProvidedServices( descriptor, allProvided); if (filtered.length == 0) { @@ -120,7 +120,7 @@ public class SystemAssembler { } // add all provided services - ProvidedInterfaceDescriptor[] provided = system.getProvidedServices(); + ProvidedInterface[] provided = system.getProvidedServices(); allProvided.addAll(Arrays.asList(provided)); } } @@ -136,7 +136,7 @@ public class SystemAssembler { */ public void start(ServiceRegistry aRegistry, Service[] aRequiredServices) { LOG.info("Starting '" + _context + "'"); - Map allProvided = new HashMap(); + Map allProvided = new HashMap(); for (Service service : aRequiredServices) { allProvided.put(service.getDescriptor(), service); @@ -145,11 +145,11 @@ public class SystemAssembler { // Compose a list of the required services required for the subsystem. - RequiredInterfaceDescriptor[] descriptors = system + RequiredInterface[] descriptors = system .getRequiredServices(); List services = new ArrayList(); - for (RequiredInterfaceDescriptor descriptor : descriptors) { - ProvidedInterfaceDescriptor[] provided = filterProvidedServices( + for (RequiredInterface descriptor : descriptors) { + ProvidedInterface[] provided = filterProvidedServices( descriptor, allProvided.keySet()); services.add(allProvided.get(provided[0])); } diff --git a/trunk/system/general/src/test/java/org/wamblee/system/Application.java b/trunk/system/general/src/test/java/org/wamblee/system/Application.java index 0ebf0018..3825c989 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/Application.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/Application.java @@ -3,14 +3,14 @@ package org.wamblee.system; import javax.sql.DataSource; public class Application extends AbstractComponent { - private static final RequiredInterfaceDescriptor[] REQUIRED = - new RequiredInterfaceDescriptor[] { + private static final RequiredInterface[] REQUIRED = + new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class), new DefaultRequiredInterfaceDescriptor("integer", Integer.class) }; public Application(ServiceRegistry aRegistry) { - super("application", aRegistry, new ProvidedInterfaceDescriptor[0], REQUIRED); + super("application", aRegistry, new ProvidedInterface[0], REQUIRED); } @Override diff --git a/trunk/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java b/trunk/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java index dd3451db..f74557be 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/DefaultInterfaceDescriptorTest.java @@ -7,27 +7,27 @@ import junit.framework.TestCase; public class DefaultInterfaceDescriptorTest extends TestCase { public void testOneRequiredOneProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class); + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class); + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedMatchSubClass() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class); + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class); + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class); assertTrue(required.implementedBy(provided)); } public void testOneRequiredOneProvidedNoMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class); + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class); + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class); assertFalse(required.implementedBy(provided)); } public void testOneRequiredMultipleProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", new Class[] { String.class, Integer.class} ); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class); + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class); assertTrue(required.implementedBy(provided)); } @@ -39,25 +39,25 @@ public class DefaultInterfaceDescriptorTest extends TestCase { } public void testMultipleRequiredOneProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", MyMultiple.class ); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", new Class[] {Runnable.class, Serializable.class} ); assertTrue(required.implementedBy(provided)); } public void testMultipleRequiredOneProvidedNoMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", MyMultiple.class ); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", new Class[] { String.class, Runnable.class} ); assertFalse(required.implementedBy(provided)); } public void testMultipleRequiredMultipleProvidedMatch() { - ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", + ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", new Class[] { Runnable.class, Serializable.class, String.class} ); - RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", + RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", new Class[] {Runnable.class, Serializable.class} ); assertTrue(required.implementedBy(provided)); } diff --git a/trunk/system/general/src/test/java/org/wamblee/system/Environment.java b/trunk/system/general/src/test/java/org/wamblee/system/Environment.java index ebc43265..e2bd2b80 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/Environment.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/Environment.java @@ -5,14 +5,14 @@ import javax.sql.DataSource; public class Environment extends AbstractComponent { - private static final ProvidedInterfaceDescriptor[] PROVIDED = - new ProvidedInterfaceDescriptor[] { + private static final ProvidedInterface[] PROVIDED = + new ProvidedInterface[] { new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class), new DefaultProvidedInterfaceDescriptor("integer", Integer.class) }; public Environment(ServiceRegistry aRegistry) { - super("environment", aRegistry, PROVIDED, new RequiredInterfaceDescriptor[0]); + super("environment", aRegistry, PROVIDED, new RequiredInterface[0]); } @Override diff --git a/trunk/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java b/trunk/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java index edd4bc2c..c372bf04 100644 --- a/trunk/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java +++ b/trunk/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java @@ -27,47 +27,47 @@ public class SystemAssemblerTest extends TestCase { } public void testFilterProvided() { - RequiredInterfaceDescriptor req1 = new DefaultRequiredInterfaceDescriptor( + RequiredInterface req1 = new DefaultRequiredInterfaceDescriptor( "name", Runnable.class); - RequiredInterfaceDescriptor req2 = new DefaultRequiredInterfaceDescriptor( + RequiredInterface req2 = new DefaultRequiredInterfaceDescriptor( "name", Serializable.class); - ProvidedInterfaceDescriptor prov1 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov1 = new DefaultProvidedInterfaceDescriptor( "name", Runnable.class); - ProvidedInterfaceDescriptor prov2 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov2 = new DefaultProvidedInterfaceDescriptor( "name", Serializable.class); - ProvidedInterfaceDescriptor prov3 = new DefaultProvidedInterfaceDescriptor( + ProvidedInterface prov3 = new DefaultProvidedInterfaceDescriptor( "name", MyMultiple.class); - AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 }, + AssertionUtils.assertEquals(new RequiredInterface[] { req1 }, SystemAssembler.filterRequiredServices(prov1, Arrays - .asList(new RequiredInterfaceDescriptor[] { req1 }))); - AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 }, + .asList(new RequiredInterface[] { req1 }))); + AssertionUtils.assertEquals(new RequiredInterface[] { req1 }, SystemAssembler.filterRequiredServices(prov1, - Arrays.asList(new RequiredInterfaceDescriptor[] { req1, + Arrays.asList(new RequiredInterface[] { req1, req2 }))); - AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1, + AssertionUtils.assertEquals(new RequiredInterface[] { req1, req2 }, SystemAssembler.filterRequiredServices(prov3, Arrays - .asList(new RequiredInterfaceDescriptor[] { req1, req2 }))); + .asList(new RequiredInterface[] { req1, req2 }))); AssertionUtils.assertEquals( - new ProvidedInterfaceDescriptor[] { prov1 }, + new ProvidedInterface[] { prov1 }, SystemAssembler.filterProvidedServices(req1, Arrays - .asList(new ProvidedInterfaceDescriptor[] { prov1 }))); + .asList(new ProvidedInterface[] { prov1 }))); AssertionUtils.assertEquals( - new ProvidedInterfaceDescriptor[] { prov1 }, SystemAssembler + new ProvidedInterface[] { prov1 }, SystemAssembler .filterProvidedServices(req1, Arrays - .asList(new ProvidedInterfaceDescriptor[] { + .asList(new ProvidedInterface[] { prov1, prov2 }))); - AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1, + AssertionUtils.assertEquals(new ProvidedInterface[] { prov1, prov3 }, SystemAssembler.filterProvidedServices(req1, Arrays - .asList(new ProvidedInterfaceDescriptor[] { prov1, prov3 }))); + .asList(new ProvidedInterface[] { prov1, prov3 }))); } public void testEnvironmentApplication() { Component environment = new Environment(_registry); Component application = new Application(_registry); SystemAssembler assembler = new SystemAssembler(new Component[] { - environment, application }, new ProvidedInterfaceDescriptor[0]); + environment, application }, new ProvidedInterface[0]); assembler.start(_registry, new Service[0]); Service[] envServices = environment.getRunningServices(); assertEquals(2, envServices.length); @@ -88,7 +88,7 @@ public class SystemAssemblerTest extends TestCase { Component application = new Application(_registry); SystemAssembler assembler = new SystemAssembler(new Component[] { application, environment }, - new ProvidedInterfaceDescriptor[0]); + new ProvidedInterface[0]); assembler.start(_registry, new Service[0]); } catch (SystemAssemblyException e) { // e.printStackTrace(); @@ -103,13 +103,13 @@ public class SystemAssemblerTest extends TestCase { assertEquals(Status.NOT_STARTED, environment.getStatus()); assertEquals(Status.NOT_STARTED, application.getStatus()); Container system = new Container("all", _registry, new Component[] { - environment, application }, new ProvidedInterfaceDescriptor[0], - new RequiredInterfaceDescriptor[0]); + environment, application }, new ProvidedInterface[0], + new RequiredInterface[0]); assertEquals(Status.NOT_STARTED, system.getStatus()); system.start("root", new Service[0]); - RequiredInterfaceDescriptor[] required = system.getRequiredServices(); + RequiredInterface[] required = system.getRequiredServices(); assertEquals(0, required.length); - ProvidedInterfaceDescriptor[] provided = system.getProvidedServices(); + ProvidedInterface[] 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 ProvidedInterface[] { new DefaultProvidedInterfaceDescriptor( "string", String.class) }, new DefaultRequiredInterfaceDescriptor[0]); } catch (SystemAssemblyException e) { @@ -145,13 +145,13 @@ public class SystemAssemblerTest extends TestCase { "all", _registry, new Component[] { environment, application }, - new ProvidedInterfaceDescriptor[0], - new RequiredInterfaceDescriptor[] { new DefaultRequiredInterfaceDescriptor( + new ProvidedInterface[0], + new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor( "string", String.class) }); system.start("root", new Service[0]); - RequiredInterfaceDescriptor[] required = system.getRequiredServices(); + RequiredInterface[] required = system.getRequiredServices(); assertEquals(1, required.length); - ProvidedInterfaceDescriptor[] provided = system.getProvidedServices(); + ProvidedInterface[] provided = system.getProvidedServices(); assertEquals(0, provided.length); } @@ -161,7 +161,7 @@ public class SystemAssemblerTest extends TestCase { Component application = new Application(_registry); Container system = new Container("all", _registry, new Component[] { application }, - new ProvidedInterfaceDescriptor[0], application + new ProvidedInterface[0], application .getRequiredServices()); system.start("root", new Service[0]); } catch (SystemAssemblyException e) { @@ -177,13 +177,13 @@ public class SystemAssemblerTest extends TestCase { Component application = new Application(_registry); Container system = new Container("all", _registry, new Component[] { application }, - new ProvidedInterfaceDescriptor[0], application + new ProvidedInterface[0], application .getRequiredServices()); Service[] envServices = environment.start("env", new Service[0]); system.start("root", envServices); - RequiredInterfaceDescriptor[] required = system.getRequiredServices(); + RequiredInterface[] required = system.getRequiredServices(); assertEquals(2, required.length); - ProvidedInterfaceDescriptor[] provided = system.getProvidedServices(); + ProvidedInterface[] provided = system.getProvidedServices(); assertEquals(0, provided.length); } @@ -195,7 +195,7 @@ public class SystemAssemblerTest extends TestCase { Component application = new Application(_registry); SystemAssembler assembler = new SystemAssembler(new Component[] { environment1, environment2, application }, - new ProvidedInterfaceDescriptor[0]); + new ProvidedInterface[0]); assembler.start(_registry, new Service[0]); } catch (SystemAssemblyException e) { @@ -209,8 +209,8 @@ public class SystemAssemblerTest extends TestCase { Component application = new Application(_registry); Container system = new Container("all", _registry, new Component[] { application }, - new ProvidedInterfaceDescriptor[0], - new RequiredInterfaceDescriptor[0]); + new ProvidedInterface[0], + new RequiredInterface[0]); system.start("root", new Service[0]); } catch (SystemAssemblyException e) { return; diff --git a/trunk/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java b/trunk/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java index a5dd685d..b9a2648c 100644 --- a/trunk/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java +++ b/trunk/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java @@ -11,8 +11,8 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.wamblee.system.AbstractComponent; -import org.wamblee.system.ProvidedInterfaceDescriptor; -import org.wamblee.system.RequiredInterfaceDescriptor; +import org.wamblee.system.ProvidedInterface; +import org.wamblee.system.RequiredInterface; import org.wamblee.system.Service; import org.wamblee.system.ServiceRegistry; import org.wamblee.system.SystemAssembler; @@ -34,8 +34,8 @@ public class SpringComponent extends AbstractComponent { private Properties _properties; private String[] _configFiles; - private Map _provided; - private Map _required; + private Map _provided; + private Map _required; /** * Parent application context containing required services. */ @@ -63,10 +63,10 @@ public class SpringComponent extends AbstractComponent { * service. */ public SpringComponent(String aName, ServiceRegistry aRegistry, String[] aConfigFiles, - Map aProvided, - Map aRequired) { - super(aName, aRegistry, aProvided.values().toArray(new ProvidedInterfaceDescriptor[0]), - aRequired.keySet().toArray(new RequiredInterfaceDescriptor[0])); + Map aProvided, + Map aRequired) { + super(aName, aRegistry, aProvided.values().toArray(new ProvidedInterface[0]), + aRequired.keySet().toArray(new RequiredInterface[0])); _properties = new Properties(); _configFiles = aConfigFiles; _provided = aProvided; @@ -141,10 +141,10 @@ public class SpringComponent extends AbstractComponent { for (Service svc: aRequiredServices) { String id = svc.getId(); - ProvidedInterfaceDescriptor descriptor = svc.getDescriptor(); - RequiredInterfaceDescriptor[] requiredServices = SystemAssembler.filterRequiredServices(descriptor, + ProvidedInterface descriptor = svc.getDescriptor(); + RequiredInterface[] requiredServices = SystemAssembler.filterRequiredServices(descriptor, _required.keySet()); - for (RequiredInterfaceDescriptor required: requiredServices) { + for (RequiredInterface required: requiredServices) { String beanName = _required.get(required); ConstructorArgumentValues cargs = new ConstructorArgumentValues(); cargs.addGenericArgumentValue(id); diff --git a/trunk/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java b/trunk/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java index f83e2ec1..b0f7f8ab 100644 --- a/trunk/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java +++ b/trunk/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java @@ -11,8 +11,8 @@ import org.wamblee.io.ClassPathResource; import org.wamblee.system.DefaultProvidedInterfaceDescriptor; import org.wamblee.system.DefaultRequiredInterfaceDescriptor; import org.wamblee.system.DefaultServiceRegistry; -import org.wamblee.system.ProvidedInterfaceDescriptor; -import org.wamblee.system.RequiredInterfaceDescriptor; +import org.wamblee.system.ProvidedInterface; +import org.wamblee.system.RequiredInterface; import org.wamblee.system.Service; import org.wamblee.system.ServiceRegistry; import org.wamblee.system.SystemAssemblyException; @@ -35,8 +35,8 @@ public class SpringComponentTest extends TestCase { public void testBlackboxSystem() { SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_XML }, - new HashMap(), - new HashMap()); + new HashMap(), + new HashMap()); system.start("Hello", new Service[0]); Service[] services = system.getRunningServices(); assertEquals(0, services.length); @@ -45,13 +45,13 @@ public class SpringComponentTest extends TestCase { } public void testOneProvidedService() { - Map provided = new HashMap(); + Map provided = new HashMap(); provided.put("helloService", new DefaultProvidedInterfaceDescriptor( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_XML }, provided, - new HashMap()); + new HashMap()); system.start("Hello", new Service[0]); Service[] services = system.getRunningServices(); assertEquals(1, services.length); @@ -62,13 +62,13 @@ public class SpringComponentTest extends TestCase { } public void testWithProperties() throws IOException { - Map provided = new HashMap(); + Map provided = new HashMap(); provided.put("helloService", new DefaultProvidedInterfaceDescriptor( "hello", HelloService.class)); SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML }, provided, - new HashMap()); + new HashMap()); Properties props = new Properties(); props.load(new ClassPathResource(PROPERTY_FILE).getInputStream()); system.addProperties(props); @@ -82,8 +82,8 @@ public class SpringComponentTest extends TestCase { try { SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML }, - new HashMap(), - new HashMap()); + new HashMap(), + new HashMap()); system.start("Bla", new Service[0]); } catch (SystemAssemblyException e) { //e.printStackTrace(); @@ -93,12 +93,12 @@ public class SpringComponentTest extends TestCase { } public void testWithRequirement() { - Map required = new HashMap(); + Map required = new HashMap(); required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class), "helloService"); SpringComponent system = new SpringComponent("system", _registry, new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML }, - new HashMap(), required); + new HashMap(), required); HelloService helloObject = new HelloService("ladida"); Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject); @@ -107,10 +107,10 @@ public class SpringComponentTest extends TestCase { } public void testWithRequirementAndProvidedService() { - Map required = new HashMap(); + Map required = new HashMap(); required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class), "helloService"); - Map provided = new HashMap(); + Map provided = new HashMap(); provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla", BlaService.class));