*
* @author Erik Brakkee
*/
-public abstract class AbstractInterfaceDescriptor implements InterfaceDescriptor {
+public class AbstractProvidedInterfaceDescriptor implements ProvidedInterfaceDescriptor {
private String _name;
private Class[] _interfaces;
* Constructs the descriptor.
* @param aInterface Type of service.
*/
- public AbstractInterfaceDescriptor(String aName, Class aInterface) {
+ public AbstractProvidedInterfaceDescriptor(String aName, Class aInterface) {
_name = aName;
_interfaces = new Class[] { aInterface };
}
- public AbstractInterfaceDescriptor(String aName, Class[] aInterfaces) {
+ public AbstractProvidedInterfaceDescriptor(String aName, Class[] aInterfaces) {
_name = aName;
_interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
}
@Override
public boolean equals(Object obj) {
- if ( !(obj instanceof AbstractInterfaceDescriptor)) {
+ if ( !(obj instanceof AbstractProvidedInterfaceDescriptor)) {
return false;
}
- AbstractInterfaceDescriptor descr = (AbstractInterfaceDescriptor)obj;
+ AbstractProvidedInterfaceDescriptor descr = (AbstractProvidedInterfaceDescriptor)obj;
if ( _interfaces.length != descr._interfaces.length ) {
return false;
}
required.addAll(Arrays.asList(system.getRequiredServices()));
}
- for (InterfaceDescriptor service : getProvidedServices()) {
+ for (ProvidedInterfaceDescriptor service : getProvidedServices()) {
if (!(provided.contains(service))) {
throw new SystemAssemblyException(getName() + ": Service '" + service
+ "' is not provided by any of the subsystems");
+++ /dev/null
-package org.wamblee.system;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-
-public class DefaultProvidedInterfaceDescriptor extends AbstractInterfaceDescriptor implements
- ProvidedInterfaceDescriptor {
-
- public DefaultProvidedInterfaceDescriptor(String aName, Class aInterface) {
- super(aName, aInterface);
- }
-
- public DefaultProvidedInterfaceDescriptor(String aName, Class[] aInterface) {
- super(aName, aInterface);
- }
-
-}
package org.wamblee.system;
-public class DefaultRequiredInterfaceDescriptor extends AbstractInterfaceDescriptor
+public class DefaultRequiredInterfaceDescriptor extends AbstractProvidedInterfaceDescriptor
implements RequiredInterfaceDescriptor {
public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) {
+++ /dev/null
-package org.wamblee.system;
-
-/**
- * Service descriptor providing a description and characteristics
- * of the provided service.
- *
- * NOTE: The current implemention only stores the type of the
- * descriptor but his can be extended towards more complex rules
- * for matching services.
- *
- * Implementations must implement {@link #equals(Object)} and {@link #hashCode()}.
- *
- * @author Erik Brakkee
- */
-public interface InterfaceDescriptor {
-
- /**
- * Symbolic name for the service as used by the subsystem.
- * @return Service name.
- */
- String getName();
-
- /**
- * Returns the service type.
- * @return Service type.
- */
- Class[] getInterfaceTypes();
-}
import java.util.Collection;
-public interface ProvidedInterfaceDescriptor extends InterfaceDescriptor {
- // Empty
+/**
+ * Represents an interface provided by a component.
+ *
+ * @author Erik Brakkee
+ */
+public interface ProvidedInterfaceDescriptor {
+
+ /**
+ * Symbolic name for the service as used by the subsystem.
+ * @return Service name.
+ */
+ String getName();
+
+ /**
+ * Returns the service type.
+ * @return Service type.
+ */
+ Class[] getInterfaceTypes();
}
public class DefaultInterfaceDescriptorTest extends TestCase {
public void testOneRequiredOneProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", String.class);
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
assertTrue(required.implementedBy(provided));
}
public void testOneRequiredOneProvidedMatchSubClass() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class);
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", Integer.class);
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
assertTrue(required.implementedBy(provided));
}
public void testOneRequiredOneProvidedNoMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name", String.class);
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
assertFalse(required.implementedBy(provided));
}
public void testOneRequiredMultipleProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name",
new Class[] { String.class, Integer.class} );
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name", String.class);
assertTrue(required.implementedBy(provided));
}
public void testMultipleRequiredOneProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name",
MyMultiple.class );
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] {Runnable.class, Serializable.class} );
}
public void testMultipleRequiredOneProvidedNoMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name",
MyMultiple.class );
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] { String.class, Runnable.class} );
}
public void testMultipleRequiredMultipleProvidedMatch() {
- ProvidedInterfaceDescriptor provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterfaceDescriptor provided = new AbstractProvidedInterfaceDescriptor("name",
new Class[] { Runnable.class, Serializable.class, String.class} );
RequiredInterfaceDescriptor required = new DefaultRequiredInterfaceDescriptor("name",
new Class[] {Runnable.class, Serializable.class} );
private static final ProvidedInterfaceDescriptor[] PROVIDED =
new ProvidedInterfaceDescriptor[] {
- new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class),
- new DefaultProvidedInterfaceDescriptor("integer", Integer.class)
+ new AbstractProvidedInterfaceDescriptor("datasource", DataSource.class),
+ new AbstractProvidedInterfaceDescriptor("integer", Integer.class)
};
public Environment(ServiceRegistry aRegistry) {
"name", Runnable.class);
RequiredInterfaceDescriptor req2 = new DefaultRequiredInterfaceDescriptor(
"name", Serializable.class);
- ProvidedInterfaceDescriptor prov1 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterfaceDescriptor prov1 = new AbstractProvidedInterfaceDescriptor(
"name", Runnable.class);
- ProvidedInterfaceDescriptor prov2 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterfaceDescriptor prov2 = new AbstractProvidedInterfaceDescriptor(
"name", Serializable.class);
- ProvidedInterfaceDescriptor prov3 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterfaceDescriptor prov3 = new AbstractProvidedInterfaceDescriptor(
"name", MyMultiple.class);
AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
system.start("root", new Service[0]);
RequiredInterfaceDescriptor[] required = system.getRequiredServices();
assertEquals(0, required.length);
- InterfaceDescriptor[] provided = system.getProvidedServices();
+ ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
assertEquals(0, provided.length);
assertEquals(Status.RUNNING, environment.getStatus());
assertEquals(Status.RUNNING, application.getStatus());
"all",
_registry,
new Component[] { environment, application },
- new ProvidedInterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor(
+ new ProvidedInterfaceDescriptor[] { new AbstractProvidedInterfaceDescriptor(
"string", String.class) },
new DefaultRequiredInterfaceDescriptor[0]);
} catch (SystemAssemblyException e) {
import junit.framework.TestCase;
import org.wamblee.io.ClassPathResource;
-import org.wamblee.system.AbstractInterfaceDescriptor;
-import org.wamblee.system.DefaultProvidedInterfaceDescriptor;
+import org.wamblee.system.AbstractProvidedInterfaceDescriptor;
+import org.wamblee.system.AbstractProvidedInterfaceDescriptor;
import org.wamblee.system.DefaultRequiredInterfaceDescriptor;
import org.wamblee.system.DefaultServiceRegistry;
import org.wamblee.system.ProvidedInterfaceDescriptor;
public void testOneProvidedService() {
Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
- provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
+ provided.put("helloService", new AbstractProvidedInterfaceDescriptor(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system", _registry,
public void testWithProperties() throws IOException {
Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
- provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
+ provided.put("helloService", new AbstractProvidedInterfaceDescriptor(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system", _registry,
new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML },
new HashMap<String, ProvidedInterfaceDescriptor>(), required);
HelloService helloObject = new HelloService("ladida");
- Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
+ Service helloService = _registry.register(new AbstractProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
system.start("Bla", new Service[] { helloService } );
system.stop();
}
required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
"helloService");
Map<String,ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
- provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla",
+ provided.put("blaService", new AbstractProvidedInterfaceDescriptor("bla",
BlaService.class));
SpringComponent system = new SpringComponent("system", _registry,
provided, required);
HelloService helloObject = new HelloService("ladida");
- Service helloService = _registry.register(new DefaultProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
+ Service helloService = _registry.register(new AbstractProvidedInterfaceDescriptor("hello", HelloService.class), helloObject);
Service[] services = system.start("Bla", new Service[] { helloService } );
assertEquals(1, services.length);