LOG.info("Initializing '" + aContext + "." + _name + "'");
doStart(aContext + "." + getName());
_status = Status.RUNNING;
+ if ( _running.size() != _provided.size()) {
+ List<ProvidedInterface> remaining =
+ new ArrayList<ProvidedInterface>(_provided);
+ remaining.removeAll(_running);
+ throw new SystemAssemblyException(aContext + "." + getName() + ": not all services were started, missing " + remaining);
+ }
}
/**
*
* @author Erik Brakkee
*/
-public class DefaultProvidedInterfaceDescriptor implements ProvidedInterface {
+public class DefaultProvidedInterface implements ProvidedInterface {
private String _name;
private Class[] _interfaces;
* Constructs the descriptor.
* @param aInterface Type of service.
*/
- public DefaultProvidedInterfaceDescriptor(String aName, Class aInterface) {
+ public DefaultProvidedInterface(String aName, Class aInterface) {
_name = aName;
_interfaces = new Class[] { aInterface };
}
- public DefaultProvidedInterfaceDescriptor(String aName, Class[] aInterfaces) {
+ public DefaultProvidedInterface(String aName, Class[] aInterfaces) {
_name = aName;
_interfaces = Arrays.copyOf(aInterfaces, aInterfaces.length);
}
@Override
public boolean equals(Object obj) {
- if ( !(obj instanceof DefaultProvidedInterfaceDescriptor)) {
+ if ( !(obj instanceof DefaultProvidedInterface)) {
return false;
}
- DefaultProvidedInterfaceDescriptor descr = (DefaultProvidedInterfaceDescriptor)obj;
+ DefaultProvidedInterface descr = (DefaultProvidedInterface)obj;
if ( _interfaces.length != descr._interfaces.length ) {
return false;
}
import java.util.Arrays;
-public class DefaultRequiredInterfaceDescriptor implements RequiredInterface {
+public class DefaultRequiredInterface implements RequiredInterface {
private String _name;
private Class[] _required;
private ProvidedInterface _provider;
- public DefaultRequiredInterfaceDescriptor(String aName, Class aInterface) {
+ public DefaultRequiredInterface(String aName, Class aInterface) {
this(aName, new Class[] { aInterface });
}
- public DefaultRequiredInterfaceDescriptor(String aName, Class[] aInterfaces) {
+ public DefaultRequiredInterface(String aName, Class[] aInterfaces) {
_name = aName;
_required = aInterfaces;
}
@Override
public boolean equals(Object obj) {
- if ( !(obj instanceof DefaultRequiredInterfaceDescriptor)) {
+ if ( !(obj instanceof DefaultRequiredInterface)) {
return false;
}
- DefaultRequiredInterfaceDescriptor descr = (DefaultRequiredInterfaceDescriptor)obj;
+ DefaultRequiredInterface descr = (DefaultRequiredInterface)obj;
if ( _required.length != descr._required.length ) {
return false;
}
private static RequiredInterface[] required() {
return
new RequiredInterface[] {
- new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class),
- new DefaultRequiredInterfaceDescriptor("integer", Integer.class)
+ new DefaultRequiredInterface("datasource", DataSource.class),
+ new DefaultRequiredInterface("integer", Integer.class)
};
}
public class DefaultInterfaceDescriptorTest extends TestCase {
public void testOneRequiredOneProvidedMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", String.class);
assertTrue(required.implementedBy(provided));
}
public void testOneRequiredOneProvidedMatchSubClass() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", Integer.class);
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
+ ProvidedInterface provided = new DefaultProvidedInterface("name", Integer.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
assertTrue(required.implementedBy(provided));
}
public void testOneRequiredOneProvidedNoMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name", String.class);
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", Number.class);
+ ProvidedInterface provided = new DefaultProvidedInterface("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", Number.class);
assertFalse(required.implementedBy(provided));
}
public void testOneRequiredMultipleProvidedMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
new Class[] { String.class, Integer.class} );
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name", String.class);
+ RequiredInterface required = new DefaultRequiredInterface("name", String.class);
assertTrue(required.implementedBy(provided));
}
}
public void testMultipleRequiredOneProvidedMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
MyMultiple.class );
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterface("name",
new Class[] {Runnable.class, Serializable.class} );
assertTrue(required.implementedBy(provided));
}
public void testMultipleRequiredOneProvidedNoMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
MyMultiple.class );
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterface("name",
new Class[] { String.class, Runnable.class} );
assertFalse(required.implementedBy(provided));
}
public void testMultipleRequiredMultipleProvidedMatch() {
- ProvidedInterface provided = new DefaultProvidedInterfaceDescriptor("name",
+ ProvidedInterface provided = new DefaultProvidedInterface("name",
new Class[] { Runnable.class, Serializable.class, String.class} );
- RequiredInterface required = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface required = new DefaultRequiredInterface("name",
new Class[] {Runnable.class, Serializable.class} );
assertTrue(required.implementedBy(provided));
}
private static final ProvidedInterface[] provided() {
return new ProvidedInterface[] {
- new DefaultProvidedInterfaceDescriptor("datasource", DataSource.class),
- new DefaultProvidedInterfaceDescriptor("integer", Integer.class)
+ new DefaultProvidedInterface("datasource", DataSource.class),
+ new DefaultProvidedInterface("integer", Integer.class)
};
}
}
public void testFilterProvided() {
- RequiredInterface req1 = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface req1 = new DefaultRequiredInterface("name",
Runnable.class);
- RequiredInterface req2 = new DefaultRequiredInterfaceDescriptor("name",
+ RequiredInterface req2 = new DefaultRequiredInterface("name",
Serializable.class);
- ProvidedInterface prov1 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov1 = new DefaultProvidedInterface(
"name", Runnable.class);
- ProvidedInterface prov2 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov2 = new DefaultProvidedInterface(
"name", Serializable.class);
- ProvidedInterface prov3 = new DefaultProvidedInterfaceDescriptor(
+ ProvidedInterface prov3 = new DefaultProvidedInterface(
"name", MyMultiple.class);
AssertionUtils.assertEquals(new RequiredInterface[] { req1 },
Container system = new Container(
"all",
new Component[] { environment, application },
- new ProvidedInterface[] { new DefaultProvidedInterfaceDescriptor(
+ new ProvidedInterface[] { new DefaultProvidedInterface(
"string", String.class) },
- new DefaultRequiredInterfaceDescriptor[0]);
+ new DefaultRequiredInterface[0]);
} catch (SystemAssemblyException e) {
return;
}
"all",
new Component[] { environment, application },
new ProvidedInterface[0],
- new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor(
+ new RequiredInterface[] { new DefaultRequiredInterface(
"string", String.class) });
system.start("root");
} catch (SystemAssemblyException e) {
"all",
new Component[] { environment, application },
new ProvidedInterface[0],
- new RequiredInterface[] { new DefaultRequiredInterfaceDescriptor(
+ new RequiredInterface[] { new DefaultRequiredInterface(
"string", String.class) });
system.getRequiredServices()[0].setProvider(
- new DefaultProvidedInterfaceDescriptor("hallo", String.class));
+ new DefaultProvidedInterface("hallo", String.class));
system.start("root");
RequiredInterface[] required = system.getRequiredServices();
assertEquals(1, required.length);
import org.wamblee.system.AbstractComponent;
import org.wamblee.system.ProvidedInterface;
import org.wamblee.system.RequiredInterface;
-import org.wamblee.system.Service;
-import org.wamblee.system.SystemAssembler;
import org.wamblee.system.SystemAssemblyException;
/**
import junit.framework.TestCase;
import org.wamblee.io.ClassPathResource;
-import org.wamblee.system.DefaultProvidedInterfaceDescriptor;
-import org.wamblee.system.DefaultRequiredInterfaceDescriptor;
-import org.wamblee.system.DefaultService;
+import org.wamblee.system.DefaultProvidedInterface;
+import org.wamblee.system.DefaultRequiredInterface;
import org.wamblee.system.ProvidedInterface;
import org.wamblee.system.RequiredInterface;
-import org.wamblee.system.Service;
import org.wamblee.system.SystemAssemblyException;
public class SpringComponentTest extends TestCase {
public void testOneProvidedService() {
Map<String, ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
- provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
+ provided.put("helloService", new DefaultProvidedInterface(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system",
public void testWithProperties() throws IOException {
Map<String, ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
- provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
+ provided.put("helloService", new DefaultProvidedInterface(
"hello", HelloService.class));
SpringComponent system = new SpringComponent("system",
new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML },
public void testWithRequirement() {
Map<RequiredInterface, String> required = new HashMap<RequiredInterface, String>();
- required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
+ required.put(new DefaultRequiredInterface("hello", HelloService.class),
"helloService");
SpringComponent system = new SpringComponent("system",
new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
new HashMap<String, ProvidedInterface>(), required);
HelloService helloObject = new HelloService("ladida");
- ProvidedInterface helloService = new DefaultProvidedInterfaceDescriptor("hello", HelloService.class);
+ ProvidedInterface helloService = new DefaultProvidedInterface("hello", HelloService.class);
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
public void testWithRequirementAndProvidedService() {
Map<RequiredInterface, String> required = new HashMap<RequiredInterface, String>();
- required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
+ required.put(new DefaultRequiredInterface("hello", HelloService.class),
"helloService");
Map<String,ProvidedInterface> provided = new HashMap<String, ProvidedInterface>();
- provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla",
+ provided.put("blaService", new DefaultProvidedInterface("bla",
BlaService.class));
SpringComponent system = new SpringComponent("system",
HelloService helloObject = new HelloService("ladida");
ProvidedInterface helloService =
- new DefaultProvidedInterfaceDescriptor("hello", HelloService.class);
+ new DefaultProvidedInterface("hello", HelloService.class);
helloService.publish(helloObject);
system.getRequiredServices()[0].setProvider(helloService);
system.start("Bla");