*/
package org.wamblee.system.core;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
/**
* Default implementation of a service descriptor.
private String _name;
private Class[] _interfaces;
- private Object _implementation;
/**
* Constructs the descriptor.
* @param aInterface Type of service.
*/
public DefaultProvidedInterface(String aName, Class aInterface) {
- _name = aName;
- _interfaces = new Class[] { aInterface };
+ this(aName, new Class[] { aInterface });
}
- public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
+ public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
_name = aName;
- _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
+ _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
}
@Override
}
@Override
- public void publish(Object aImplementation) {
- _implementation = aImplementation;
+ public void publish(Object aImplementation, Scope aScope) {
+ aScope.publishInterface(this, aImplementation);
}
@Override
- public Object getImplementation() {
- return _implementation;
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getName());
+ buf.append(":");
+ for (Class intf: _interfaces) {
+ buf.append(" " + intf.getName());
+ }
+ return buf.toString();
}
@Override
- public boolean equals(Object obj) {
- if ( !(obj instanceof DefaultProvidedInterface)) {
- return false;
- }
- DefaultProvidedInterface descr = (DefaultProvidedInterface)obj;
- if ( _interfaces.length != descr._interfaces.length ) {
- return false;
- }
- String[] interfaces1 = new String[_interfaces.length];
- String[] interfaces2 = new String[_interfaces.length];
- for (int i = 0; i < _interfaces.length; i++) {
- interfaces1[i] = _interfaces[i].getName();
- interfaces2[i] = descr._interfaces[i].getName();
- }
- Arrays.sort(interfaces1);
- Arrays.sort(interfaces2);
- return Arrays.equals(interfaces1, interfaces2);
+ public boolean equals(Object aObj) {
+ return this == aObj;
+ /*
+ if ( !(aObj instanceof DefaultProvidedInterface)) {
+ return false;
+ }
+ DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj;
+ return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
+ */
}
-
+
@Override
public int hashCode() {
- return _interfaces.hashCode();
+ return getEqualsRepresentation().hashCode();
}
@Override
- public String toString() {
- StringBuffer buf = new StringBuffer();
- for (Class intf: _interfaces) {
- buf.append("." + intf.getName());
- }
- return buf.toString();
+ 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>();
+ for (Class cls: _interfaces) {
+ result.add(cls.getName());
+ }
+ Collections.sort(result);
+ String value = "";
+ for (String str: result) {
+ value += ":" + str;
+ }
+ return value;
}
}