diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-20 11:15:59 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-20 11:15:59 +0000 |
commit | a89055accbb22a5c40b9e8f62ffac383c6b83479 (patch) | |
tree | eb3731548639ce622462f4c3587a60d89b1d5d82 | |
parent | 61b35b18fe64fc4eef8c84d0d6b35ef5fe7d3869 (diff) |
Correct the reference multiplicity validation algorithm to match what OASIS is expecting
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@806124 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
4 files changed, 64 insertions, 24 deletions
diff --git a/java/sca/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java b/java/sca/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java index 49c3deb84d..477d9b6721 100644 --- a/java/sca/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java +++ b/java/sca/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java @@ -48,7 +48,7 @@ public class AComponentImpl implements AComponent { private DComponent dReference2; - @Reference(name = "dReference1") + @Reference(name = "dReference1", required = false) public void setDReference(DComponent dReference) { this.dReference1 = dReference; } diff --git a/java/sca/itest/references/src/main/resources/AutoWiredReferencesTest.composite b/java/sca/itest/references/src/main/resources/AutoWiredReferencesTest.composite index 77851b81a7..3934025e64 100644 --- a/java/sca/itest/references/src/main/resources/AutoWiredReferencesTest.composite +++ b/java/sca/itest/references/src/main/resources/AutoWiredReferencesTest.composite @@ -23,7 +23,7 @@ <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" /> <reference name="bReference" target="BComponent" /> <reference name="cReference" autowire="true" /> - <reference name="dReference1" /> + <reference name="dReference1" multiplicity="0..1"/> <!-- <reference name="dReference1" target="DComponent" /> --> diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java index 4019a6eed2..64f89e84e4 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java @@ -35,6 +35,7 @@ import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Implementation; 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.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; @@ -81,7 +82,6 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI private void processComponentReferences(Composite composite) { monitor.pushContext("Composite: " + composite.getName().toString()); - try { // index all of the components in the composite Map<String, Component> components = new HashMap<String, Component>(); @@ -128,14 +128,20 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } // end if } // end for } // end for + + // Validate that references are wired or promoted, according + // to their multiplicity + validateReferenceMultiplicity(composite, component); } finally { monitor.popContext(); } } // end for + } finally { monitor.popContext(); } + } // end method processCompoenntReferences private void createReferenceEndpointReferences(Composite composite, @@ -154,6 +160,13 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI // autowired reference Multiplicity multiplicity = reference.getMultiplicity(); for (Component targetComponent : composite.getComponents()) { + + // Tuscany specific selection of the first autowire reference + // when there are more than one (ASM_60025) + if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && + (reference.getEndpointReferences().size() != 0) ) { + break; + } // Prevent autowire connecting to self if (targetComponent == component) @@ -393,6 +406,48 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } // end method + private void validateReferenceMultiplicity(Composite composite, Component component){ + for (ComponentReference componentReference : component.getReferences()) { + if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), + componentReference.getEndpointReferences())) { + if (componentReference.getEndpointReferences().isEmpty()) { + + // No error if the reference is promoted out of the current composite + boolean promoted = false; + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + if (compositeReference.getPromotedReferences().contains(componentReference)) { + promoted = true; + break; + } + } + if (!promoted && !componentReference.isForCallback()) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ReferenceWithoutTargets", + composite.getName().toString(), + componentReference.getName()); + } + } else { + // no error if reference is autowire and more targets + // than multiplicity have been found + if (componentReference.getAutowire() == true){ + break; + } + + // TUSCANY-3132 first example of updated error handling + Monitor.error(monitor, + this, + "assembly-validation-messages", + "TooManyReferenceTargets", + componentReference.getName()); + } + } + } + + } + /** * Create Endpoint References for a component reference inside a given composite * @param composite - the composite diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java index 3d34efa6d9..94e1a6eed9 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java @@ -79,16 +79,15 @@ abstract class ReferenceConfigurationUtil { } } - static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, List<?> targets, List<Binding> bindings) { + static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, List<EndpointReference> endpointReferences) { - // Count targets - int count = targets.size(); - - //FIXME workaround, this validation is sometimes invoked too early - // before we get a chance to init the multiplicity attribute - if (multiplicity == null) { + // In some tests multiplicity is not set + if (multiplicity == null){ return true; } + + // Count targets + int count = endpointReferences.size(); switch (multiplicity) { case ZERO_N: @@ -100,25 +99,11 @@ abstract class ReferenceConfigurationUtil { break; case ONE_ONE: if (count != 1) { - if (count == 0) { - for (Binding binding : bindings) { - if (!(binding instanceof OptimizableBinding) || binding.getURI() != null) { - return true; - } - } - } return false; } break; case ONE_N: if (count < 1) { - if (count == 0) { - for (Binding binding : bindings) { - if (!(binding instanceof OptimizableBinding) || binding.getURI() != null) { - return true; - } - } - } return false; } break; |