1 package org.wamblee.system;
3 import java.util.Arrays;
6 * Default implementation of a service descriptor.
10 public class DefaultProvidedInterface implements ProvidedInterface {
13 private Class[] _interfaces;
14 private Object _implementation;
17 * Constructs the descriptor.
18 * @param aInterface Type of service.
20 public DefaultProvidedInterface(String aName, Class aInterface) {
22 _interfaces = new Class[] { aInterface };
25 public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
27 _interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
31 public String getName() {
36 public Class[] getInterfaceTypes() {
41 public void publish(Object aImplementation) {
42 _implementation = aImplementation;
46 public Object getImplementation() {
47 return _implementation;
51 public boolean equals(Object obj) {
52 if ( !(obj instanceof DefaultProvidedInterface)) {
55 DefaultProvidedInterface descr = (DefaultProvidedInterface)obj;
56 if ( _interfaces.length != descr._interfaces.length ) {
59 String[] interfaces1 = new String[_interfaces.length];
60 String[] interfaces2 = new String[_interfaces.length];
61 for (int i = 0; i < _interfaces.length; i++) {
62 interfaces1[i] = _interfaces[i].getName();
63 interfaces2[i] = descr._interfaces[i].getName();
65 Arrays.sort(interfaces1);
66 Arrays.sort(interfaces2);
67 return Arrays.equals(interfaces1, interfaces2);
71 public int hashCode() {
72 return _interfaces.hashCode();
76 public String toString() {
77 StringBuffer buf = new StringBuffer();
78 for (Class intf: _interfaces) {
79 buf.append("." + intf.getName());
81 return buf.toString();