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 aSystems Subsystems.
25 * @param aProvided Provided services of the system.
26 * @param aRequired Required services by the system.
28 public CompositeSystem(String aName, SubSystem[] aSystems,
29 ServiceDescriptor[] aProvided, ServiceDescriptor[] aRequired) {
30 super(aName, aProvided, aRequired);
36 * Validates the subsystems together to check that there are
37 * no required services not in the required list and
38 * no services in the provided list that cannot be provided.
39 * Also logs a warning in case of superfluous requirements.
41 private void validate() {
42 List<ServiceDescriptor> provided = new ArrayList<ServiceDescriptor>();
43 for (SubSystem system : _systems) {
44 provided.addAll(Arrays.asList(system.getProvidedServices()));
47 List<ServiceDescriptor> required = new ArrayList<ServiceDescriptor>();
48 for (SubSystem system : _systems) {
49 required.addAll(Arrays.asList(system.getRequiredServices()));
52 for (ServiceDescriptor service : getProvidedServices()) {
53 if (!(provided.contains(service))) {
54 throw new SystemAssemblyException(getName() + ": Service '" + service
55 + "' is not provided by any of the subsystems");
59 for (ServiceDescriptor service : getRequiredServices()) {
60 if (!(required.contains(service))) {
63 + "' indicated as required is not actually required by any of the subsystems");
67 List<ServiceDescriptor> reallyRequired = new ArrayList<ServiceDescriptor>(
69 for (ServiceDescriptor service : provided) {
70 reallyRequired.remove(service);
72 for (ServiceDescriptor service: getRequiredServices()) {
73 reallyRequired.remove(service);
75 for (ServiceDescriptor service: reallyRequired) {
76 throw new SystemAssemblyException(getName() + ": " + "Service '" + service + "' is not provided internally and is not indicated as required for this sub system");
81 protected void doInitialize(String aContext, Service[] aRequiredServices) {
82 List<ServiceDescriptor> descriptors = new ArrayList<ServiceDescriptor>();
83 for (Service service : aRequiredServices) {
84 descriptors.add(service.getDescriptor());
86 SystemAssembler assembler = new SystemAssembler(getName(), _systems,
87 descriptors.toArray(new ServiceDescriptor[0]));
88 assembler.start(aRequiredServices);
91 private void info(String aMsg) {
92 LOG.info(getName() + ": " + aMsg);