From 37050003ad805851e591b66cc3d5933332913fd3 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 4 Jun 2008 20:40:59 +0000 Subject: [PATCH] removed the unique id from the provided interface. Now using object identity instead. --- .../java/org/wamblee/mythtv/Application.java | 1 - system/TODO.txt | 1 - .../system/core/DefaultProvidedInterface.java | 21 +++++++++++------- .../system/core/DefaultRequiredInterface.java | 8 ++++++- .../org/wamblee/system/core/DefaultScope.java | 15 +++++-------- .../system/core/ProvidedInterface.java | 14 +++++++----- .../system/core/RequiredInterface.java | 6 +++++ ...tRequiredExternallyRequiredEdgeFilter.java | 2 -- .../RequiredProvidedEdgeFactory.java | 4 ++-- .../core/DefaultRequiredInterfaceTest.java | 22 +++++-------------- .../wamblee/system/core/DefaultScopeTest.java | 6 +---- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java b/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java index 901e4417..7cc13f87 100644 --- a/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java +++ b/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java @@ -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. } } diff --git a/system/TODO.txt b/system/TODO.txt index 57802098..de724e1e 100644 --- a/system/TODO.txt +++ b/system/TODO.txt @@ -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 diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java b/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java index d3a40bfe..6ec52a44 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultProvidedInterface.java @@ -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 result = new ArrayList(); diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java index 7fc96530..01575db2 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultRequiredInterface.java @@ -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; } diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java b/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java index 18f26cc8..7290a790 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java @@ -28,7 +28,7 @@ public class DefaultScope implements Scope { private List _parents; private Map _properties; private Map _runtimes; - private Map _provided; + private Map _provided; private ProvidedInterface[] _externallyProvided; public DefaultScope(ProvidedInterface[] aExternallyProvided) { @@ -44,7 +44,7 @@ public class DefaultScope implements Scope { _parents = new ArrayList(aParent); _properties = new HashMap(); _runtimes = new HashMap(); - _provided = new HashMap(); + _provided = new HashMap(); _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 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); diff --git a/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java index aa2621f7..f717535c 100644 --- a/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/ProvidedInterface.java @@ -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); } diff --git a/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java b/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java index 7f7fc348..74c132e0 100644 --- a/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java +++ b/system/general/src/main/java/org/wamblee/system/core/RequiredInterface.java @@ -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); } diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilter.java b/system/general/src/main/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilter.java index 598608c5..c7084028 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilter.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilter.java @@ -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 diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/RequiredProvidedEdgeFactory.java b/system/general/src/main/java/org/wamblee/system/graph/component/RequiredProvidedEdgeFactory.java index 89f4056c..711501a1 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/RequiredProvidedEdgeFactory.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/RequiredProvidedEdgeFactory.java @@ -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)); } } diff --git a/system/general/src/test/java/org/wamblee/system/core/DefaultRequiredInterfaceTest.java b/system/general/src/test/java/org/wamblee/system/core/DefaultRequiredInterfaceTest.java index 3fe55080..b6c1a95f 100644 --- a/system/general/src/test/java/org/wamblee/system/core/DefaultRequiredInterfaceTest.java +++ b/system/general/src/test/java/org/wamblee/system/core/DefaultRequiredInterfaceTest.java @@ -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))); + } } diff --git a/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java b/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java index d07ccd45..7199c6fb 100644 --- a/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java +++ b/system/general/src/test/java/org/wamblee/system/core/DefaultScopeTest.java @@ -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)); -- 2.31.1