summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-03-05 12:59:57 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-03-05 12:59:57 +0000
commit72ba5ab2910c858e178691fc3b14796bf25209ea (patch)
tree58aa9b493759e2ac534d530ec18db5933b2e9f4a
parentcc1316754fddeeaa691825a79b9db3c5f227cdcc (diff)
TUSCANY-3486 - add the composite reference multiplicy resolution algorithm as per the spec
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@919398 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties1
-rw-r--r--sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java67
2 files changed, 68 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties b/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
index baaa60f992..bf96eb16df 100644
--- a/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
+++ b/sca-java-2.x/trunk/modules/assembly/src/main/resources/org/apache/tuscany/sca/assembly/builder/assembly-validation-messages.properties
@@ -32,6 +32,7 @@ PropertyMustSupplyIncompatible = Component property mustSupply attribute incompa
PropertyMustSupplyNull = [ASM40011,ASM60034] No value configured on a mustSupply property: Component = {0} Property = {1}
PropertyOverrideManyAttribute = Component property many attribute incompatible with property: Component = {0} Property = {1}
ReferenceNotFoundForComponentReference = [ASM50008] Component type reference not found for component reference: Component = {0} Reference = {1}
+CompositeReferenceIncompatibleMultiplicity = [ASM60011] Composite reference multiplicity incompatible with component reference multiplicity: Composite = {0} Composite reference = {1} Component reference = {2}
ReferenceIncompatibleMultiplicity = [ASM50009] 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}
diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java
index 2ea8c5ac5e..ddcfc883d6 100644
--- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java
+++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java
@@ -35,6 +35,7 @@ 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.Multiplicity;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
@@ -263,6 +264,9 @@ public class CompositeComponentTypeBuilderImpl {
List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences();
for (ComponentReference promotedComponentReference : promotedReferences) {
+
+ // promote multiplicity
+ reconcileReferenceMultiplicity(componentType, compositeReference, promotedComponentReference, monitor);
// promote interface contracts
calculatePromotedReferenceInterfaceContract(compositeReference, promotedComponentReference, monitor);
@@ -520,5 +524,68 @@ public class CompositeComponentTypeBuilderImpl {
}
}
}
+
+ private void reconcileReferenceMultiplicity(ComponentType componentType,
+ Reference compositeReference,
+ Reference promotedComponentReference,
+ Monitor monitor) {
+ if (compositeReference.getMultiplicity() != null) {
+ if (!isValidMultiplicityOverride(promotedComponentReference.getTargets().size() > 0,
+ promotedComponentReference.getMultiplicity(),
+ compositeReference.getMultiplicity())) {
+ Monitor.error(monitor,
+ this,
+ Messages.ASSEMBLY_VALIDATION,
+ "CompositeReferenceIncompatibleMultiplicity",
+ componentType.getURI(),
+ compositeReference.getName(),
+ promotedComponentReference.getName());
+ }
+ } else {
+ compositeReference.setMultiplicity(promotedComponentReference.getMultiplicity());
+ }
+ }
+
+ private boolean isValidMultiplicityOverride(boolean componentRefHasTarget,
+ Multiplicity componentRefMul,
+ Multiplicity compositeRefMul) {
+ if ((componentRefMul != null) &&
+ (compositeRefMul != null) &&
+ componentRefMul != compositeRefMul) {
+ if (componentRefHasTarget){
+ switch (componentRefMul) {
+ case ZERO_ONE:
+ return compositeRefMul == Multiplicity.ZERO_ONE ||
+ compositeRefMul == Multiplicity.ONE_ONE;
+ case ONE_ONE:
+ return compositeRefMul == Multiplicity.ZERO_ONE ||
+ compositeRefMul == Multiplicity.ONE_ONE;
+ case ZERO_N:
+ return true;
+ case ONE_N:
+ return true;
+ default:
+ return false;
+ }
+ } else {
+ switch (componentRefMul) {
+ case ZERO_ONE:
+ return compositeRefMul == Multiplicity.ONE_ONE;
+ case ONE_ONE:
+ return compositeRefMul == Multiplicity.ONE_ONE;
+ case ZERO_N:
+ return true;
+ case ONE_N:
+ return compositeRefMul == Multiplicity.ONE_ONE ||
+ compositeRefMul == Multiplicity.ONE_N;
+
+ default:
+ return false;
+ }
+ }
+ } else {
+ return true;
+ }
+ }
} //end class