summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/assembly
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-09-18 10:49:33 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-09-18 10:49:33 +0000
commitdb06a8d9de25db76909ba5806e4e93eaee4556ed (patch)
treed65552cc69409b33c9d9836bc67d9c25a7710649 /java/sca/modules/assembly
parent12d905c8cd8cf3d1e64595ef9a0f42e8e988f61e (diff)
Some more incremental changes to the new builders. committing to create a backup at this stage. still doesn't work.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@816581 13f79535-47bb-0310-9956-ffa450edef68
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.java164
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java168
-rw-r--r--java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties2
3 files changed, 262 insertions, 72 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 1c411c1956..54475253a2 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
@@ -84,6 +84,7 @@ public class ComponentBuilderImpl {
}
/**
+ * Configure the component based on its component type using OASIS rules
*
* @param component
*/
@@ -107,7 +108,7 @@ public class ComponentBuilderImpl {
configureServices(component);
// references
- //configureReferences(component);
+ configureReferences(component);
// properties
//configureProperties(component);
@@ -115,6 +116,8 @@ public class ComponentBuilderImpl {
}
/**
+ * Use the component type builder to build the component type for
+ * this component.
*
* @param component
*/
@@ -126,7 +129,9 @@ public class ComponentBuilderImpl {
}
/**
- *
+ * Configure this component's services based on the services in its
+ * component type and the configuration from the composite file
+ *
* @param component
*/
private void configureServices(Component component){
@@ -158,19 +163,65 @@ public class ComponentBuilderImpl {
componentService);
- // intents - done in CompositePolicyBuilder
- // discuss with RF
+ // intents - done later in CompositePolicyBuilder - discuss with RF
//calculateIntents(componentService,
// componentTypeService);
- // policy sets - done in CompositePolicyBuilder
- // discuss with RF
+ // policy sets - done later in CompositePolicyBuilder - discuss with RF
// calculatePolicySets(componentService,
// componentTypeService);
}
}
+ /**
+ * Configure this component's references based on the references in its
+ * component type and the configuration from the composite file
+ *
+ * @param component
+ */
+ private void configureReferences(Component component){
+
+ // If the component type has references that are not described in this
+ // component then create references for this component
+ addReferencesFromComponentType(component);
+
+ // Connect this component's references to the
+ // references from its component type
+ connectReferencesToComponentType(component);
+
+ // look at each component reference in turn and calculate its
+ // configuration based on OASIS rules
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference componentTypeReference = componentReference.getReference();
+
+ // interface contracts
+ calculateInterfaceContract(componentReference,
+ componentTypeReference);
+
+ // bindings
+ // We don've to do anything with reference bindings. You've either
+ // specified one or you haven't
+ //calculateBindings(componentService,
+ // componentTypeService);
+
+
+ // add callback service model objects
+ //createCallbackService(component,
+ // componentReference);
+
+
+ // intents - done later in CompositePolicyBuilder - discuss with RF
+ //calculateIntents(componentService,
+ // componentTypeService);
+
+ // policy sets - done later in CompositePolicyBuilder - discuss with RF
+ // calculatePolicySets(componentService,
+ // componentTypeService);
+
+ }
+ }
+
private void addServicesFromComponentType(Component component){
// Create a component service for each service
@@ -190,6 +241,27 @@ public class ComponentBuilderImpl {
}
}
}
+ }
+
+ private void addReferencesFromComponentType(Component component){
+
+ // Create a component reference for each reference
+ if (component.getImplementation() != null) {
+ for (Reference reference : component.getImplementation().getReferences()) {
+ ComponentReference componentReference =
+ (ComponentReference)component.getReference(reference.getName());
+
+ // if the component doesn't have a reference with the same name as the
+ // component type reference then create one
+ if (componentReference == null) {
+ componentReference = assemblyFactory.createComponentReference();
+ componentReference.setForCallback(reference.isForCallback());
+ componentReference.setName(reference.getName());
+ componentReference.setReference(reference);
+ component.getReferences().add(componentReference);
+ }
+ }
+ }
}
private void connectServicesToComponentType(Component component){
@@ -214,36 +286,66 @@ public class ComponentBuilderImpl {
}
}
}
+
+ private void connectReferencesToComponentType(Component component){
+
+ // Connect each component reference to the corresponding component type reference
+ for (ComponentReference componentReference : component.getReferences()) {
+ if (componentReference.getReference() != null || componentReference.isForCallback()) {
+ continue;
+ }
+
+ Reference reference = component.getImplementation().getReference(componentReference.getName());
+
+ if (reference != null) {
+ componentReference.setReference(reference);
+ } else {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ReferenceNotFoundForComponentReference",
+ component.getName(),
+ componentReference.getName());
+ }
+ }
+ }
/**
- * OASIS RULE: Interface contract from higher in the hierarchy takes precedence
+ * OASIS RULE: Interface contract from higher in the implementation 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();
+ * @param topContract the top contract
+ * @param bottomContract the bottom contract
+ */
+ private void calculateInterfaceContract(Contract topContract,
+ Contract bottomContract) {
+ // Use the interface contract from the bottom level contract if
+ // none is specified on the top level contract
+ InterfaceContract topInterfaceContract = topContract.getInterfaceContract();
+ InterfaceContract bottomInterfaceContract = bottomContract.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 (topInterfaceContract == null) {
+ topContract.setInterfaceContract(bottomInterfaceContract);
+ } else if (bottomInterfaceContract != null) {
+ // Check that the top and bottom interface contracts are compatible
+ boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract,
+ bottomInterfaceContract);
if (!isCompatible) {
- Monitor.error(monitor,
- this,
- "assembly-validation-messages",
- "ServiceInterfaceNotSubSet",
- componentService.getName());
+ if (topContract instanceof Reference) {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ReferenceInterfaceNotSubSet",
+ topContract.getName());
+ } else {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ServiceInterfaceNotSubSet",
+ topContract.getName());
+ }
}
- }
- }
+ }
+ }
/**
* OASIS RULE: Bindings from higher in the hierarchy take precedence
@@ -378,4 +480,4 @@ public class ComponentBuilderImpl {
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 e13445077a..68db5bdb72 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
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.assembly.builder.impl;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -31,9 +32,11 @@ 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;
@@ -52,6 +55,9 @@ import org.apache.tuscany.sca.policy.PolicySubject;
/**
* @version $Rev$ $Date$
*/
+
+// TODO - really implementation.composite component type builder
+
public class ComponentTypeBuilderImpl {
private static final Logger logger = Logger.getLogger(ComponentTypeBuilderImpl.class.getName());
@@ -114,19 +120,12 @@ public class ComponentTypeBuilderImpl {
component.getName());
}
- /* process structural hierarchy
- * replace by structuralParent links and associated processing
// Push down the autowire flag from the composite to components
+ // TODO - Is this the right place to do this structural inheritance
if (component.getAutowire() == null) {
component.setAutowire(composite.getAutowire());
}
-
- // what else needs pushing down?
- // intents
- // policySets
-
- */
-
+
// configure the component from its component type
componentBuilder.configureComponentFromComponentType(component);
}
@@ -145,7 +144,7 @@ public class ComponentTypeBuilderImpl {
calculateServices(composite, components, componentServices);
// references
- //calculateReferences(composite);
+ calculateReferences(composite, components, componentReferences);
// properties
//calculateProperties(composite);
@@ -229,7 +228,6 @@ public class ComponentTypeBuilderImpl {
// 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
@@ -238,15 +236,55 @@ public class ComponentTypeBuilderImpl {
// promote bindings
calculatePromotedBindings(compositeService, promotedComponentService);
- // promote intents
+ // promote intents - done later in CompositePolicyBuilder - discuss with RF
// calculatePromotedIntents(compositeService, promotedComponentService);
- // promote policy sets
+ // promote policy sets - done later in CompositePolicyBuilder - discuss with RF
// calculatePromotedPolicySets(compositeService, promotedComponentService);
+ }
+ }
+
+ /**
+ * Connect the references in the component type to the component references that
+ * they promote
+ *
+ * @param componentType
+ * @param component
+ */
+ private void calculateReferences(ComponentType componentType,
+ Map<String, Component> components,
+ Map<String, ComponentReference> componentReferences){
+
+ // Connect this component type's references to the
+ // references from child components which it promotes
+ connectPromotedReferences(componentType,
+ components,
+ componentReferences);
- }
+ // look at each component type reference in turn and
+ // calculate its configuration based on OASIS rules
+ for (Reference reference : componentType.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+ List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences();
+
+ for(ComponentReference promotedComponentReference : promotedReferences){
+
+ // promote interface contracts
+ calculatePromotedInterfaceContract(compositeReference, promotedComponentReference);
- }
+ // promote bindings
+ // Don't need to promote reference bindings as any lower level binding will
+ // already be targeting the correct service without need for promotion
+ //calculatePromotedBindings(compositeReference, promotedComponentReference);
+
+ // promote intents - done later in CompositePolicyBuilder - discuss with RF
+ // calculatePromotedIntents(compositeService, promotedComponentService);
+
+ // promote policy sets - done later in CompositePolicyBuilder - discuss with RF
+ // calculatePromotedPolicySets(compositeService, promotedComponentService);
+ }
+ }
+ }
/**
* Connect the services in the component type to the component services that
@@ -300,39 +338,89 @@ public class ComponentTypeBuilderImpl {
}
}
}
- }
+ }
/**
- * OASIS RULE: Interface contracts from higher in the implementation hierarchy takes precedence
+ * Connect the references in the component type to the component references that
+ * they promote
*
- * @param compositeService
- * @param promotedComponentService
+ * @param componentType
+ * @param component
*/
- 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());
+ private void connectPromotedReferences(ComponentType componentType,
+ Map<String, Component> components,
+ Map<String, ComponentReference> componentReferences){
+
+ // Connect composite (component type) references to the component references that they promote
+ for (Reference reference : componentType.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+ List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences();
+ for (int i = 0, n = promotedReferences.size(); i < n; i++) {
+ ComponentReference componentReference = promotedReferences.get(i);
+ if (componentReference.isUnresolved()) {
+ String componentReferenceName = componentReference.getName();
+ componentReference = componentReferences.get(componentReferenceName);
+ if (componentReference != null) {
+ // Set the promoted component
+ Component promotedComponent = compositeReference.getPromotedComponents().get(i);
+ promotedComponent = components.get(promotedComponent.getName());
+ compositeReference.getPromotedComponents().set(i, promotedComponent);
+
+ componentReference.setPromoted(true);
+
+ // Point to the resolved component reference
+ promotedReferences.set(i, componentReference);
+ } else {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "PromotedReferenceNotFound",
+ ((Composite)componentType).getName().toString(),
+ componentReferenceName);
+ }
+ }
}
- }
+ }
}
/**
+ * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence
+ *
+ * @param topContract the top contract
+ * @param bottomContract the bottom contract
+ */
+ private void calculatePromotedInterfaceContract(Contract topContract,
+ Contract bottomContract) {
+ // Use the interface contract from the bottom level contract if
+ // none is specified on the top level contract
+ InterfaceContract topInterfaceContract = topContract.getInterfaceContract();
+ InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract();
+
+ if (topInterfaceContract == null) {
+ topContract.setInterfaceContract(bottomInterfaceContract);
+ } else if (bottomInterfaceContract != null) {
+ // Check that the top and bottom interface contracts are compatible
+ boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract,
+ bottomInterfaceContract);
+ if (!isCompatible) {
+ if (topContract instanceof Reference) {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ReferenceInterfaceNotSubSet",
+ topContract.getName());
+ } else {
+ Monitor.error(monitor,
+ this,
+ "assembly-validation-messages",
+ "ServiceInterfaceNotSubSet",
+ topContract.getName());
+ }
+ }
+ }
+ }
+
+ /**
* OASIS RULE: Bindings from higher in the implementation hierarchy take precedence
*
* @param compositeService
diff --git a/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties b/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties
index 61b61279de..3a70a70bf7 100644
--- a/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties
+++ b/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties
@@ -32,7 +32,7 @@ PropertyNotFound = Property not found for component property: Component = {0} Pr
PropertyMustSupplyIncompatible = Component property mustSupply attribute incompatible with property: Component = {0} Property = {1}
PropertyMustSupplyNull = [ASM_4008] No value configured on a mustSupply property: Component = {0} Property = {1}
PropertyOverrideManyAttribute = Component property many attribute incompatible with property: Component = {0} Property = {1}
-ReferenceNotFound = Reference not found for component reference: Component = {0} Reference = {1}
+ReferenceNotFoundForComponentReference = Reference not found for component reference: Component = {0} Reference = {1}
ReferenceIncompatibleMultiplicity = Component reference multiplicity incompatible with reference multiplicity: Component = {0} Reference = {1}
ReferenceIncompatibleInterface = Incompatible interfaces on component reference and target: Composite = {0} Reference = {1} Service = {2}
ReferencePromotionIncompatibleInterface = Promoted reference interface incompatible with promoting reference: Promoting interface = {0} Promoted = {1}