import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
private static final Log LOG = LogFactory.getLog(Container.class);
- private List<Component> _components;
- private CompositeEdgeFilter _edgeFilter;
- private boolean _sealed;
+ private List<Component> components;
+ private CompositeEdgeFilter edgeFilter;
+ private boolean sealed;
/**
* Constructs the container
public Container(String aName, Component[] aComponents,
List<ProvidedInterface> aProvided, List<RequiredInterface> aRequired) {
super(aName, aProvided, aRequired);
- _components = new ArrayList<Component>();
+ components = new ArrayList<Component>();
- _edgeFilter = new CompositeEdgeFilter();
- _sealed = false;
+ edgeFilter = new CompositeEdgeFilter();
+ sealed = false;
for (Component component : aComponents) {
addComponent(component);
}
throw new SystemAssemblyException("Duplicate component '"
+ aComponent.getName() + "'");
}
- _components.add(aComponent);
+ components.add(aComponent);
aComponent.addContext(getQualifiedName());
return this;
}
+ aProvidedInterface + "'");
}
}
- _edgeFilter.add(new ConnectRequiredProvidedEdgeFilter(aClientComponent, aRequiredInterface, aServerComponent, aProvidedInterface));
+ edgeFilter.add(new ConnectRequiredProvidedEdgeFilter(aClientComponent, aRequiredInterface, aServerComponent, aProvidedInterface));
}
/**
public void connectExternalRequired(String aComponent, String aRequiredInterface,
String aExternalRequiredInterface) {
checkSealed();
- // TODO validate
- _edgeFilter.add(new ConnectRequiredExternallyRequiredEdgeFilter(
+ Component client = findComponent(aComponent);
+ if ( client == null ) {
+ throw new SystemAssemblyException(getQualifiedName() + ": No component '" + aComponent + "' in the container");
+ }
+ if ( aRequiredInterface != null ) {
+ if ( findInterface(client.getRequiredInterfaces(), aRequiredInterface) == null ) {
+ throw new SystemAssemblyException(
+ getQualifiedName() + ": Component '" + aComponent + "' does not have a required interface named '"
+ + aRequiredInterface + "'");
+ }
+ }
+ if ( aExternalRequiredInterface != null) {
+ if ( findInterface(getRequiredInterfaces(), aExternalRequiredInterface) == null ) {
+ throw new SystemAssemblyException(
+ getQualifiedName() + ": container does not have a required interface named '"
+ + aExternalRequiredInterface + "'");
+ }
+ }
+ edgeFilter.add(new ConnectRequiredExternallyRequiredEdgeFilter(
aComponent, aRequiredInterface, aExternalRequiredInterface));
}
public void connectExternalProvided(String aExternalProvided, String aComponent, String aProvidedInterface) {
checkSealed();
- // TODO validate
- _edgeFilter.add(new ConnectExternalProvidedProvidedFilter(aExternalProvided, aComponent, aProvidedInterface));
+ Component server = findComponent(aComponent);
+
+
+ if ( server == null ) {
+ throw new SystemAssemblyException("No component '" + aComponent + "' in the container");
+ }
+ if ( aProvidedInterface != null ) {
+ if ( findInterface(server.getProvidedInterfaces(), aProvidedInterface) == null) {
+ throw new SystemAssemblyException(
+ getQualifiedName() + ": Component '" + aComponent + "' does not have a provided interface named '"
+ + aProvidedInterface + "'");
+ }
+ }
+ if ( aExternalProvided != null ) {
+ if ( findInterface(getProvidedInterfaces(), aExternalProvided) == null) {
+ throw new SystemAssemblyException(
+ getQualifiedName() + ": Container does not have a provided interface named '"
+ + aExternalProvided + "'");
+ }
+ }
+ edgeFilter.add(new ConnectExternalProvidedProvidedFilter(aExternalProvided, aComponent, aProvidedInterface));
}
@Override
public void addContext(String aContext) {
super.addContext(aContext);
- for (Component component : _components) {
+ for (Component component : components) {
component.addContext(aContext);
}
}
* be added.
*/
public void seal() {
- _sealed = true;
+ sealed = true;
}
/**
* @return True iff the container is sealed.
*/
public boolean isSealed() {
- return _sealed;
+ return sealed;
}
/**
@Override
protected Scope doStart(Scope aExternalScope) {
- checkSealed();
validate();
Scope scope = new DefaultScope(getProvidedInterfaces().toArray(new ProvidedInterface[0]), aExternalScope);
ComponentGraph graph = doStartOptionalDryRun(scope, false);
private ComponentGraph doStartOptionalDryRun(Scope aScope, boolean aDryRun) {
ComponentGraph graph = createComponentGraph();
graph.validate();
- if (!aDryRun) {
- graph.link();
- }
+ graph.link();
LOG.info("Starting '" + getQualifiedName() + "'");
List<Component> started = new ArrayList<Component>();
- for (Component component : _components) {
+ for (Component component : components) {
try {
// Start the service.
if (!aDryRun) {
for (RequiredInterface req : getRequiredInterfaces()) {
graph.addRequiredInterface(this, req);
}
- for (Component comp : _components) {
+ for (Component comp : components) {
graph.addComponent(comp);
}
for (ProvidedInterface prov: getProvidedInterfaces()) {
graph.addProvidedInterface(this, prov);
}
- graph.addEdgeFilter(_edgeFilter);
+ graph.addEdgeFilter(edgeFilter);
return graph;
}
@Override
protected void doStop(Scope aScope) {
- for (int i = _components.size() - 1; i >= 0; i--) {
- Component component = _components.get(i);
+ 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) {
+ if (sealed) {
throw new SystemAssemblyException("Container is sealed");
}
}
* @return Component or null if not found.
*/
public Component findComponent(String aName) {
- for (Component<?> component: _components) {
+ for (Component<?> component: components) {
if ( component.getName().equals(aName)) {
return component;
}