2 * Copyright 2007 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;
25 * Default implementation of a service descriptor.
27 * @author Erik Brakkee
29 public class DefaultProvidedInterface implements ProvidedInterface {
32 private Class[] _interfaces;
35 * Constructs the descriptor.
36 * @param aInterface Type of service.
38 public DefaultProvidedInterface(String aName, Class aInterface) {
39 this(aName, new Class[] { aInterface });
42 public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
44 _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
48 public String getName() {
53 public Class[] getInterfaceTypes() {
58 public String toString() {
59 StringBuffer buf = new StringBuffer();
60 buf.append(getName());
62 for (Class intf: _interfaces) {
63 buf.append(" " + intf.getName());
65 return buf.toString();
69 public boolean equals(Object aObj) {
72 if ( !(aObj instanceof DefaultProvidedInterface)) {
75 DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj;
76 return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
81 public int hashCode() {
82 return getEqualsRepresentation().hashCode();
86 public boolean covers(ProvidedInterface aInterface) {
87 // TODO do more than just equals.
88 if ( !(aInterface instanceof DefaultProvidedInterface)) {
91 return getEqualsRepresentation().equals(((DefaultProvidedInterface)aInterface).getEqualsRepresentation());
95 private String getEqualsRepresentation() {
96 List<String> result = new ArrayList<String>();
97 for (Class cls: _interfaces) {
98 result.add(cls.getName());
100 Collections.sort(result);
102 for (String str: result) {