removed the unique id from the provided interface. Now using object
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 4 Jun 2008 20:40:59 +0000 (20:40 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 4 Jun 2008 20:40:59 +0000 (20:40 +0000)
identity instead.

mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java
system/TODO.txt
system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java
system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.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/main/java/org/wamblee/system/core/RequiredInterface.java
system/general/src/main/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilter.java
system/general/src/main/java/org/wamblee/system/graph/component/RequiredProvidedEdgeFactory.java
system/general/src/test/java/org/wamblee/system/core/DefaultRequiredInterfaceTest.java
system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java

index 901e4417d9f75aed39759b0686b56e8f0550802e..7cc13f87d3b6b27045528aac070e5ba562118834 100644 (file)
@@ -79,7 +79,6 @@ public class Application implements ServletContextListener {
     public void contextDestroyed(ServletContextEvent arg0) {
         LOG.info("terminating");
         
-        // TODO check if timer will be automatically stopped. 
         // Empty. 
     }
 }
index 5780209886ab303343c0664e1b20810b76350051..de724e1e2e5108629135fb779a7ecb7c1b9765ee 100644 (file)
@@ -1,4 +1,3 @@
-uniqueId van provided interface moet worden gezet door provided interface zelf.
 
 opzoeken waar de provided interfaces van de scope gebruikt worden, als het
 goed is nog nergens. Scope moet een Component worden en publiceren van een 
index d3a40bfe227f4aec5d449f2e262b1e76670a093c..6ec52a44291dfb8d89c88b026669b5502b91b297 100644 (file)
@@ -31,7 +31,6 @@ public class DefaultProvidedInterface implements ProvidedInterface {
        
        private String _name; 
        private Class[] _interfaces;
-       private String _uniqueId; 
        
        /**
         * Constructs the descriptor. 
@@ -43,8 +42,7 @@ public class DefaultProvidedInterface implements ProvidedInterface {
        
        public DefaultProvidedInterface(String aName, Class[] aInterfaces) { 
                _name = aName; 
-               _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
-               _uniqueId = UUID.randomUUID().toString(); 
+               _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length); 
        }
 
        @Override
@@ -57,11 +55,6 @@ public class DefaultProvidedInterface implements ProvidedInterface {
                return _interfaces;
        }
        
-       @Override
-       public String getUniqueId() {
-               return _uniqueId;
-       }
-       
        @Override
        public void publish(Object aImplementation, Scope aScope) {
                aScope.publishInterface(this, aImplementation);
@@ -80,11 +73,14 @@ public class DefaultProvidedInterface implements ProvidedInterface {
        
        @Override
        public boolean equals(Object aObj) {
+           return this == aObj;
+           /*
            if ( !(aObj instanceof DefaultProvidedInterface)) { 
                return false; 
            }
            DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj; 
            return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
+           */
        }
        
        @Override
@@ -92,6 +88,15 @@ public class DefaultProvidedInterface implements ProvidedInterface {
            return getEqualsRepresentation().hashCode();
        }
        
+       @Override
+       public boolean covers(ProvidedInterface aInterface) {
+           // TODO do more than just equals. 
+           if ( !(aInterface instanceof DefaultProvidedInterface)) { 
+               return false; 
+           }
+           return getEqualsRepresentation().equals(((DefaultProvidedInterface)aInterface).getEqualsRepresentation());
+       }
+       
        
        private String getEqualsRepresentation() { 
            List<String> result = new ArrayList<String>(); 
index 7fc965308d4603e2386325c86c7f40c07e763c0d..01575db2c0dbc4e78b9bc53ac989b9cd22f0e2a6 100644 (file)
@@ -96,7 +96,13 @@ public class DefaultRequiredInterface implements RequiredInterface {
        }
        
        @Override
-       public boolean equals(Object obj) {
+       public boolean equals(Object obj) { 
+           return this == obj; 
+       }
+       
+       @Override
+       public boolean covers(RequiredInterface obj) {
+           // TODO do more than equals. 
                if ( !(obj instanceof DefaultRequiredInterface)) { 
                        return false; 
                }
index 18f26cc8d0a1e8ddaa75a3b88affd2c81422bf5b..7290a790365eda04712f5ffe5ecd74cc692a2fb4 100644 (file)
@@ -28,7 +28,7 @@ public class DefaultScope implements Scope {
        private List<Scope> _parents;
        private Map<String, Object> _properties;
        private Map<String, Object> _runtimes;
-       private Map<String, ProvidedInterfaceImplementation> _provided;
+       private Map<ProvidedInterface, ProvidedInterfaceImplementation> _provided;
        private ProvidedInterface[] _externallyProvided;
 
        public DefaultScope(ProvidedInterface[] aExternallyProvided) {
@@ -44,7 +44,7 @@ public class DefaultScope implements Scope {
                _parents = new ArrayList<Scope>(aParent);
                _properties = new HashMap<String, Object>();
                _runtimes = new HashMap<String, Object>();
-               _provided = new HashMap<String, ProvidedInterfaceImplementation>();
+               _provided = new HashMap<ProvidedInterface, ProvidedInterfaceImplementation>();
                _externallyProvided = aExternallyProvided;
        }
 
@@ -81,7 +81,7 @@ public class DefaultScope implements Scope {
        @Override
        synchronized public void publishInterface(ProvidedInterface aInterface,
                        Object aImplementation) {
-               _provided.put(aInterface.getUniqueId(), new ProvidedInterfaceImplementation(aInterface,
+               _provided.put(aInterface, new ProvidedInterfaceImplementation(aInterface,
                                aImplementation));
        }
 
@@ -90,13 +90,8 @@ public class DefaultScope implements Scope {
                        Class<T> aType) {
                if ( aInterface == null ) { 
                        return null; 
-               }
-               String id = aInterface.getUniqueId(); 
-               if ( id == null ) { 
-                       // optional interface that was not published.
-                       return null;
-               }
-               ProvidedInterfaceImplementation provided = _provided.get(id);
+               } 
+               ProvidedInterfaceImplementation provided = _provided.get(aInterface);
                if (provided == null) {
                        for (Scope parent : _parents) {
                                T impl = parent.getInterfaceImplementation(aInterface, aType);
index aa2621f7f017e70bbb8e8a4eb19f7f9e71fbabfd..f717535cf71f0369f9a3595ffa1c3d962422d998 100644 (file)
@@ -37,11 +37,6 @@ public interface ProvidedInterface {
         */
        Class[] getInterfaceTypes();
 
-       /**
-        * Gets the unique if of the provided interface.   
-        */
-       String getUniqueId();
-
        /**
         * Publishes an implementation of the interface. The implementation must 
         * call {@link Scope#publishInterface(ProvidedInterface, Object)} to publish the
@@ -50,4 +45,13 @@ public interface ProvidedInterface {
         * @param aScope Scope in which to publish the implementation. 
         */
        void publish(Object aImplementation, Scope aScope);
+       
+       
+       /**
+        * Determines whether the current provided interface exceeds the given provided interface. 
+        * In other words if it can provide at least what the given provided interface can provide. 
+        * @param aInterface Interface to compare to. 
+        * @return True if the current interface exceeds the given provided interface. 
+        */
+       boolean covers(ProvidedInterface aInterface); 
 }
index 7f7fc348d411b308f6b0fe1c40cb4dd6eb7b0b55..74c132e02aa7532cde7ec98e982b5be58c82573f 100644 (file)
@@ -46,4 +46,10 @@ public interface RequiredInterface {
         * @return Provider or null if not set. 
         */
        ProvidedInterface getProvider();
+       
+       /**
+        * Determines if the requirements of the current interface are at least those
+        * of the given required interface. 
+        */
+       boolean covers(RequiredInterface aInterface); 
 }
index 598608c511b5cd3f00a2de345d54f8f61a833a4f..c70840281ecda2e38e3a4f7cffa98199f97fd610 100644 (file)
@@ -17,8 +17,6 @@ package org.wamblee.system.graph.component;
 
 import org.wamblee.system.graph.Edge;
 import org.wamblee.system.graph.EdgeFilter;
-import org.wamblee.system.graph.EdgeSelector;
-import org.wamblee.system.graph.Node;
 
 /**
  * Filter used to explicitly connect required and provided interfaces within a
index 89f4056c423f11f572be0bc39aeebd7a04a1be95..711501a1894e54ffd92cf100709ed3a4a5d6c9fb 100644 (file)
@@ -55,7 +55,7 @@ public class RequiredProvidedEdgeFactory implements EdgeFactory {
                 }
             } else if (aTo instanceof ExternalRequiredInterfaceNode) {
                 ExternalRequiredInterfaceNode external = (ExternalRequiredInterfaceNode) aTo;
-                if ( required.getRequired().equals(external.getRequired())) { 
+                if ( external.getRequired().covers(required.getRequired())) { 
                     result.add(new DefaultEdge(required, external));
                 }
             }
@@ -63,7 +63,7 @@ public class RequiredProvidedEdgeFactory implements EdgeFactory {
             ProvidedInterfaceNode provided = (ProvidedInterfaceNode)aFrom;
             if ( aTo instanceof ExternalProvidedInterfaceNode) { 
                 ExternalProvidedInterfaceNode external = (ExternalProvidedInterfaceNode)aTo;
-                if ( provided.getProvided().equals(external.getProvided())) { 
+                if (provided.getProvided().covers(external.getProvided())) { 
                     result.add(new DefaultEdge(external, provided));
                 }
             }
index 3fe5508034805df75bc7fe3f47ffc8e311eff405..b6c1a95ffea842e46ed8978fa07154f6e054e20d 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.system.core;
 
 import org.wamblee.system.core.DefaultRequiredInterface;
@@ -22,21 +22,9 @@ import junit.framework.TestCase;
 
 public class DefaultRequiredInterfaceTest extends TestCase {
 
-       public void testEquals() { 
-               assertEquals(
-                               new DefaultRequiredInterface("a", String.class),
-                               new DefaultRequiredInterface("a", String.class));
-               assertEquals(
-                               new DefaultRequiredInterface("a", new Class[]{ String.class, Integer.class}),
-                               new DefaultRequiredInterface("a", new Class[]{ String.class, Integer.class}));
-               
-               assertFalse(
-                               new DefaultRequiredInterface("a", String.class).equals(
-                               new DefaultRequiredInterface("a", Integer.class)));
-               assertFalse(
-                               new DefaultRequiredInterface("a", new Class[]{ String.class}).equals(
-                               new DefaultRequiredInterface("a", new Class[]{ String.class, Integer.class})));
-               
-       }
+    public void testEquals() {
+        assertFalse(new DefaultRequiredInterface("a", String.class)
+                .equals(new DefaultRequiredInterface("a", String.class)));
+    }
 
 }
index d07ccd456819de128e35165d852e4df370ea1840..7199c6fb4fc6f00f3366ab9159cd0c48d24aae1f 100644 (file)
@@ -24,7 +24,6 @@ public class DefaultScopeTest extends TestCase {
         Scope scope = new DefaultScope(new ProvidedInterface[0]); 
          
         scope.publishInterface(provider, 100);
-        assertNotNull(provider.getUniqueId());
         assertEquals(100, scope.getInterfaceImplementation(provider, Integer.class).intValue());
     }
     
@@ -39,10 +38,7 @@ public class DefaultScopeTest extends TestCase {
         
         child.publishInterface(provider2, "hallo");
         
-        assertNotNull(provider1.getUniqueId());
-        assertNotNull(provider2.getUniqueId()); 
-        
-        assertFalse(provider1.getUniqueId().equals(provider2.getUniqueId()));
+        assertFalse(provider1.equals(provider2));
  
         assertEquals(100, child.getInterfaceImplementation(provider1, Integer.class).intValue());
         assertEquals("hallo", child.getInterfaceImplementation(provider2, String.class));