diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-05 12:59:57 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-05 12:59:57 +0000 |
commit | 72ba5ab2910c858e178691fc3b14796bf25209ea (patch) | |
tree | 58aa9b493759e2ac534d530ec18db5933b2e9f4a /sca-java-2.x/trunk/modules/builder/src/main/java | |
parent | cc1316754fddeeaa691825a79b9db3c5f227cdcc (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
Diffstat (limited to 'sca-java-2.x/trunk/modules/builder/src/main/java')
-rw-r--r-- | sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java | 67 |
1 files changed, 67 insertions, 0 deletions
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 |