(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / core / DefaultProvidedInterface.java
index 10b8f6184cbbf5c5c50ce192720b8037b7132138..1297d363b7337e23599424a5a0ba2b28983a62bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -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 java.util.ArrayList;
@@ -20,93 +20,101 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-
 /**
  * Default implementation of a service descriptor.
- *
+ * 
  * @author Erik Brakkee
  */
 public class DefaultProvidedInterface implements ProvidedInterface {
-       
-       private String _name; 
-       private Class[] _interfaces;
-       private String _uniqueId; 
-       
-       /**
-        * Constructs the descriptor. 
-        * @param aInterface Type of service. 
-        */
-       public DefaultProvidedInterface(String aName, Class aInterface) {
-               this(aName, new Class[] { aInterface }); 
-       }
-       
-       public DefaultProvidedInterface(String aName, Class[] aInterfaces) { 
-               _name = aName; 
-               _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
-               _uniqueId = null; 
-       }
-
-       @Override
-       public String getName() {
-               return _name;
-       }
-       
-       @Override
-       public Class[] getInterfaceTypes() {
-               return _interfaces;
-       }
-
-       @Override
-       public void setUniqueId(String aId) {
-               _uniqueId = aId;        
-       }
-       
-       @Override
-       public String getUniqueId() {
-               return _uniqueId;
-       }
-       
-       @Override
-       public void publish(Object aImplementation, Scope aScope) {
-               aScope.publishInterface(this, aImplementation);
-       }
-       
-       @Override
-       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 aObj) {
-           if ( !(aObj instanceof DefaultProvidedInterface)) { 
-               return false; 
-           }
-           DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj; 
-           return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
-       }
-       
-       @Override
-       public int hashCode() {
-           return getEqualsRepresentation().hashCode();
-       }
-       
-       
-       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; 
-       }
+    private String name;
+
+    private Class[] interfaces;
+
+    /**
+     * Constructs the descriptor.
+     * 
+     * @param aInterface
+     *            Type of service.
+     */
+    public DefaultProvidedInterface(String aName, Class aInterface) {
+        this(aName, new Class[] { aInterface });
+    }
+
+    /**
+     * Creates a new DefaultProvidedInterface object.
+     * 
+     */
+    public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
+        name = aName;
+        interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Class[] getInterfaceTypes() {
+        return interfaces;
+    }
+
+    @Override
+    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 aObj) {
+        return this == aObj;
+
+        /*
+         * if ( !(aObj instanceof DefaultProvidedInterface)) { return false; }
+         * DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj;
+         * return
+         * getEqualsRepresentation().equals(provided.getEqualsRepresentation());
+         */
+    }
+
+    @Override
+    public int hashCode() {
+        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>();
+
+        for (Class cls : interfaces) {
+            result.add(cls.getName());
+        }
+
+        Collections.sort(result);
+
+        StringBuffer value = new StringBuffer();
+
+        for (String str : result) {
+            value.append(":" + str);
+        }
+
+        return value.toString();
+    }
 }