1 package org.wamblee.system;
3 import java.util.ArrayList;
4 import java.util.Arrays;
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
10 import sun.util.LocaleServiceProviderPool.LocalizedObjectGetter;
13 * Composite system consisting of multiple subsystems.
15 public class CompositeSystem extends AbstractSubSystem {
17 private static final Log LOG = LogFactory.getLog(CompositeSystem.class);
19 private SubSystem[] _systems;
22 * Construcst the composite system.
23 * @param aName Name of the system.
24 * @param aRegistry Service registry.
25 * @param aSystems Subsystems.
26 * @param aProvided Provided services of the system.
27 * @param aRequired Required services by the system.
29 public CompositeSystem(String aName, ServiceRegistry aRegistry, SubSystem[] aSystems,
30 ServiceDescriptor[] aProvided, ServiceDescriptor[] aRequired) {
31 super(aName, aRegistry, aProvided, aRequired);
37 * Validates the subsystems together to check that there are
38 * no required services not in the required list and
39 * no services in the provided list that cannot be provided.
40 * Also logs a warning in case of superfluous requirements.
42 private void validate() {
43 List<ServiceDescriptor> provided = new ArrayList<ServiceDescriptor>();
44 for (SubSystem system : _systems) {
45 provided.addAll(Arrays.asList(system.getProvidedServices()));
48 List<ServiceDescriptor> required = new ArrayList<ServiceDescriptor>();
49 for (SubSystem system : _systems) {
50 required.addAll(Arrays.asList(system.getRequiredServices()));
53 for (ServiceDescriptor service : getProvidedServices()) {
54 if (!(provided.contains(service))) {
55 throw new SystemAssemblyException(getName() + ": Service '" + service
56 + "' is not provided by any of the subsystems");
60 for (ServiceDescriptor service : getRequiredServices()) {
61 if (!(required.contains(service))) {
64 + "' indicated as required is not actually required by any of the subsystems");
68 List<ServiceDescriptor> reallyRequired = new ArrayList<ServiceDescriptor>(
70 for (ServiceDescriptor service : provided) {
71 reallyRequired.remove(service);
73 for (ServiceDescriptor service: getRequiredServices()) {
74 reallyRequired.remove(service);
76 for (ServiceDescriptor service: reallyRequired) {
77 throw new SystemAssemblyException(getName() + ": " + "Service '" + service + "' is not provided internally and is not indicated as required for this sub system");
82 protected void doStart(String aContext, Service[] aRequiredServices) {
83 List<ProvidedServiceDescriptor> descriptors = new ArrayList<ProvidedServiceDescriptor>();
84 for (Service service : aRequiredServices) {
85 descriptors.add(service.getDescriptor());
87 SystemAssembler assembler = new SystemAssembler(aContext + "." + getName(), _systems,
88 descriptors.toArray(new ProvidedServiceDescriptor[0]));
89 assembler.start(getRegistry(), aRequiredServices);
93 protected void doStop() {
97 private void info(String aMsg) {
98 LOG.info(getName() + ": " + aMsg);