2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.system.core;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.List;
24 * Default implementation of a service descriptor.
26 * @author Erik Brakkee
28 public class DefaultProvidedInterface implements ProvidedInterface {
31 private Class[] interfaces;
34 * Constructs the descriptor.
39 public DefaultProvidedInterface(String aName, Class aInterface) {
40 this(aName, new Class[] { aInterface });
44 * Creates a new DefaultProvidedInterface object.
47 public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
49 interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
53 public String getName() {
58 public Class[] getInterfaceTypes() {
63 public String toString() {
64 StringBuffer buf = new StringBuffer();
65 buf.append(getName());
68 for (Class intf : interfaces) {
69 buf.append(" " + intf.getName());
72 return buf.toString();
76 public boolean equals(Object aObj) {
80 * if ( !(aObj instanceof DefaultProvidedInterface)) { return false; }
81 * DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj;
83 * getEqualsRepresentation().equals(provided.getEqualsRepresentation());
88 public int hashCode() {
89 return getEqualsRepresentation().hashCode();
93 public boolean covers(ProvidedInterface aInterface) {
94 // TODO do more than just equals.
95 if (!(aInterface instanceof DefaultProvidedInterface)) {
99 return getEqualsRepresentation().equals(
100 ((DefaultProvidedInterface) aInterface).getEqualsRepresentation());
103 private String getEqualsRepresentation() {
104 List<String> result = new ArrayList<String>();
106 for (Class cls : interfaces) {
107 result.add(cls.getName());
110 Collections.sort(result);
112 StringBuffer value = new StringBuffer();
114 for (String str : result) {
115 value.append(":" + str);
118 return value.toString();