*/
package org.wamblee.system.adapters;
+import org.wamblee.system.container.Container;
import org.wamblee.system.core.Component;
-import org.wamblee.system.core.Container;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+
/**
* Composite restriction that wraps a number of other restrictions. The restriction is
--- /dev/null
+/*
+ * Copyright 2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.container;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wamblee.general.Pair;
+import org.wamblee.system.core.AbstractComponent;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.DefaultScope;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.component.ComponentGraph;
+
+/**
+ * Container consisting of multiple components.
+ *
+ * @author Erik Brakkee
+ */
+public class Container extends AbstractComponent<Scope> {
+
+ private static final Log LOG = LogFactory.getLog(Container.class);
+
+ private List<Component> _components;
+ private Set<String> _componentNames;
+ private CompositeInterfaceRestriction _restriction;
+ private boolean _sealed;
+
+ /**
+ * Constructs the container
+ *
+ * @param aName
+ * Name of the container
+ * @param aComponents
+ * Components.
+ * @param aProvided
+ * Provided services of the container
+ * @param aRequired
+ * Required services by the container.
+ */
+ public Container(String aName, Component[] aComponents,
+ ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
+ super(aName, aProvided, aRequired);
+ _components = new ArrayList<Component>();
+
+ _componentNames = new HashSet<String>();
+ _restriction = new CompositeInterfaceRestriction();
+ _sealed = false;
+ for (Component component : aComponents) {
+ addComponent(component);
+ }
+ }
+
+ public Container(String aName) {
+ this(aName, new Component[0], new ProvidedInterface[0],
+ new RequiredInterface[0]);
+ }
+
+ public Container addComponent(Component aComponent) {
+ checkSealed();
+ if (aComponent.getContext() != null) {
+ throw new SystemAssemblyException(
+ "Inconsistent hierarchy, component '"
+ + aComponent.getName()
+ + "' is already part of another hierarchy");
+ }
+ if (_componentNames.contains(aComponent.getName())) {
+ throw new SystemAssemblyException("Duplicate component '"
+ + aComponent.getName() + "'");
+ }
+ _components.add(aComponent);
+ _componentNames.add(aComponent.getName());
+ aComponent.addContext(getQualifiedName());
+ return this;
+ }
+
+ /**
+ * Adds an interface restriction for explicitly configuring the relations
+ * between components.
+ *
+ * @param aRestriction
+ * Restriction to add.
+ * @return Reference to this to allow call chaining.
+ */
+ public Container addRestriction(InterfaceRestriction aRestriction) {
+ checkSealed();
+ _restriction.add(aRestriction);
+ return this;
+ }
+
+ @Override
+ public Container addProvidedInterface(ProvidedInterface aProvided) {
+ checkSealed();
+ super.addProvidedInterface(aProvided);
+ return this;
+ }
+
+ @Override
+ public Container addRequiredInterface(RequiredInterface aRequired) {
+ checkSealed();
+ super.addRequiredInterface(aRequired);
+ return this;
+ }
+
+ @Override
+ public void addContext(String aContext) {
+ super.addContext(aContext);
+ for (Component component : _components) {
+ component.addContext(aContext);
+ }
+ }
+
+ /**
+ * Validates the components together to check that there are no required
+ * services not in the required list and no services in the provided list
+ * that cannot be provided. Also logs a warning in case of superfluous
+ * requirements.
+ *
+ * @throws SystemAssemblyException
+ * in case of any validation problems.
+ */
+ public void validate() {
+ doStartOptionalDryRun(null, true);
+ }
+
+ /**
+ * Seal the container, meaning that no further components or interfaces may
+ * be added.
+ */
+ public void seal() {
+ _sealed = true;
+ }
+
+ /**
+ * Checks if the container is sealed.
+ *
+ * @return True iff the container is sealed.
+ */
+ public boolean isSealed() {
+ return _sealed;
+ }
+
+ /**
+ * Utility method to start with an empty external scope. This is useful for
+ * top-level containers which are not part of another container.
+ *
+ * @return Scope.
+ */
+ public Scope start() {
+ Scope scope = new DefaultScope(getProvidedInterfaces());
+ return super.start(scope);
+ }
+
+ @Override
+ protected Scope doStart(Scope aExternalScope) {
+ checkSealed();
+ validate();
+ Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
+ ComponentGraph graph = doStartOptionalDryRun(scope, false);
+ exposeProvidedInterfaces(graph, aExternalScope, scope);
+ seal();
+ return scope;
+ }
+
+ private void exposeProvidedInterfaces(ComponentGraph aGraph, Scope aExternalScope,
+ Scope aInternalScope) {
+ for (Pair<ProvidedInterface,ProvidedInterface> mapping:
+ aGraph.findExternalProvidedInterfaceMapping()) {
+ Object svc = aInternalScope.getInterfaceImplementation(mapping.getSecond(), Object.class);
+ addInterface(mapping.getFirst(), svc, aExternalScope);
+ }
+ }
+
+ private ComponentGraph doStartOptionalDryRun(Scope aScope, boolean aDryRun) {
+ ComponentGraph graph = createComponentGraph();
+ graph.validate();
+ if (!aDryRun) {
+ graph.link();
+ }
+
+ LOG.info("Starting '" + getQualifiedName() + "'");
+
+ List<Component> started = new ArrayList<Component>();
+ for (Component component : _components) {
+ try {
+ // Start the service.
+ if (!aDryRun) {
+ Object runtime = component.start(aScope);
+ aScope.addRuntime(component, runtime);
+ started.add(component);
+ }
+ } catch (SystemAssemblyException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ LOG.error(getQualifiedName() + ": could not start '"
+ + component.getQualifiedName() + "'", e);
+ stopAlreadyStartedComponents(started, aScope);
+ throw e;
+ }
+ }
+ return graph;
+ }
+
+ private ComponentGraph createComponentGraph() {
+ ComponentGraph graph = new ComponentGraph();
+ for (RequiredInterface req : getRequiredInterfaces()) {
+ graph.addRequiredInterface(req);
+ }
+ for (Component comp : _components) {
+ graph.addComponent(comp);
+ }
+ for (ProvidedInterface prov: getProvidedInterfaces()) {
+ graph.addProvidedInterface(prov);
+ }
+
+ graph.addRestriction(_restriction);
+ return graph;
+ }
+
+ private void stopAlreadyStartedComponents(List<Component> aStarted,
+ Scope aScope) {
+ // an exception occurred, stop the successfully started
+ // components
+ for (int i = aStarted.size() - 1; i >= 0; i--) {
+ try {
+ Component component = aStarted.get(i);
+ aStarted.get(i).stop(aScope.getRuntime(component));
+ } catch (Throwable t) {
+ LOG.error(getQualifiedName() + ": error stopping "
+ + aStarted.get(i).getQualifiedName());
+ }
+ }
+ }
+
+ @Override
+ protected void doStop(Scope aScope) {
+ for (int i = _components.size() - 1; i >= 0; i--) {
+ Component component = _components.get(i);
+ Object runtime = aScope.getRuntime(component);
+ component.stop(runtime);
+ }
+ }
+
+ private void checkSealed() {
+ if (_sealed) {
+ throw new SystemAssemblyException("Container is sealed");
+ }
+ }
+}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
+
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
/**
* An interface restriction on the required interface of a component.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
+
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
/**
* Interface restriction for restricting the linking of provided and required
+++ /dev/null
-/*
- * Copyright 2007 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.system.core;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wamblee.collections.CollectionFilter;
-import org.wamblee.conditions.Condition;
-import org.wamblee.general.Pair;
-
-/**
- * Container consisting of multiple components.
- *
- * @author Erik Brakkee
- */
-public class Container extends AbstractComponent<Scope> {
-
- private static final Log LOG = LogFactory.getLog(Container.class);
-
- private List<Component> _components;
- private Set<String> _componentNames;
- private CompositeInterfaceRestriction _restriction;
- private boolean _sealed;
-
- static ProvidedInterface[] filterProvidedServices(
- Component aClient, RequiredInterface aRequired, Collection<Pair<ProvidedInterface,Component>> aProvided,
- InterfaceRestriction aRestriction) {
- List<ProvidedInterface> result = new ArrayList<ProvidedInterface>();
- for (Pair<ProvidedInterface,Component> descriptor : aProvided) {
- ProvidedInterface provided = descriptor.getFirst();
- Component server = descriptor.getSecond();
- if (aRequired.implementedBy(provided) &&
- !aRestriction.isViolated(aClient, aRequired, server, provided)) {
- result.add(provided);
- }
- }
- return result.toArray(new ProvidedInterface[0]);
- }
-
- /**
- * Constructs the container
- *
- * @param aName
- * Name of the container
- * @param aComponents
- * Components.
- * @param aProvided
- * Provided services of the container
- * @param aRequired
- * Required services by the container.
- */
- public Container(String aName, Component[] aComponents,
- ProvidedInterface[] aProvided, RequiredInterface[] aRequired) {
- super(aName, aProvided, aRequired);
- _components = new ArrayList<Component>();
-
- _componentNames = new HashSet<String>();
- _restriction = new CompositeInterfaceRestriction();
- _sealed = false;
- for (Component component : aComponents) {
- addComponent(component);
- }
- }
-
- public Container(String aName) {
- this(aName, new Component[0], new ProvidedInterface[0],
- new RequiredInterface[0]);
- }
-
- public Container addComponent(Component aComponent) {
- checkSealed();
- if (aComponent.getContext() != null) {
- throw new SystemAssemblyException(
- "Inconsistent hierarchy, component '"
- + aComponent.getName()
- + "' is already part of another hierarchy");
- }
- if (_componentNames.contains(aComponent.getName())) {
- throw new SystemAssemblyException("Duplicate component '"
- + aComponent.getName() + "'");
- }
- _components.add(aComponent);
- _componentNames.add(aComponent.getName());
- aComponent.addContext(getQualifiedName());
- return this;
- }
-
- /**
- * Adds an interface restriction for explicitly configuring the
- * relations between components.
- * @param aRestriction Restriction to add.
- * @return Reference to this to allow call chaining.
- */
- public Container addRestriction(InterfaceRestriction aRestriction) {
- checkSealed();
- _restriction.add(aRestriction);
- return this;
- }
-
- @Override
- public Container addProvidedInterface(ProvidedInterface aProvided) {
- checkSealed();
- super.addProvidedInterface(aProvided);
- return this;
- }
-
- @Override
- public Container addRequiredInterface(RequiredInterface aRequired) {
- checkSealed();
- super.addRequiredInterface(aRequired);
- return this;
- }
-
- @Override
- public void addContext(String aContext) {
- super.addContext(aContext);
- for (Component component: _components) {
- component.addContext(aContext);
- }
- }
-
- /**
- * Validates the components together to check that there are no required
- * services not in the required list and no services in the provided list
- * that cannot be provided. Also logs a warning in case of superfluous
- * requirements.
- *
- * @throws SystemAssemblyException
- * in case of any validation problems.
- */
- public void validate() {
- validateProvidedInterfacesArePresent();
-
- validateRequiredInterfaces();
-
- doStartOptionalDryRun(null, true);
- }
-
- private void validateRequiredInterfaces() {
- List<RequiredInterface> required = new ArrayList<RequiredInterface>();
- for (Component component : _components) {
- required.addAll(Arrays.asList(component.getRequiredInterfaces()));
- }
-
- for (RequiredInterface service : getRequiredInterfaces()) {
- // TODO required interfaces by the component could be
- // subclasses or implementations of the requirements
- // of the contained components. The code below assumes
- // an exact match.
- if (!(required.contains(service))) {
- info("Service '"
- + service
- + "' indicated as required is not actually required by any of the components");
- }
- // Check for the case that the externally required service
- // is optional whereas the internally required service is
- // mandatory.
- if (service.isOptional()) {
- for (RequiredInterface intf : required) {
- if (intf.equals(service) && !intf.isOptional()) {
- warn("Required service '"
- + service
- + "' indicated as optional is mandatory by one of its components ("
- + getClients(intf)
- + ", "
- + intf
- + "), this can lead to problems when the container is started and the interface is not provided to the container.");
- }
- }
- }
- }
- }
-
- private void validateProvidedInterfacesArePresent() {
- for (ProvidedInterface service : getProvidedInterfaces()) {
- findProvidedInterface(service);
- }
- }
-
- /**
- * Finds the component and provided interface that matches a provided interface of this
- * container.
- * @param aProvided Interface to provide externally.
- * @return Pair of component and provided interface
- * @throws SystemAssemblyException In case there are multiple matches or no match at all.
- */
- private Pair<Component,ProvidedInterface> findProvidedInterface(ProvidedInterface aProvided) {
- List<Pair<Component,ProvidedInterface>> result =
- new ArrayList<Pair<Component,ProvidedInterface>>();
- for (Component component: _components) {
- for (ProvidedInterface provided: component.getProvidedInterfaces()) {
- if ( aProvided.equals(provided) ) {
- result.add(new Pair<Component,ProvidedInterface>(component, provided));
- }
- }
- }
- if ( result.size() == 0) {
- throw new SystemAssemblyException(getQualifiedName() + ": Service '"
- + aProvided
- + "' is not provided by any of its components");
- }
- if ( result.size() > 1) {
- throw new SystemAssemblyException(getQualifiedName() + ": Service '"
- + aProvided
- + "' is provided by multiple components: " + result);
- }
- return result.get(0);
- }
-
-
- /**
- * Seal the container, meaning that no further components or interfaces may
- * be added.
- */
- public void seal() {
- _sealed = true;
- }
-
- /**
- * Checks if the container is sealed.
- *
- * @return True iff the container is sealed.
- */
- public boolean isSealed() {
- return _sealed;
- }
-
- /**
- * Utility method to start with an empty external scope. This is useful for
- * top-level containers which are not part of another container.
- * @return Scope.
- */
- public Scope start() {
- Scope scope = new DefaultScope(getProvidedInterfaces());
- return super.start(scope);
- }
-
- @Override
- protected Scope doStart(Scope aExternalScope) {
- checkSealed();
- validate();
- Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
- doStartOptionalDryRun(scope, false);
- exposeProvidedInterfaces(aExternalScope, scope);
- seal();
- return scope;
- }
-
- private void exposeProvidedInterfaces(Scope aExternalScope, Scope aInternalScope) {
- for (ProvidedInterface intf: getProvidedInterfaces()) {
- Pair<Component, ProvidedInterface> found = findProvidedInterface(intf);
- Object svc = aInternalScope.getInterfaceImplementation(found.getSecond(), Object.class);
- addInterface(intf, svc, aExternalScope);
- }
- }
-
- private void doStartOptionalDryRun(Scope aScope, boolean aDryRun) {
- LOG.info("Starting '" + getQualifiedName() + "'");
-
- List<Pair<ProvidedInterface,Component>> allProvided = new ArrayList<Pair<ProvidedInterface,Component>>();
-
- addProvidersOfRequiredInterfaces(allProvided);
-
- List<Component> started = new ArrayList<Component>();
- for (Component component : _components) {
- try {
- initializeProvidersForRequiredInterfaces(allProvided,
- component, aDryRun);
-
- // Start the service.
- if (!aDryRun) {
- Object runtime = component.start(aScope);
- aScope.addRuntime(component, runtime);
- started.add(component);
- }
-
- // add all provided services
- ProvidedInterface[] provided = component
- .getProvidedInterfaces();
- for (ProvidedInterface prov: provided) {
- allProvided.add(new Pair<ProvidedInterface,Component>(prov, component));
- }
- } catch (SystemAssemblyException e) {
- throw e;
- } catch (RuntimeException e) {
- LOG.error(getQualifiedName() + ": could not start '"
- + component.getQualifiedName() + "'", e);
- stopAlreadyStartedComponents(started, aScope);
- throw e;
- }
- }
- }
-
- private void addProvidersOfRequiredInterfaces(
- List<Pair<ProvidedInterface,Component>> allProvided) {
- // all interfaces from the required list of this container are
- // provided to the components inside it.
- RequiredInterface[] required = getRequiredInterfaces();
- for (RequiredInterface intf : required) {
- ProvidedInterface provider = intf.getProvider();
- if (provider != null) {
- allProvided.add(new Pair<ProvidedInterface,Component>(provider, null));
- } else {
- if (!intf.isOptional()) {
- throw new SystemAssemblyException(getQualifiedName()
- + ": required interface '" + intf
- + "' is not provided");
- }
- }
- }
- }
-
- private void stopAlreadyStartedComponents(List<Component> aStarted,
- Scope aScope) {
- // an exception occurred, stop the successfully started
- // components
- for (int i = aStarted.size() - 1; i >= 0; i--) {
- try {
- Component component = aStarted.get(i);
- aStarted.get(i).stop(aScope.getRuntime(component));
- } catch (Throwable t) {
- LOG.error(getQualifiedName() + ": error stopping "
- + aStarted.get(i).getQualifiedName());
- }
- }
- }
-
- /**
- * Sets the provided interface or a component.
- *
- * @param aAllProvided
- * All available provided interfaces.
- * @param aComponent
- * Component whose required interfaces we are looking at.
- * @param aValidateOnly
- * If true then the provider will not be set for required
- * interfaces.
- */
- private void initializeProvidersForRequiredInterfaces(
- List<Pair<ProvidedInterface,Component>> aAllProvided, Component aComponent,
- boolean aValidateOnly) {
- // Check if all required services are already provided by
- // earlier
- // systems.
-
- for (RequiredInterface descriptor : aComponent.getRequiredInterfaces()) {
- ProvidedInterface[] filtered = filterProvidedServices(aComponent, descriptor,
- aAllProvided, _restriction);
- if (filtered.length == 1) {
- if (!aValidateOnly) {
- descriptor.setProvider(filtered[0]);
- }
- } else if (filtered.length > 1) {
- throw new SystemAssemblyException(
- "Service '"
- + descriptor
- + "' required by system '"
- + aComponent
- + "' matches multiple services provided by other systems: "
- + getServers(filtered));
- } else {
- // filtered.length == 0
- if (!descriptor.isOptional()) {
- throw new SystemAssemblyException(
- "Service '"
- + descriptor
- + "' required by system '"
- + aComponent
- + "' is not provided by systems that are started earlier");
- }
- }
- }
- }
-
- @Override
- protected void doStop(Scope aScope) {
- for (int i = _components.size() - 1; i >= 0; i--) {
- Component component = _components.get(i);
- Object runtime = aScope.getRuntime(component);
- component.stop(runtime);
- }
- }
-
- private void info(String aMsg) {
- LOG.info(getQualifiedName() + ": " + aMsg);
- }
-
- private void warn(String aMsg) {
- LOG.warn(getQualifiedName() + ": " + aMsg);
- }
-
- private String getServers(ProvidedInterface[] aProvidedList) {
- String result = "";
- for (ProvidedInterface provided : aProvidedList) {
- result += "(components ";
- for (Component component : _components) {
- for (ProvidedInterface provided2 : component
- .getProvidedInterfaces()) {
- if (provided.equals(provided2)) {
- result += component + " ";
- }
- }
- }
- result += ", interface " + provided + ")";
- }
- return result;
- }
-
- private List<Component> getClients(RequiredInterface aRequirement) {
- List<Component> clients = new ArrayList<Component>();
- for (Component component : _components) {
- for (RequiredInterface required : component.getRequiredInterfaces()) {
- if (required.equals(aRequirement)
- && required.isOptional() == aRequirement.isOptional()) {
- clients.add(component);
- }
- }
- }
- return clients;
- }
-
- private void checkSealed() {
- if (_sealed) {
- throw new SystemAssemblyException("Container is sealed");
- }
- }
-}
public Node getTo() {
return _to;
}
+
+ @Override
+ public String toString() {
+ return "Edge(" + _from.getName() + ", " + _to.getName() + ")";
+ }
}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.List;
+
+import org.wamblee.system.container.InterfaceRestriction;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Graph;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+public class ApplyRestrictionsVisitor implements Visitor {
+
+ private Graph _graph;
+ private InterfaceRestriction _restriction;
+
+ public ApplyRestrictionsVisitor(Graph aGraph, InterfaceRestriction aRestriction) {
+ _graph = aGraph;
+ _restriction = aRestriction;
+ }
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ if ( aEdge.getFrom() instanceof RequiredInterfaceNode &&
+ aEdge.getTo() instanceof ProvidedInterfaceNode) {
+ RequiredInterfaceNode from = (RequiredInterfaceNode)aEdge.getFrom();
+ ProvidedInterfaceNode to = (ProvidedInterfaceNode) aEdge.getTo();
+
+ if ( _restriction.isViolated(from.getComponent(), from.getRequired(), to.getComponent(), to.getProvided())) {
+ _graph.removeEdge(aEdge);
+ }
+ }
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ // Empty
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.List;
+
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Graph;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+/**
+ * Visitor that checks externally provided
+ * <ul>
+ * <li>
+ * </ul>
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class CheckExternallyProvidedVisitor implements Visitor {
+
+ private Graph _graph;
+
+ public CheckExternallyProvidedVisitor(Graph aGraph) {
+ _graph = aGraph;
+ }
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ // Empty.
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ if ( aNode instanceof ExternalProvidedInterfaceNode) {
+ ExternalProvidedInterfaceNode provided = (ExternalProvidedInterfaceNode) aNode;
+ List<Edge> edges = _graph.findOutgoing(provided);
+ if ( edges.size() > 2 ) {
+ createDuplicateException("External provided interfaces has multiple internal matches", aNode, edges);
+ }
+ if ( edges.size() == 0 ) {
+ throw new SystemAssemblyException(aNode + ": external provded interface is not provided by any of the internal components");
+ }
+ }
+ }
+
+ private void createDuplicateException(String aMsg, Node aNode, List<Edge> edges) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(aNode
+ + ": " + aMsg + ": ");
+ for (Edge edge : edges) {
+ buf.append(edge.getTo() + "/ ");
+ }
+ throw new SystemAssemblyException(buf.toString());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+/**
+ * Visitor that checks externally required services:
+ * <ul>
+ * <li>
+ * </ul>
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class CheckExternallyRequiredVisitor implements Visitor {
+
+ public CheckExternallyRequiredVisitor() {
+ // Empty.
+ }
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ // Empty.
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ if ( aNode instanceof ExternalRequiredInterfaceNode) {
+ ExternalRequiredInterfaceNode required = (ExternalRequiredInterfaceNode) aNode;
+ if ( !required.getRequired().isOptional() && required.getRequired().getProvider() == null) {
+ throw new SystemAssemblyException(aNode + ": External required interface is not provided");
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.List;
+
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Graph;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+/**
+ * Visitor that checks whether required and provided interfaces are matched
+ * appropriately:
+ * <ul>
+ * <li>Each required interface is connected to at most one provided interface
+ * </li>
+ * <li>Required interfaces that are not optional must be connected to precisely
+ * one provided interface</li>
+ * </ul>
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class CheckRequiredProvidedMultiplicityVisitor implements Visitor {
+
+ private Graph _graph;
+
+ public CheckRequiredProvidedMultiplicityVisitor(Graph aGraph) {
+ _graph = aGraph;
+ }
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ // Empty
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ if (aNode instanceof RequiredInterfaceNode) {
+ RequiredInterfaceNode required = (RequiredInterfaceNode) aNode;
+ List<Edge> edges = _graph.findOutgoing(aNode);
+ if (edges.size() > 1) {
+ createDuplicateException("Multiple internal providers of interface found", aNode, edges);
+ }
+ if (edges.size() == 0 && !required.getRequired().isOptional()) {
+ throw new SystemAssemblyException(
+ aNode
+ + ": mandatpory required interface not provided by other components started earlier");
+ }
+ } else if ( aNode instanceof ProvidedInterfaceNode) {
+ List<Edge> edges = _graph.findOutgoing(aNode);
+ if ( edges.size() > 1) {
+ createDuplicateException("multiple internal matches for externally provided interface", aNode, edges);
+ }
+ if ( edges.size() == 0 ) {
+ throw new SystemAssemblyException(aNode + ": external provided interface is not provided internally");
+ }
+ }
+ }
+
+ private void createDuplicateException(String aMsg, Node aNode, List<Edge> edges) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(aNode
+ + ": " + aMsg + ": ");
+ for (Edge edge : edges) {
+ buf.append(edge.getTo() + "/ ");
+ }
+ throw new SystemAssemblyException(buf.toString());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Graph;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+public class CheckStartupDependenciesVisitor implements Visitor {
+
+ private Graph _graph;
+ private List<Node> _available;
+
+ public CheckStartupDependenciesVisitor(Graph aGraph) {
+ _graph = aGraph;
+ _available = new ArrayList<Node>();
+ }
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ // Empty
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ List<Edge> edges = _graph.findOutgoing(aNode);
+
+ // check dependencies.
+ for (Edge edge: edges) {
+ Node dep = edge.getTo();
+ if ( !_available.contains(dep)) {
+ throw new SystemAssemblyException(aNode + ": required dependency '" + dep + "' was not started");
+ }
+ }
+
+ _available.add(aNode);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.wamblee.general.Pair;
+import org.wamblee.system.container.CompositeInterfaceRestriction;
+import org.wamblee.system.container.InterfaceRestriction;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.DefaultEdge;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Graph;
+import org.wamblee.system.graph.Node;
+
+
+// TODO info superfluous required interfaces
+// TODO check optional external required but mandatory internal.
+
+public class ComponentGraph extends Graph {
+
+ private CompositeInterfaceRestriction _restriction;
+
+ public ComponentGraph() {
+ _restriction = new CompositeInterfaceRestriction();
+ }
+
+ public void addRestriction(InterfaceRestriction aRestriction) {
+ _restriction.add(aRestriction);
+ }
+
+ public void addRequiredInterface(RequiredInterface aInterface) {
+ addNode(new ExternalRequiredInterfaceNode(aInterface));
+ }
+
+ public void addProvidedInterface(ProvidedInterface aInterface) {
+ addNode(new ExternalProvidedInterfaceNode(aInterface));
+ }
+
+ public void validate() {
+ extend(new RequiredProvidedEdgeFactory());
+ accept(new ApplyRestrictionsVisitor(this, _restriction));
+ accept(new CheckRequiredProvidedMultiplicityVisitor(this));
+ accept(new CheckExternallyRequiredVisitor());
+ accept(new CheckExternallyProvidedVisitor(this));
+ accept(new CheckStartupDependenciesVisitor(this));
+ }
+
+ public void link() {
+ accept(new LinkVisitor());
+ }
+
+ /**
+ * Finds a list of mappings of external provided interface to internal provided interface.
+ *
+ * @return List of pairs of external to internal interface.
+ */
+ public List<Pair<ProvidedInterface, ProvidedInterface>> findExternalProvidedInterfaceMapping() {
+ List<Pair<ProvidedInterface, ProvidedInterface>> result =
+ new ArrayList<Pair<ProvidedInterface,ProvidedInterface>>();
+ for (Edge edge: getEdges()) {
+ if ( edge.getFrom() instanceof ExternalProvidedInterfaceNode &&
+ edge.getTo() instanceof ProvidedInterfaceNode ) {
+ result.add(new Pair<ProvidedInterface,ProvidedInterface>(
+ ((ExternalProvidedInterfaceNode)edge.getFrom()).getProvided(),
+ ((ProvidedInterfaceNode)edge.getTo()).getProvided()
+ ));
+ }
+ }
+ return result;
+ }
+
+ public void addComponent(Component aComponent) {
+ // Add required interfaces.
+ Node compNode = new ComponentNode(aComponent);
+ List<Node> requiredNodes = new ArrayList<Node>();
+ for (RequiredInterface required: aComponent.getRequiredInterfaces()) {
+ Node reqNode = new RequiredInterfaceNode(aComponent, required);
+ addNode(reqNode);
+ requiredNodes.add(reqNode);
+ }
+ // Add the component
+ addNode(compNode);
+
+ // Edges from component to required interface.
+ for (Node reqNode: requiredNodes) {
+ addEdge(new DefaultEdge(compNode, reqNode));
+ }
+
+ // Add provided interfaces
+ List<Node> providedNodes = new ArrayList<Node>();
+ for (ProvidedInterface provided: aComponent.getProvidedInterfaces()) {
+ Node provNode = new ProvidedInterfaceNode(aComponent, provided);
+ addNode(provNode);
+ providedNodes.add(provNode);
+ }
+
+ // Edges from provided interface to component
+ for (Node provNode: providedNodes) {
+ addEdge(new DefaultEdge(provNode, compNode));
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.Component;
+import org.wamblee.system.graph.Node;
+
+public class ComponentNode implements Node {
+
+ private Component<?> _component;
+
+ public ComponentNode(Component<?> aComponent) {
+ _component = aComponent;
+ }
+
+ @Override
+ public String getName() {
+ return _component.getQualifiedName();
+ }
+
+ public Component<?> getComponent() {
+ return _component;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.graph.Node;
+
+public class ExternalProvidedInterfaceNode implements Node {
+
+ private ProvidedInterface _provided;
+
+ public ExternalProvidedInterfaceNode(ProvidedInterface aProvided) {
+ _provided = aProvided;
+ }
+
+ @Override
+ public String getName() {
+ return _provided.getName();
+ }
+
+ public ProvidedInterface getProvided() {
+ return _provided;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.Node;
+
+public class ExternalRequiredInterfaceNode implements Node {
+
+ private RequiredInterface _required;
+
+ public ExternalRequiredInterfaceNode(RequiredInterface aRequired) {
+ _required = aRequired;
+ }
+
+ @Override
+ public String getName() {
+ return _required.getName();
+ }
+
+ public RequiredInterface getRequired() {
+ return _required;
+ }
+
+ @Override
+ public String toString() {
+ return "EXTERNAL" + ":" + _required;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.SystemAssemblyException;
+import org.wamblee.system.graph.DefaultEdge;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.Node;
+import org.wamblee.system.graph.Visitor;
+
+/**
+ * Visitor that creates links between required and provided interfaces as
+ * described by the edges in the graph.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class LinkVisitor implements Visitor {
+
+ @Override
+ public void visitEdge(Edge aEdge) {
+ Node from = aEdge.getFrom();
+ Node to = aEdge.getTo();
+ if (from instanceof RequiredInterfaceNode) {
+ RequiredInterfaceNode required = (RequiredInterfaceNode) from;
+ if (to instanceof ProvidedInterfaceNode) {
+
+ ProvidedInterfaceNode provided = (ProvidedInterfaceNode) to;
+ required.getRequired().setProvider(provided.getProvided());
+
+ } else if (to instanceof ExternalRequiredInterfaceNode) {
+ ExternalRequiredInterfaceNode external = (ExternalRequiredInterfaceNode) to;
+ ProvidedInterface provider = external.getRequired()
+ .getProvider();
+ if (provider == null && !required.getRequired().isOptional()) {
+ throw new SystemAssemblyException("Mandatory interface '"
+ + from + "' is not provided.");
+ }
+ if ( provider != null ) {
+ required.getRequired().setProvider(provider);
+ }
+ }
+ } else if (from instanceof ProvidedInterfaceNode) {
+ // Provided interfaces can only be published after the system has
+ // started.
+ }
+ }
+
+ @Override
+ public void visitNode(Node aNode) {
+ // Empty.
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.graph.Node;
+
+public class ProvidedInterfaceNode implements Node {
+
+ private Component _component;
+ private ProvidedInterface _provided;
+
+ public ProvidedInterfaceNode(Component aComponent, ProvidedInterface aProvided) {
+ _component = aComponent;
+ _provided = aProvided;
+ }
+
+ @Override
+ public String getName() {
+ return _component.getQualifiedName() + ":" + _provided.getName();
+ }
+
+ public ProvidedInterface getProvided() {
+ return _provided;
+ }
+
+ public Component getComponent() {
+ return _component;
+ }
+
+ @Override
+ public String toString() {
+ return _component.getQualifiedName() + ":" + _provided;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.graph.Node;
+
+public class RequiredInterfaceNode implements Node {
+
+ private Component _component;
+ private RequiredInterface _required;
+
+ public RequiredInterfaceNode(Component aComponent, RequiredInterface aRequired) {
+ _component = aComponent;
+ _required = aRequired;
+ }
+
+ @Override
+ public String getName() {
+ return _component.getQualifiedName() + ":" + _required.getName();
+ }
+
+ public RequiredInterface getRequired() {
+ return _required;
+ }
+
+ public Component getComponent() {
+ return _component;
+ }
+
+ @Override
+ public String toString() {
+ return _component.getQualifiedName() + ":" + _required;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.graph.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.wamblee.system.graph.DefaultEdge;
+import org.wamblee.system.graph.Edge;
+import org.wamblee.system.graph.EdgeFactory;
+import org.wamblee.system.graph.Node;
+
+/**
+ * Factory that creates links between required and provided interfaces.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class RequiredProvidedEdgeFactory implements EdgeFactory {
+
+ public RequiredProvidedEdgeFactory() {
+ // Empty.
+ }
+
+ @Override
+ public List<Edge> create(Node aFrom, Node aTo) {
+ List<Edge> result = new ArrayList<Edge>();
+ if (aFrom instanceof RequiredInterfaceNode) {
+ RequiredInterfaceNode required = (RequiredInterfaceNode) aFrom;
+ if (aTo instanceof ProvidedInterfaceNode) {
+
+ ProvidedInterfaceNode provided = (ProvidedInterfaceNode) aTo;
+ if (required.getRequired()
+ .implementedBy(provided.getProvided())) {
+ result.add(new DefaultEdge(required, provided));
+ }
+ } else if (aTo instanceof ExternalRequiredInterfaceNode) {
+ ExternalRequiredInterfaceNode external = (ExternalRequiredInterfaceNode) aTo;
+ if ( required.getRequired().equals(external.getRequired())) {
+ result.add(new DefaultEdge(required, external));
+ }
+ }
+ } else if ( aFrom instanceof ProvidedInterfaceNode) {
+ ProvidedInterfaceNode provided = (ProvidedInterfaceNode)aFrom;
+ if ( aTo instanceof ExternalProvidedInterfaceNode) {
+ ExternalProvidedInterfaceNode external = (ExternalProvidedInterfaceNode)aTo;
+ if ( provided.getProvided().equals(external.getProvided())) {
+ result.add(new DefaultEdge(external, provided));
+ }
+ }
+ }
+ return result;
+ }
+
+}
import java.util.Collections;
import java.util.List;
+import org.wamblee.system.container.Container;
import org.wamblee.system.core.Component;
-import org.wamblee.system.core.Container;
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import java.util.Collections;
import java.util.List;
+import org.wamblee.system.container.Container;
import org.wamblee.system.core.Component;
-import org.wamblee.system.core.Container;
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.io.ClassPathResource;
import org.wamblee.persistence.DerbyDatabase;
-import org.wamblee.system.core.Container;
+import org.wamblee.system.container.Container;
public class DatabaseComponentFactory {
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
-
-import javax.sql.DataSource;
+package org.wamblee.system.container;
import org.wamblee.system.core.AbstractComponent;
import org.wamblee.system.core.DefaultRequiredInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
import org.wamblee.test.EventTracker;
public class Application extends AbstractComponent {
}
@Override
- protected Object doStart(Scope aScope) {
+ public Object doStart(Scope aScope) {
track("start." + getName());
_string = aScope.getInterfaceImplementation(getRequiredInterfaces()[0].getProvider(), String.class);
_integer = aScope.getInterfaceImplementation(getRequiredInterfaces()[1].getProvider(), Integer.class);
}
@Override
- protected void doStop(Object aRuntime) {
+ public void doStop(Object aRuntime) {
track("stop." + getName());
if ( _random != (Double)aRuntime) {
throw new IllegalArgumentException("Wrong runtime: expected " + _random + " but got " +
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
+
+import static org.easymock.EasyMock.anyObject;
import java.util.Arrays;
+import junit.framework.TestCase;
+
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
-import org.wamblee.test.EasyMockMatchers;
-import static org.easymock.classextension.EasyMock.*;
-
-import junit.framework.TestCase;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.Environment;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
public class CompositeInterfaceRestrictionTest extends TestCase {
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
-import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.wamblee.general.Pair;
+import org.wamblee.system.core.Component;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.DefaultRequiredInterface;
+import org.wamblee.system.core.DefaultScope;
+import org.wamblee.system.core.Environment;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
+import org.wamblee.system.core.StringComponent;
+import org.wamblee.system.core.SystemAssemblyException;
import org.wamblee.test.AssertionUtils;
import org.wamblee.test.EasyMockMatchers;
import org.wamblee.test.EventTracker;
return result;
}
- public void testFilterProvided() {
- RequiredInterface req1 = new DefaultRequiredInterface("name",
- Runnable.class);
- RequiredInterface req2 = new DefaultRequiredInterface("name",
- Serializable.class);
- ProvidedInterface prov1 = new DefaultProvidedInterface("name",
- Runnable.class);
- ProvidedInterface prov2 = new DefaultProvidedInterface("name",
- Serializable.class);
- ProvidedInterface prov3 = new DefaultProvidedInterface("name",
- MyMultiple.class);
-
- Component client = new Application("client");
- Component dummy = new Application("dummy");
-
- InterfaceRestriction noRestriction = new InterfaceRestriction() {
- @Override
- public boolean isViolated(Component aClient,
- RequiredInterface aRequired, Component aServer,
- ProvidedInterface aProvided) {
- return false;
- }
- };
-
- AssertionUtils.assertEquals(new ProvidedInterface[] { prov1 },
- Container.filterProvidedServices(client, req1,
- createProvidedInput(new ProvidedInterface[] { prov1 },
- dummy), noRestriction));
- AssertionUtils.assertEquals(new ProvidedInterface[] { prov1 },
- Container.filterProvidedServices(client, req1,
- createProvidedInput(new ProvidedInterface[] { prov1,
- prov2 }, dummy), noRestriction));
- AssertionUtils.assertEquals(new ProvidedInterface[] { prov1, prov3 },
- Container.filterProvidedServices(client, req1,
- createProvidedInput(new ProvidedInterface[] { prov1,
- prov3 }, dummy), noRestriction));
-
- InterfaceRestriction everything = new InterfaceRestriction() {
- @Override
- public boolean isViolated(Component aClient,
- RequiredInterface aRequired, Component aServer,
- ProvidedInterface aProvided) {
- return true;
- }
- };
- AssertionUtils.assertEquals(new ProvidedInterface[0], Container
- .filterProvidedServices(client, req1, createProvidedInput(
- new ProvidedInterface[] { prov1, prov3 }, dummy),
- everything));
-
- }
-
public void testEnvironmentApplication() {
Environment environment = new Environment(_tracker);
Application application = new Application(_tracker);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.system.core;
+package org.wamblee.system.container;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.wamblee.test.AssertionUtils;
-
import junit.framework.TestCase;
+import org.wamblee.system.core.Environment;
+import org.wamblee.test.AssertionUtils;
+
public class DefaultInterfaceRestrictionTest extends TestCase {
private Application _app1 = new Application("app1", "pf1.");
private Application _app2 = new Application("app2", "pf2.");