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;
22 import java.util.UUID;
26 * Default implementation of a service descriptor.
28 * @author Erik Brakkee
30 public class DefaultProvidedInterface implements ProvidedInterface {
33 private Class[] _interfaces;
36 * Constructs the descriptor.
37 * @param aInterface Type of service.
39 public DefaultProvidedInterface(String aName, Class aInterface) {
40 this(aName, new Class[] { aInterface });
43 public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
45 _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
49 public String getName() {
54 public Class[] getInterfaceTypes() {
59 public void publish(Object aImplementation, Scope aScope) {
60 aScope.publishInterface(this, aImplementation);
64 public String toString() {
65 StringBuffer buf = new StringBuffer();
66 buf.append(getName());
68 for (Class intf: _interfaces) {
69 buf.append(" " + intf.getName());
71 return buf.toString();
75 public boolean equals(Object aObj) {
78 if ( !(aObj instanceof DefaultProvidedInterface)) {
81 DefaultProvidedInterface provided = (DefaultProvidedInterface)aObj;
82 return getEqualsRepresentation().equals(provided.getEqualsRepresentation());
87 public int hashCode() {
88 return getEqualsRepresentation().hashCode();
92 public boolean covers(ProvidedInterface aInterface) {
93 // TODO do more than just equals.
94 if ( !(aInterface instanceof DefaultProvidedInterface)) {
97 return getEqualsRepresentation().equals(((DefaultProvidedInterface)aInterface).getEqualsRepresentation());
101 private String getEqualsRepresentation() {
102 List<String> result = new ArrayList<String>();
103 for (Class cls: _interfaces) {
104 result.add(cls.getName());
106 Collections.sort(result);
108 for (String str: result) {