summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/assembly
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/assembly')
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java310
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java340
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java4
3 files changed, 597 insertions, 57 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java
index 2be900d3b5..2e6f3075ba 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.assembly.builder.impl;
import java.net.URI;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -29,20 +30,33 @@ import javax.xml.transform.TransformerFactory;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderTmp;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.ExtensionType;
import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySubject;
/**
*
@@ -50,69 +64,317 @@ import org.apache.tuscany.sca.policy.PolicyFactory;
*/
public class ComponentBuilderImpl {
private static final Logger logger = Logger.getLogger(ComponentBuilderImpl.class.getName());
+
+ protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
+ protected static final String BINDING_SCA = "binding.sca";
+ protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA);
private ComponentTypeBuilderImpl componentTypeBuilder;
private Monitor monitor;
-
- public ComponentBuilderImpl(Monitor monitor) {
- this.monitor = monitor;
- }
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private InterfaceContractMapper interfaceContractMapper;
+
+ public ComponentBuilderImpl(ExtensionPointRegistry registry) {
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+
+ interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+ }
public void setComponentTypeBuilder(ComponentTypeBuilderImpl componentTypeBuilder){
this.componentTypeBuilder = componentTypeBuilder;
}
+ /**
+ *
+ * @param component
+ */
public void configureComponentFromComponentType(Component component){
- ComponentType componentType = createComponentType(component);
+
+ // do any required pre-processing on the implementation
+ // what does this do?
+ if (component.getImplementation() instanceof ComponentPreProcessor) {
+ ((ComponentPreProcessor)component.getImplementation()).preProcess(component);
+ }
+
+ // create the component type for this component
+ // taking any nested composites into account
+ createComponentType(component);
// services
- configureServices(component, componentType);
+ configureServices(component);
// references
- //configureReferences(component, componentType);
+ //configureReferences(component);
// properties
- //configureProperties(component, componentType);
+ //configureProperties(component);
}
- private ComponentType createComponentType(Component component){
+ /**
+ *
+ * @param component
+ */
+ private void createComponentType(Component component){
Implementation implementation = component.getImplementation();
- ComponentType componentType = (ComponentType)implementation;
if (implementation instanceof Composite) {
- componentType = componentTypeBuilder.createComponentType((Composite)implementation);
+ componentTypeBuilder.createComponentType((Composite)implementation);
}
- return componentType;
}
- private void configureServices(Component component, ComponentType componentType){
+ /**
+ *
+ * @param component
+ */
+ private void configureServices(Component component){
+
+ // If the component type has services that are not described in this
+ // component then create services for this component
+ addServicesFromComponentType(component);
+
+ // Connect this component's services to the
+ // services from its component type
+ connectServicesToComponentType(component);
+
+ // look at each component service in turn and calculate its
+ // configuration based on OASIS rules
+ for (ComponentService componentService : component.getServices()) {
+ Service componentTypeService = componentService.getService();
+
+ // interface contracts
+ calculateInterfaceContract(componentService,
+ componentTypeService);
+
+ // bindings
+ calculateBindings(componentService,
+ componentTypeService);
+
+
+ // add callback reference model objects
+ createCallbackReference(component,
+ componentService);
+
+
+
+ // need to propagate
+ // intents
+ // policy sets
+ // based on OASIS rules
+ }
+ }
+
+ private void addServicesFromComponentType(Component component){
+
+ // Create a component service for each service
+ if (component.getImplementation() != null) {
+ for (Service service : component.getImplementation().getServices()) {
+ ComponentService componentService =
+ (ComponentService)component.getService(service.getName());
+
+ // if the component doesn't have a service with the same name as the
+ // component type service then create one
+ if (componentService == null) {
+ componentService = assemblyFactory.createComponentService();
+ componentService.setForCallback(service.isForCallback());
+ String name = service.getName();
+ componentService.setName(name);
+ component.getServices().add(componentService);
+ }
+ }
+ }
+ }
+
+ private void connectServicesToComponentType(Component component){
+
+ // Connect each component service to the corresponding component type service
for (ComponentService componentService : component.getServices()) {
if (componentService.getService() != null || componentService.isForCallback()) {
continue;
}
- Service service = componentType.getService(componentService.getName());
-
+ Service service = component.getImplementation().getService(componentService.getName());
+
if (service != null) {
componentService.setService(service);
} else {
Monitor.error(monitor,
this,
"assembly-validation-messages",
- "ServiceNotFoundForComponentService",
+ "ServiceNotFoundForComponentService",
component.getName(),
componentService.getName());
}
-
- // need to propagate
- // bindings
- // interface contracts
- // intents
- // policy sets
- // based on OASIS rules
}
}
+
+ /**
+ * OASIS RULE: Interface contract from higher in the hierarchy takes precedence
+ *
+ * @param componentService the top service
+ * @param componentTypeService the bottom service
+ */
+ private void calculateInterfaceContract(Service componentService,
+ Service componentTypeService){
+ // Use the interface contract from the higher level service (1) if
+ // none is specified on the lower level service (2)
+ InterfaceContract componentServiceInterfaceContract = componentService.getInterfaceContract();
+ InterfaceContract componentTypeServiceInterfaceContract = componentTypeService.getInterfaceContract();
+
+ if (componentServiceInterfaceContract == null) {
+ componentService.setInterfaceContract(componentTypeServiceInterfaceContract);
+ } else if (componentTypeServiceInterfaceContract != null) {
+ // Check that the two interface contracts are compatible
+ boolean isCompatible =
+ interfaceContractMapper.isCompatible(componentServiceInterfaceContract,
+ componentTypeServiceInterfaceContract);
+ if (!isCompatible) {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ServiceInterfaceNotSubSet",
+ componentService.getName());
+ }
+ }
+ }
+
+ /**
+ * OASIS RULE: Bindings from higher in the hierarchy take precedence
+ *
+ * @param componentService the top service
+ * @param componentTypeService the bottom service
+ */
+ private void calculateBindings(Service componentService,
+ Service componentTypeService){
+ // forward bindings
+ if (componentService.getBindings().isEmpty()) {
+ componentService.getBindings().addAll(componentTypeService.getBindings());
+ }
+
+ if (componentService.getBindings().isEmpty()) {
+ createSCABinding(componentService, null);
+ }
+
+ // callback bindings
+ if (componentService.getCallback() == null) {
+ componentService.setCallback(componentTypeService.getCallback());
+ if (componentService.getCallback() == null) {
+ // Create an empty callback to avoid null check
+ componentService.setCallback(assemblyFactory.createCallback());
+ }
+ } else if (componentService.getCallback().getBindings().isEmpty() && componentTypeService.getCallback() != null) {
+ componentService.getCallback().getBindings().addAll(componentTypeService.getCallback().getBindings());
+ }
+
+ }
- // etc.
+ /**
+ * Create a callback reference for a component service
+ *
+ * @param component
+ * @param service
+ */
+ private void createCallbackReference(Component component, ComponentService service) {
+
+ // if the service has a callback interface create a reference
+ // to represent the callback
+ if (service.getInterfaceContract() != null && // can be null in unit tests
+ service.getInterfaceContract().getCallbackInterface() != null) {
+
+ ComponentReference callbackReference = assemblyFactory.createComponentReference();
+ callbackReference.setForCallback(true);
+ callbackReference.setName(service.getName());
+ try {
+ InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone();
+ contract.setInterface(contract.getCallbackInterface());
+ contract.setCallbackInterface(null);
+ callbackReference.setInterfaceContract(contract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ Service implService = service.getService();
+ if (implService != null) {
+
+ // If the implementation service is a CompositeService, ensure that the Reference that is
+ // created is a CompositeReference, otherwise create a Reference
+ Reference implReference;
+ if (implService instanceof CompositeService) {
+ CompositeReference implCompReference = assemblyFactory.createCompositeReference();
+ // Set the promoted component from the promoted component of the composite service
+ implCompReference.getPromotedComponents().add(((CompositeService)implService).getPromotedComponent());
+ // Set the promoted service
+ ComponentReference promotedReference = assemblyFactory.createComponentReference();
+ String promotedRefName =
+ ((CompositeService)implService).getPromotedComponent().getName() + "/"
+ + ((CompositeService)implService).getPromotedService().getName();
+ promotedReference.setName(promotedRefName);
+ promotedReference.setUnresolved(true);
+ implCompReference.getPromotedReferences().add(promotedReference);
+ implReference = implCompReference;
+ // Add the composite reference to the composite implementation artifact
+ Implementation implementation = component.getImplementation();
+ if (implementation != null && implementation instanceof Composite) {
+ ((Composite)implementation).getReferences().add(implCompReference);
+ } // end if
+ } else {
+ implReference = assemblyFactory.createReference();
+ } // end if
+ //
+
+ implReference.setName(implService.getName());
+ try {
+ InterfaceContract implContract = (InterfaceContract)implService.getInterfaceContract().clone();
+ implContract.setInterface(implContract.getCallbackInterface());
+ implContract.setCallbackInterface(null);
+ implReference.setInterfaceContract(implContract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ callbackReference.setReference(implReference);
+ }
+ component.getReferences().add(callbackReference);
+
+ // Set the bindings of the callback reference
+ if (callbackReference.getBindings().isEmpty()) {
+ // If there are specific callback bindings set, use them
+ if (service.getCallback() != null) {
+ callbackReference.getBindings().addAll(service.getCallback().getBindings());
+ } else {
+ // otherwise use the bindings on the forward service
+ callbackReference.getBindings().addAll(service.getBindings());
+ } // end if
+ } // end if
+ service.setCallbackReference(callbackReference);
+ }
+ }
+
+ /**
+ * Create a default SCA binding in the case that no binding
+ * is specified by the user
+ *
+ * @param contract
+ * @param definitions
+ */
+ protected void createSCABinding(Contract contract, Definitions definitions) {
+
+ SCABinding scaBinding = scaBindingFactory.createSCABinding();
+
+ if (definitions != null) {
+ for (ExtensionType attachPointType : definitions.getBindingTypes()) {
+ if (attachPointType.getType().equals(BINDING_SCA_QNAME)) {
+ ((PolicySubject)scaBinding).setExtensionType(attachPointType);
+ }
+ }
+ }
+
+ contract.getBindings().add(scaBinding);
+ contract.setOverridingBindings(false);
+ }
} //end class
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java
index 1f6a1bf792..cd63b5a288 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java
@@ -18,15 +18,36 @@
*/
package org.apache.tuscany.sca.assembly.builder.impl;
+import java.util.HashMap;
+import java.util.Map;
import java.util.logging.Logger;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Contract;
import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.ExtensionType;
+import org.apache.tuscany.sca.policy.PolicySubject;
/**
* @version $Rev$ $Date$
@@ -34,29 +55,51 @@ import org.apache.tuscany.sca.monitor.Monitor;
public class ComponentTypeBuilderImpl {
private static final Logger logger = Logger.getLogger(ComponentTypeBuilderImpl.class.getName());
+ protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
+ protected static final String BINDING_SCA = "binding.sca";
+ protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA);
+
private ComponentBuilderImpl componentBuilder;
private Monitor monitor;
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private InterfaceContractMapper interfaceContractMapper;
+
+
+ public ComponentTypeBuilderImpl(ExtensionPointRegistry registry) {
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
- public ComponentTypeBuilderImpl(Monitor monitor) {
- this.monitor = monitor;
+ interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
}
public void setComponentBuilder(ComponentBuilderImpl componentBuilder){
this.componentBuilder = componentBuilder;
}
- public ComponentType createComponentType(Implementation implementation){
+ /**
+ * Calculate the component type for the provided implementation
+ *
+ * @param implementation
+ * @return component type
+ */
+ public void createComponentType(Implementation implementation){
if (!(implementation instanceof Composite)){
// component type will have been calculated at resolve time
- return implementation;
+ return;
}
// create the composite component type as this was not
// calculated at resolve time
Composite composite = (Composite)implementation;
- // make sure that the component has been properly configured based
- // on its component type
+ // first make sure that each child component has been properly configured based
+ // on its own component type
for (Component component : composite.getComponents()) {
// Check for duplicate component names
@@ -69,43 +112,278 @@ public class ComponentTypeBuilderImpl {
component.getName());
}
- // Propagate the autowire flag from the composite to components
- // Should this be later?
+ // Push down the autowire flag from the composite to components
if (component.getAutowire() == null) {
component.setAutowire(composite.getAutowire());
}
- // do any require pre-processing on the implementation
- // what does this do?
- if (component.getImplementation() instanceof ComponentPreProcessor) {
- ((ComponentPreProcessor)component.getImplementation()).preProcess(component);
- }
-
- // services
- calculateServices(composite, component);
-
- // references
- //calculateReferences(composite, component);
+ // what else needs pushing down?
+ // intents
+ // policySets
- // properties
- //calculateProperties(composite, component);
+ // configure the component from its component type
+ componentBuilder.configureComponentFromComponentType(component);
}
-
+
// create the composite component type based on the promoted artifacts
// from the components that it contains
- return composite;
+ // index all the components, services and references in the
+ // component type so that they are easy to find
+ Map<String, Component> components = new HashMap<String, Component>();
+ Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>();
+ Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>();
+ indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences);
+
+ // services
+ calculateServices(composite, components, componentServices);
+
+ // references
+ //calculateReferences(composite);
+
+ // properties
+ //calculateProperties(composite);
+
+ }
+
+ /**
+ * Index components, services and references inside a composite.
+ *
+ * @param composite
+ * @param components
+ * @param componentServices
+ * @param componentReferences
+ */
+ private void indexComponentsServicesAndReferences(Composite composite,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices,
+ Map<String, ComponentReference> componentReferences) {
+
+ for (Component component : composite.getComponents()) {
+
+ // Index components by name
+ components.put(component.getName(), component);
+
+ ComponentService nonCallbackService = null;
+ int nonCallbackServices = 0;
+ for (ComponentService componentService : component.getServices()) {
+
+ // Index component services by component name / service name
+ String uri = component.getName() + '/' + componentService.getName();
+ componentServices.put(uri, componentService);
+
+ // count how many non-callback services there are
+ // if there is only one the component name also acts as the service name
+ if (!componentService.isForCallback()) {
+
+ // Check how many non callback non-promoted services we have
+ if (nonCallbackServices == 0) {
+ nonCallbackService = componentService;
+ }
+ nonCallbackServices++;
+ }
+ }
+
+ if (nonCallbackServices == 1) {
+ // If we have a single non callback service, index it by
+ // component name as well
+ componentServices.put(component.getName(), nonCallbackService);
+ }
+
+ // Index references by component name / reference name
+ for (ComponentReference componentReference : component.getReferences()) {
+ String uri = component.getName() + '/' + componentReference.getName();
+ componentReferences.put(uri, componentReference);
+ }
+ }
+ }
+
+
+ /**
+ * Connect the services in the component type to the component services that
+ * they promote
+ *
+ * @param componentType
+ * @param component
+ */
+ private void calculateServices(ComponentType componentType,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices){
+
+ // Connect this component types services to the
+ // services from child components which it promotes
+ connectPromotedServices(componentType,
+ components,
+ componentServices);
+
+ // look at each component type service in turn and
+ // calculate its configuration based on OASIS rules
+ for (Service service : componentType.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ Component promotedComponent = compositeService.getPromotedComponent();
+ ComponentService promotedComponentService = compositeService.getPromotedService();
+
+ // promote interface contracts
+ calculatePromotedInterfaceContract(compositeService, promotedComponentService);
+
+ // promote bindings
+ calculatePromotedBindings(compositeService, promotedComponentService);
+
+ // promote intents
+
+ // promote policy sets
+
+ }
+
}
- private void calculateServices(ComponentType componentType, Component component){
- for (ComponentService componentService : component.getServices()) {
- // need to propagate
- // bindings
- // interface contracts
- // intents
- // policy sets
- // based on OASIS rules
+ /**
+ * Connect the services in the component type to the component services that
+ * they promote
+ *
+ * @param componentType
+ * @param component
+ */
+ private void connectPromotedServices(ComponentType componentType,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices){
+
+ for (Service service : componentType.getServices()) {
+ // Connect composite (component type) services to the component services
+ // that they promote
+ CompositeService compositeService = (CompositeService)service;
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null && componentService.isUnresolved()) {
+ // get the name of the promoted component/service
+ String promotedComponentName = compositeService.getPromotedComponent().getName();
+ String promotedServiceName;
+ if (componentService.getName() != null) {
+ if (compositeService.isForCallback()) {
+ // For callbacks the name already has the form "componentName/servicename"
+ promotedServiceName = componentService.getName();
+ } else {
+ promotedServiceName = promotedComponentName + '/' + componentService.getName();
+ }
+ } else {
+ promotedServiceName = promotedComponentName;
+ }
+
+ // find the promoted service
+ ComponentService promotedService = componentServices.get(promotedServiceName);
+
+ if (promotedService != null) {
+
+ // Point to the resolved component
+ Component promotedComponent = components.get(promotedComponentName);
+ compositeService.setPromotedComponent(promotedComponent);
+
+ // Point to the resolved component service
+ compositeService.setPromotedService(promotedService);
+ } else {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "PromotedServiceNotFound",
+ ((Composite)componentType).getName().toString(),
+ promotedServiceName);
+ }
+ }
+ }
+ }
+
+ /**
+ * OASIS RULE: Interface contract from higher in the hierarchy takes precedence
+ *
+ * @param compositeService
+ * @param promotedComponentService
+ */
+ private void calculatePromotedInterfaceContract(CompositeService compositeService,
+ ComponentService promotedComponentService){
+ // Use the interface contract from the promoted component service if
+ // none is specified on the composite service
+ InterfaceContract compositeServiceInterfaceContract = compositeService.getInterfaceContract();
+ InterfaceContract promotedServiceInterfaceContract = promotedComponentService.getInterfaceContract();
+ if (compositeServiceInterfaceContract == null) {
+ compositeService.setInterfaceContract(promotedServiceInterfaceContract);
+ } else if (promotedServiceInterfaceContract != null) {
+ // Check that the compositeServiceInterfaceContract and promotedServiceInterfaceContract
+ // are compatible
+ boolean isCompatible =
+ interfaceContractMapper.isCompatible(compositeServiceInterfaceContract,
+ promotedServiceInterfaceContract);
+ if (!isCompatible) {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ServiceInterfaceNotSubSet",
+ promotedComponentService.getName());
+ }
+ }
+ }
+
+ /**
+ * OASIS RULE: Bindings from higher in the hierarchy take precedence
+ *
+ * @param compositeService
+ * @param promotedComponentService
+ */
+ private void calculatePromotedBindings(CompositeService compositeService,
+ ComponentService promotedComponentService){
+ // forward bindings
+ if (compositeService.getBindings().isEmpty()) {
+ for (Binding binding : promotedComponentService.getBindings()) {
+ try {
+ compositeService.getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
+
+ if (compositeService.getBindings().isEmpty()) {
+ createSCABinding(compositeService, null);
}
+
+ // callback bindings
+ if (promotedComponentService.getCallback() != null){
+ if (compositeService.getCallback() != null) {
+ compositeService.getCallback().getBindings().clear();
+ } else {
+ compositeService.setCallback(assemblyFactory.createCallback());
+ }
+
+ for (Binding binding : promotedComponentService.getCallback().getBindings()) {
+ try {
+ compositeService.getCallback().getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
}
+
+ /**
+ * Create a default SCA binding in the case that no binding
+ * is specified by the user
+ *
+ * @param contract
+ * @param definitions
+ */
+ protected void createSCABinding(Contract contract, Definitions definitions) {
+
+ SCABinding scaBinding = scaBindingFactory.createSCABinding();
+
+ if (definitions != null) {
+ for (ExtensionType attachPointType : definitions.getBindingTypes()) {
+ if (attachPointType.getType().equals(BINDING_SCA_QNAME)) {
+ ((PolicySubject)scaBinding).setExtensionType(attachPointType);
+ }
+ }
+ }
+
+ contract.getBindings().add(scaBinding);
+ contract.setOverridingBindings(false);
+ }
+
} //end class
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java
index 70b74d6642..819b953ab6 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java
@@ -83,8 +83,8 @@ public class ModelBuilderImpl implements CompositeBuilder, CompositeBuilderTmp {
compositeIncludeBuilder = new CompositeIncludeBuilderImpl(assemblyFactory);
compositeCloneBuilder = new CompositeCloneBuilderImpl();
- componentTypeBuilder = new ComponentTypeBuilderImpl(monitor);
- componentBuilder = new ComponentBuilderImpl(monitor);
+ componentTypeBuilder = new ComponentTypeBuilderImpl(registry);
+ componentBuilder = new ComponentBuilderImpl(registry);
componentTypeBuilder.setComponentBuilder(componentBuilder);
componentBuilder.setComponentTypeBuilder(componentTypeBuilder);