identity instead.
public void contextDestroyed(ServletContextEvent arg0) {
LOG.info("terminating");
- // TODO check if timer will be automatically stopped.
// Empty.
}
}
-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
private String _name;
private Class[] _interfaces;
- private String _uniqueId;
/**
* Constructs the descriptor.
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
return _interfaces;
}
- @Override
- public String getUniqueId() {
- return _uniqueId;
- }
-
@Override
public void publish(Object aImplementation, Scope aScope) {
aScope.publishInterface(this, aImplementation);
@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
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>();
}
@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;
}
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) {
_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;
}
@Override
synchronized public void publishInterface(ProvidedInterface aInterface,
Object aImplementation) {
- _provided.put(aInterface.getUniqueId(), new ProvidedInterfaceImplementation(aInterface,
+ _provided.put(aInterface, new ProvidedInterfaceImplementation(aInterface,
aImplementation));
}
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);
*/
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
* @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);
}
* @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);
}
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
}
} 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));
}
}
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));
}
}
* 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;
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)));
+ }
}
Scope scope = new DefaultScope(new ProvidedInterface[0]);
scope.publishInterface(provider, 100);
- assertNotNull(provider.getUniqueId());
assertEquals(100, scope.getInterfaceImplementation(provider, Integer.class).intValue());
}
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));