X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FDefaultProvidedInterface.java;h=484f63a0a9730198b3fdfeb9bf606cb08aea600b;hb=ddd261f331280640c5b53c7128230b629ebcd268;hp=60c111ed1ecfd14c699924b0f2fb10b8476af2ce;hpb=2768257dc89eeac0398e8b5ec42b0ff031e0e344;p=utils 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 60c111ed..484f63a0 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 @@ -1,21 +1,25 @@ /* * Copyright 2007 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * 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; import java.util.Arrays; +import java.util.Collections; +import java.util.List; + /** * Default implementation of a service descriptor. @@ -23,78 +27,141 @@ import java.util.Arrays; * @author Erik Brakkee */ public class DefaultProvidedInterface implements ProvidedInterface { - - 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 }; - } - - 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 void publish(Object aImplementation) { - _implementation = aImplementation; - } - - @Override - public Object getImplementation() { - return _implementation; - } - - @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); - } - - @Override - public int hashCode() { - return _interfaces.hashCode(); - } - - @Override - public String toString() { - StringBuffer buf = new StringBuffer(); - buf.append(getName()); - buf.append(":"); - for (Class intf: _interfaces) { - buf.append(" " + intf.getName()); - } - return buf.toString(); - } + /** + * DOCUMENT ME! + */ + private String name; + + /** + * DOCUMENT ME! + */ + 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. + * + * @param aName DOCUMENT ME! + * @param aInterfaces DOCUMENT ME! + */ + public DefaultProvidedInterface(String aName, Class[] aInterfaces) { + name = aName; + interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public String getName() { + return name; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public Class[] getInterfaceTypes() { + return interfaces; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(getName()); + buf.append(":"); + + for (Class intf : interfaces) { + buf.append(" " + intf.getName()); + } + + return buf.toString(); + } + + /** + * DOCUMENT ME! + * + * @param aObj DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public boolean equals(Object aObj) { + return this == aObj; + + /* + if ( !(aObj instanceof DefaultProvidedInterface)) { + return false; + } + DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj; + return getEqualsRepresentation().equals(provided.getEqualsRepresentation()); + */ + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public int hashCode() { + return getEqualsRepresentation().hashCode(); + } + + /** + * DOCUMENT ME! + * + * @param aInterface DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + @Override + public boolean covers(ProvidedInterface aInterface) { + // TODO do more than just equals. + if (!(aInterface instanceof DefaultProvidedInterface)) { + return false; + } + + return getEqualsRepresentation() + .equals(((DefaultProvidedInterface) aInterface).getEqualsRepresentation()); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + private String getEqualsRepresentation() { + List result = new ArrayList(); + + for (Class cls : interfaces) { + result.add(cls.getName()); + } + + Collections.sort(result); + + String value = ""; + + for (String str : result) { + value += (":" + str); + } + + return value; + } }