provided interface now sets its own unique id.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 4 Jun 2008 20:08:00 +0000 (20:08 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 4 Jun 2008 20:08:00 +0000 (20:08 +0000)
system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java
system/general/src/main/java/org/wamblee/system/core/DefaultScope.java
system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java
system/general/src/test/java/org/wamblee/system/container/ContainerTest.java
system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java

index 10b8f6184cbbf5c5c50ce192720b8037b7132138..d3a40bfe227f4aec5d449f2e262b1e76670a093c 100644 (file)
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.UUID;
 
 
 /**
@@ -43,7 +44,7 @@ public class DefaultProvidedInterface implements ProvidedInterface {
        public DefaultProvidedInterface(String aName, Class[] aInterfaces) { 
                _name = aName; 
                _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
-               _uniqueId = null
+               _uniqueId = UUID.randomUUID().toString()
        }
 
        @Override
@@ -55,11 +56,6 @@ public class DefaultProvidedInterface implements ProvidedInterface {
        public Class[] getInterfaceTypes() {
                return _interfaces;
        }
-
-       @Override
-       public void setUniqueId(String aId) {
-               _uniqueId = aId;        
-       }
        
        @Override
        public String getUniqueId() {
index 51949ca1570df5dd755a905edb1a4e5049a92a71..18f26cc8d0a1e8ddaa75a3b88affd2c81422bf5b 100644 (file)
@@ -81,10 +81,8 @@ public class DefaultScope implements Scope {
        @Override
        synchronized public void publishInterface(ProvidedInterface aInterface,
                        Object aImplementation) {
-               String id = UUID.randomUUID().toString();
-               _provided.put(id, new ProvidedInterfaceImplementation(aInterface,
+               _provided.put(aInterface.getUniqueId(), new ProvidedInterfaceImplementation(aInterface,
                                aImplementation));
-               aInterface.setUniqueId(id);
        }
 
        @Override
index fe7f7d26a73483907d0102b29050c86455f8d55c..aa2621f7f017e70bbb8e8a4eb19f7f9e71fbabfd 100644 (file)
@@ -36,17 +36,9 @@ public interface ProvidedInterface {
         * @return Service type. 
         */
        Class[] getInterfaceTypes();
-       
-       /**
-        * Sets a unique id of the provided interface to identify it within a given scope.
-        * Will be called by the container as part of calling {@link #publish(Object, Scope)}. 
-        * @param aId Unique id. 
-        */
-       void setUniqueId(String aId);
 
        /**
-        * Gets the unique if of the provided interface. This is set by the container
-        * using {@link #setUniqueId(String)}.  
+        * Gets the unique if of the provided interface.   
         */
        String getUniqueId();
 
index cc18db2e50bac0a1c11fe3886fc10583db8e393c..83abf3c2302debf477dc907efb5b0ffa7a6358d4 100644 (file)
@@ -201,7 +201,6 @@ public class ContainerTest extends TestCase {
             return;
         }
         fail();
-
     }
 
     public void testDuplicateComponent() {
@@ -216,6 +215,7 @@ public class ContainerTest extends TestCase {
         fail();
     }
 
+
     public void testInconsistentHierarchy() {
         try {
             Component comp = new Application();
@@ -527,74 +527,79 @@ public class ContainerTest extends TestCase {
                 Thread.currentThread()).toArray(new String[0]));
 
     }
-    
-    public void testNonUniqueRequiredInterface() { 
+
+    public void testNonUniqueRequiredInterface() {
         final Container container = new Container("top");
-        container.addRequiredInterface(new DefaultRequiredInterface("i", Integer.class));
-        container.addRequiredInterface(new DefaultRequiredInterface("x", String.class));
-        container.addRequiredInterface(new DefaultRequiredInterface("y", String.class));
-        
+        container.addRequiredInterface(new DefaultRequiredInterface("i",
+                Integer.class));
+        container.addRequiredInterface(new DefaultRequiredInterface("x",
+                String.class));
+        container.addRequiredInterface(new DefaultRequiredInterface("y",
+                String.class));
+
         Application app = new Application("1");
         container.addComponent(app);
 
-    
-        AssertionUtils.assertException(new AssertionUtils.ErroneousCode() { 
+        AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
             @Override
             public void run() throws Exception {
-                container.start();                
+                container.start();
             }
         }, SystemAssemblyException.class);
-           
-        container.connectExternalRequired("1", app.getRequiredInterfaces()[0].getName(), 
-                "y");
-        
+
+        container.connectExternalRequired("1", app.getRequiredInterfaces()[0]
+                .getName(), "y");
+
         ProvidedInterface i = new DefaultProvidedInterface("i", Integer.class);
         ProvidedInterface x = new DefaultProvidedInterface("x", String.class);
         ProvidedInterface y = new DefaultProvidedInterface("y", String.class);
-    
+
         Scope externalScope = new DefaultScope(new ProvidedInterface[0]);
-        
+
         externalScope.publishInterface(i, 100);
         externalScope.publishInterface(x, "x-value");
         externalScope.publishInterface(y, "y-value");
-        
+
         container.getRequiredInterfaces()[0].setProvider(i);
         container.getRequiredInterfaces()[1].setProvider(x);
         container.getRequiredInterfaces()[2].setProvider(y);
-        
+
         Scope runtime = container.start(externalScope);
-        
+
         assertEquals("y-value", app.getString());
-        
+
     }
-    
-    public void testNonUniqueProvidedInterface() { 
-        
-        final Container container = new Container("top").addProvidedInterface(new DefaultProvidedInterface("external", String.class)); 
+
+    public void testNonUniqueProvidedInterface() {
+
+        final Container container = new Container("top")
+                .addProvidedInterface(new DefaultProvidedInterface("external",
+                        String.class));
         Environment env1 = new Environment("env1");
         Environment env2 = new Environment("env2");
-        
-        
-        container.addComponent(env1); 
+
+        container.addComponent(env1);
         container.addComponent(env2);
-        
-        AssertionUtils.assertException(new AssertionUtils.ErroneousCode() { 
+
+        AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
             @Override
             public void run() throws Exception {
-                container.start();                
+                container.start();
             }
         }, SystemAssemblyException.class);
-        
+
         // now choose env2
-        
-        container.connectExternalProvided(container.getProvidedInterfaces()[0].getName(), 
-                env2.getName(), env2.getProvidedInterfaces()[0].getName());
-        
+
+        container.connectExternalProvided(container.getProvidedInterfaces()[0]
+                .getName(), env2.getName(), env2.getProvidedInterfaces()[0]
+                .getName());
+
         Scope scope = container.start();
-        
+
         // check the value of the provided interface of the container
-        
-        String value = scope.getInterfaceImplementation(container.getProvidedInterfaces()[0], String.class);
+
+        String value = scope.getInterfaceImplementation(container
+                .getProvidedInterfaces()[0], String.class);
         assertNotNull(value);
         assertEquals(value, env2.getString());
         assertFalse(value.equals(env1.getString()));
index 8458c326e5265d483feda55dc0d6e4895a85be60..d07ccd456819de128e35165d852e4df370ea1840 100644 (file)
@@ -22,10 +22,10 @@ public class DefaultScopeTest extends TestCase {
     public void testLookup() { 
         ProvidedInterface provider = new DefaultProvidedInterface("x", Integer.class);
         Scope scope = new DefaultScope(new ProvidedInterface[0]); 
-        
-        assertNull(provider.getUniqueId()); 
+         
         scope.publishInterface(provider, 100);
         assertNotNull(provider.getUniqueId());
+        assertEquals(100, scope.getInterfaceImplementation(provider, Integer.class).intValue());
     }
     
     public void testNestedLookup() {