You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/04/14 04:24:13 UTC
svn commit: r528742 - in /incubator/tuscany/java/sca/modules:
core-spi/src/main/java/org/apache/tuscany/spi/component/
core/src/main/java/org/apache/tuscany/core/component/
core/src/main/java/org/apache/tuscany/core/deployer/
implementation-java-runtim...
Author: jsdelfino
Date: Fri Apr 13 19:24:12 2007
New Revision: 528742
URL: http://svn.apache.org/viewvc?view=rev&rev=528742
Log:
Added handling of composite references that use the SCA default binding. For now translate these references to wires on the promoted references in the inner composites.
Modified:
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/context/PojoAtomicComponent.java
Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java?view=diff&rev=528742&r1=528741&r2=528742
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java Fri Apr 13 19:24:12 2007
@@ -20,10 +20,8 @@
import java.net.URI;
import java.util.List;
-import java.util.Map;
import org.apache.tuscany.assembly.ComponentService;
-import org.apache.tuscany.assembly.Contract;
import org.apache.tuscany.spi.event.RuntimeEventListener;
/**
@@ -84,7 +82,6 @@
Component getComponent(URI uri);
List<SCAObject> getSCAObjects();
- List<Object> getModelObjects();
void add(SCAObject object, Object model);
<T extends SCAObject> T getSCAObject(Class<T> objectType, Object model);
<T> T getModelObject(Class<T> modelType, SCAObject object);
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java?view=diff&rev=528742&r1=528741&r2=528742
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java Fri Apr 13 19:24:12 2007
@@ -109,10 +109,6 @@
return null;
}
- public List<Object> getModelObjects() {
- return modelObjects;
- }
-
public <T extends SCAObject> T getSCAObject(Class<T> objectType, Object model) {
for(int i=0; i<modelObjects.size(); i++) {
if(modelObjects.get(i) == model) {
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java?view=diff&rev=528742&r1=528741&r2=528742
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java Fri Apr 13 19:24:12 2007
@@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
@@ -112,19 +111,26 @@
public Collection<Component> deploy(Composite composite) throws BuilderException, ResolutionException {
@SuppressWarnings("unchecked")
+
+ // Create a deployment context
ScopeContainer<URI> scopeContainer = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
URI groupId = URI.create(composite.getName().getLocalPart());
URI componentId = URI.create("/");
DeploymentContext deploymentContext = new RootDeploymentContext(null, groupId, componentId, xmlFactory,
scopeContainer);
+ // Create a default component implemented by the given composite
org.apache.tuscany.assembly.Component componentDef = new DefaultAssemblyFactory().createComponent();
componentDef.setName(composite.getName().getLocalPart());
componentDef.setImplementation(composite);
+
+ // Adjust the composite graph and wire the references with SCA bindings
+ processSCABinding(composite);
- // build runtime artifacts
- build(componentDef, deploymentContext);
+ // Build runtime artifacts using the builders
+ builder.build(componentDef, deploymentContext);
+ // Register all components with the component manager
Collection<Component> components = deploymentContext.getComponents().values();
for (Component toRegister : components) {
try {
@@ -133,12 +139,12 @@
throw new BuilderInstantiationException("Error registering component", e);
}
}
-
+
+ // Connect components, services and references
List<SCAObject> scaObjects = componentManager.getSCAObjects();
- List<Object> modelObjects = componentManager.getModelObjects();
for (int i = 0; i < scaObjects.size(); i++) {
- Object model = modelObjects.get(i);
SCAObject scaObject = scaObjects.get(i);
+ Object model = componentManager.getModelObject(Object.class, scaObject);
if (model instanceof org.apache.tuscany.assembly.Component) {
connect((Component)scaObject, (org.apache.tuscany.assembly.Component)model);
} else if (model instanceof CompositeReference) {
@@ -158,18 +164,45 @@
return components;
}
-
- /**
- * Build the runtime context for a loaded componentDefinition.
- *
- * @param parent the context that will be the parent of the new sub-context
- * @param componentDefinition the componentDefinition being deployed
- * @param deploymentContext the current deployment context
- * @return the new runtime context
- */
- protected SCAObject build(org.apache.tuscany.assembly.Component componentDefinition,
- DeploymentContext deploymentContext) throws BuilderException {
- return builder.build(componentDefinition, deploymentContext);
+
+
+ private void processSCABinding(Composite composite) {
+
+ // Resolve all wires
+ for (org.apache.tuscany.assembly.Component component: composite.getComponents()) {
+
+ // Process composite components
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentReference componentReference: component.getReferences()) {
+
+ // Process component references with a default binding
+ if (componentReference.getBinding(SCABinding.class) != null) {
+
+ // Wire the promoted references inside the nested composite
+ CompositeReference compositeReference = (CompositeReference)componentReference.getReference();
+ if (compositeReference != null) {
+ for (ComponentReference promotedReference: compositeReference.getPromotedReferences()) {
+
+ // Add all the actual (promoted) targets to the promoted reference
+ for (ComponentService componentService: componentReference.getTargets()) {
+ org.apache.tuscany.assembly.Service service = componentService.getService();
+ if (service instanceof CompositeService) {
+ CompositeService compositeService = (CompositeService)service;
+ ComponentService promotedService = compositeService.getPromotedService();
+ if (promotedService != null) {
+ promotedReference.getTargets().add(promotedService);
+ }
+ } else {
+ promotedReference.getTargets().add(componentService);
+ }
+ }
+ promotedReference.promotedAs().clear();
+ }
+ }
+ }
+ }
+ }
+ }
}
public static org.apache.tuscany.assembly.Reference getReference(Implementation type, String name) {
@@ -181,6 +214,171 @@
return null;
}
+ public void connect(org.apache.tuscany.assembly.Component definition) throws WiringException {
+ Component source = componentManager.getSCAObject(Component.class, definition);
+ if (source == null) {
+ throw new ComponentNotFoundException("Source not found", URI.create(definition.getName()));
+ }
+
+ for (ComponentReference ref : definition.getReferences()) {
+ List<Wire> wires = new ArrayList<Wire>();
+ String refName = ref.getName();
+ org.apache.tuscany.assembly.Reference refDefinition = getReference(definition.getImplementation(), refName);
+ assert refDefinition != null;
+ List<ComponentService> services = ref.getTargets();
+ for (ComponentService service : services) {
+ org.apache.tuscany.assembly.Component targetCompoent =
+ service.getBinding(SCABinding.class).getComponent();
+ Component target = componentManager.getSCAObject(Component.class, targetCompoent);
+ URI targetUri = URI.create(target.getUri() + "#" + service.getName());
+ if (target == null && (refDefinition.getMultiplicity() == Multiplicity.ZERO_ONE || refDefinition
+ .getMultiplicity() == Multiplicity.ZERO_N)) {
+ // a non-required reference, just skip
+ continue;
+ }
+ if (target == null) {
+ throw new ComponentNotFoundException("Target not found", targetUri);
+ }
+ URI sourceURI = URI.create(source.getUri() + "#" + refName);
+ Wire wire;
+ try {
+ wire =
+ createWire(sourceURI, targetUri, refDefinition.getInterfaceContract(), service.getService()
+ .getInterfaceContract(), Wire.LOCAL_BINDING);
+ } catch (IncompatibleInterfaceContractException e1) {
+ throw new IncompatibleInterfacesException(sourceURI, targetUri, e1);
+ }
+
+ // If this component is implemented by a composite then
+ // we need to attach the wires to the component in the
+ // implementing composite that defines the references that
+ // have been promoted to here. The composite component is not
+ // itself wired as it plays no part in the runtime invocation
+ // chain
+ // We grab the nested component here, whose refefrences have
+ // been promoted
+ // and use it later on
+ Component nestedComponentSource = null;
+
+ if (definition.getImplementation() instanceof Composite) {
+ // Need to get the component from the composite. This is
+ // slightly tricky
+ // as we need to:
+ // Cast the reference to a composite reference
+ // Get the promoted references
+ List<ComponentReference> promotedReference =
+ ((CompositeReference)refDefinition).getPromotedReferences();
+ // For each promoted reference get the SCA binding
+ for (ComponentReference componentReference : promotedReference) {
+ SCABinding scaBinding = componentReference.getBinding(SCABinding.class);
+ // from the binding get the component
+ org.apache.tuscany.assembly.Component nestedComponent = scaBinding.getComponent();
+ // map the model component to the runtime component
+ nestedComponentSource = componentManager.getSCAObject(Component.class, nestedComponent);
+ }
+ }
+
+ // The same is true of the target for when callbacks are wired
+ // or when the
+ // target invoker is created. If the target is a composite
+ // component go get
+ // the component from the implementing composite whose service
+ // we are targetting
+ Component nestedComponentTarget = null;
+
+ if (targetCompoent.getImplementation() instanceof Composite) {
+ // Need to get the component from the composite. Here we go:
+ // Get the implementation from the target component (this
+ // should be a composite)
+ List<org.apache.tuscany.assembly.Service> nestedServices = targetCompoent.getImplementation().getServices();
+ // Get the service from the implementation that matches the
+ // service we are processing
+ for (org.apache.tuscany.assembly.Service nestedService : nestedServices) {
+ if (nestedService.getName().equals(service.getName())) {
+ // Get the real service that this is promoted from
+ ComponentService promotedService = ((CompositeService)nestedService).getPromotedService();
+ // Get the SCA binding from the promoted service
+ SCABinding scaBinding = promotedService.getBinding(SCABinding.class);
+ // Get the component from the binding
+ org.apache.tuscany.assembly.Component nestedComponent = scaBinding.getComponent();
+ // Map this model component to the runtime component
+ nestedComponentTarget = componentManager.getSCAObject(Component.class, nestedComponent);
+ }
+ }
+ }
+
+ // add the required invokers to the wire created prviously. of
+ // particluar imporantance is the target invoker that provides
+ // the
+ // bridge to the target service. We have to check
+ try {
+ if (nestedComponentTarget == null) {
+ attachInvokers(refName, wire, source, target);
+ } else {
+ attachInvokers(refName, wire, source, nestedComponentTarget);
+ }
+
+ } catch (TargetInvokerCreationException e) {
+ throw new WireCreationException("Error creating invoker", sourceURI, targetUri, e);
+ }
+
+ if (postProcessorRegistry != null) {
+ postProcessorRegistry.process(wire);
+ }
+
+ // TODO: Which components do we need to use for the optimize
+ optimize(source, target, wire);
+
+ // In the case of a composite component add the wire to the
+ // component inside
+ // the reference loop because there may be many references
+ // promoted to the composite component from different components
+ if (definition.getImplementation() instanceof Composite) {
+ nestedComponentSource.attachWire(wire);
+ } else {
+ // add the wire to the collcetion that will be added
+ // en-masse to the
+ // source component later on
+ wires.add(wire);
+ }
+
+ // if there is a callback associated with the invocation chain
+ // then this needs to be connected to the target. It has to be
+ // done
+ // inside the service/target loop because there may be multiple
+ // targets for the reference
+ if (!wire.getCallbackInvocationChains().isEmpty()) {
+ // as previously the target may be implemented by a
+ // composite
+ // so we need to find the target component within the
+ // composite
+ // to set the callback on if this is the case
+ if (targetCompoent.getImplementation() instanceof Composite) {
+ nestedComponentTarget.attachCallbackWire(wire);
+ } else {
+ target.attachCallbackWire(wire);
+ }
+ }
+ }
+
+ // If this component is implemented by a composite then
+ // the wires will already have been added to the appropriate
+ // components in the code above
+ if (definition.getImplementation() instanceof Composite) {
+ // not sure we need to do anything else here
+ } else {
+ if (wires.size() > 1) {
+ // attach as a multiplicity
+ source.attachWires(wires);
+ } else if (wires.size() == 1) {
+ // attach as a single wire
+ Wire wire = wires.get(0);
+ source.attachWire(wire);
+ }
+ }
+ }
+ }
+
public void connect(Component source, org.apache.tuscany.assembly.Component definition) throws WiringException {
if (definition.getImplementation() instanceof Composite) {
@@ -188,12 +386,10 @@
return;
}
- for (ComponentReference ref : definition.getReferences()) {
+ for (ComponentReference componentReference : definition.getReferences()) {
List<Wire> wires = new ArrayList<Wire>();
- String refName = ref.getName();
- org.apache.tuscany.assembly.Reference refDefinition = ref.getReference();
- assert refDefinition != null;
- List<CompositeReference> promoted = ref.promotedAs();
+ String refName = componentReference.getName();
+ List<CompositeReference> promoted = componentReference.promotedAs();
if (!promoted.isEmpty()) {
// TODO: Assume a component reference can only be promoted by at
// most one composite reference
@@ -202,15 +398,12 @@
// FIXME: Assume we only have one binding
ReferenceBinding binding = target.getReferenceBindings().get(0);
URI targetUri = binding.getTargetUri();
- InterfaceContract contract = binding.getBindingInterfaceContract();
- if (contract == null) {
- contract = refDefinition.getInterfaceContract();
- }
+ InterfaceContract contract = compositeReference.getInterfaceContract();
QName type = binding.getBindingType();
URI sourceUri = URI.create(source.getUri() + "#" + refName);
Wire wire;
try {
- wire = createWire(sourceUri, targetUri, refDefinition.getInterfaceContract(), contract, type);
+ wire = createWire(sourceUri, targetUri, componentReference.getInterfaceContract(), contract, type);
} catch (IncompatibleInterfaceContractException e1) {
throw new IllegalStateException(e1);
}
@@ -222,13 +415,13 @@
}
wires.add(wire);
} else {
- List<ComponentService> services = ref.getTargets();
+ List<ComponentService> services = componentReference.getTargets();
for (ComponentService service : services) {
org.apache.tuscany.assembly.Component targetCompoent = service.getBinding(SCABinding.class)
.getComponent();
Component target = componentManager.getSCAObject(Component.class, targetCompoent);
URI targetUri = URI.create(target.getUri() + "#" + service.getName());
- if (target == null && (refDefinition.getMultiplicity() == Multiplicity.ZERO_ONE || refDefinition
+ if (target == null && (componentReference.getMultiplicity() == Multiplicity.ZERO_ONE || componentReference
.getMultiplicity() == Multiplicity.ZERO_N)) {
// a non-required reference, just skip
continue;
@@ -239,7 +432,7 @@
URI sourceURI = URI.create(source.getUri() + "#" + refName);
Wire wire;
try {
- wire = createWire(sourceURI, targetUri, refDefinition.getInterfaceContract(), service
+ wire = createWire(sourceURI, targetUri, componentReference.getInterfaceContract(), service
.getService().getInterfaceContract(), Wire.LOCAL_BINDING);
} catch (IncompatibleInterfaceContractException e1) {
throw new IncompatibleInterfacesException(sourceURI, targetUri, e1);
@@ -343,16 +536,16 @@
}
}
- private SCAObject getSCAObject(Map<SCAObject, Object> models, Object model) {
- SCAObject source = null;
- for (Map.Entry<SCAObject, Object> e : models.entrySet()) {
- if (e.getValue() == model) {
- source = e.getKey();
- }
- }
- return source;
- }
-
+ /**
+ * Create a new wire connecting a source to a target.
+ * @param sourceURI
+ * @param targetUri
+ * @param sourceContract
+ * @param targetContract
+ * @param bindingType
+ * @return
+ * @throws IncompatibleInterfaceContractException
+ */
protected Wire createWire(URI sourceURI,
URI targetUri,
InterfaceContract sourceContract,
@@ -393,8 +586,6 @@
private void attachInvokers(String name, Wire wire, Invocable source, Invocable target)
throws TargetInvokerCreationException {
- // TODO section will deleted be replaced when we cut-over to the
- // physical marshallers
for (InvocationChain chain : wire.getInvocationChains()) {
chain.setTargetInvoker(target.createTargetInvoker(name, chain.getTargetOperation(), false));
}
Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/context/PojoAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/context/PojoAtomicComponent.java?view=diff&rev=528742&r1=528741&r2=528742
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/context/PojoAtomicComponent.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/implementation/java/context/PojoAtomicComponent.java Fri Apr 13 19:24:12 2007
@@ -177,8 +177,9 @@
public void attachCallbackWire(Wire wire) {
assert wire.getSourceUri().getFragment() != null;
// FIXME: [rfeng] This is a hack to get it compiled
+ //FIXME callbackName must contain the name of a callback property
String callbackName = wire.getSourceContract().getCallbackInterface().toString();
- assert configuration.getDefinition().getCallbackMembers().get(callbackName) != null;
+ //assert configuration.getDefinition().getCallbackMembers().get(callbackName) != null;
List<Wire> wireList = callBackwires.get(callbackName);
if (wireList == null) {
wireList = new ArrayList<Wire>();
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org