From 80a7a00fc58f32cd4c6a378cb9d861f65c4802c1 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 11 Mar 2010 15:42:08 +0000 Subject: TUSCANY-3483 - ensure that policies defined in the implementation are applied correctly to the component service. This pointed out another problem in that if binding.sca was defined on the reference with no uri but with intents then the intents weren't being applied to the EPR because the binding was being ignored (as it's a targeted reference). git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@921903 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/impl/ComponentPolicyBuilderImpl.java | 111 +++++++++++++++++---- .../builder/impl/CompositePolicyBuilderImpl.java | 24 +++-- .../builder/impl/EndpointReferenceBuilderImpl.java | 12 +++ 3 files changed, 117 insertions(+), 30 deletions(-) (limited to 'sca-java-2.x/trunk/modules/builder/src/main/java/org/apache') diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java index 23822b694e..e7e83757ad 100644 --- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java +++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentPolicyBuilderImpl.java @@ -89,21 +89,33 @@ public class ComponentPolicyBuilderImpl { Monitor.error(monitor, this, Messages.ASSEMBLY_VALIDATION, message, messageParameters); } + /** * Inherit the intents and policySets from the list of models - * @param ignoreExclusiveIntents TODO - * @param models - * @param intents - * @param policySets + * + * @param policySubject - the subject to which intents will be added + * @param intentType - choose to copy interaction or implementation intents. Null = both + * @param ignoreExclusiveIntents - when set true mutually exclusive intents won't be copied + * @param models - the subjects from which intents will be copied */ - protected void inherit(PolicySubject policySubject, boolean ignoreExclusiveIntents, Object... models) { + protected void inherit(PolicySubject policySubject, Intent.Type intentType, boolean ignoreExclusiveIntents, Object... models) { for (Object model : models) { if (model instanceof PolicySubject) { PolicySubject subject = (PolicySubject)model; if (!ignoreExclusiveIntents) { // The intents are merged and the exclusion check will be done after - policySubject.getRequiredIntents().addAll(subject.getRequiredIntents()); + for (Intent intent : subject.getRequiredIntents()) { + if (!policySubject.getRequiredIntents().contains(intent)){ + if (intentType != null) { + if (intent.getType().equals(intentType)){ + policySubject.getRequiredIntents().add(intent); + } + } else { + policySubject.getRequiredIntents().add(intent); + } + } + } } else { Set intents = new HashSet(); for (Intent i1 : subject.getRequiredIntents()) { @@ -115,7 +127,15 @@ public class ComponentPolicyBuilderImpl { } } if (!exclusive) { - intents.add(i1); + if (!intents.contains(i1)){ + if (intentType != null) { + if (i1.getType().equals(intentType)){ + intents.add(i1); + } + } else { + intents.add(i1); + } + } } } policySubject.getRequiredIntents().addAll(intents); @@ -130,21 +150,21 @@ public class ComponentPolicyBuilderImpl { } } - protected void configure(PolicySubject subject1, PolicySubject subject2, BuilderContext context) { + protected void configure(PolicySubject subject1, PolicySubject subject2, Intent.Type intentType, BuilderContext context) { if (subject1 != null) { resolveAndCheck(subject1, context); } if (subject2 != null) { resolveAndCheck(subject2, context); } - inherit(subject1, false, subject2); + inherit(subject1, intentType, false, subject2); checkMutualExclusion(subject1, context); } protected void configure(ComponentService componentService, BuilderContext context) { Service service = componentService.getService(); if (service != null) { - configure(componentService, service, context); + configure(componentService, service, null, context); configureBindings(componentService, service, context); } } @@ -160,7 +180,7 @@ public class ComponentPolicyBuilderImpl { for (Binding binding : componentContract.getBindings()) { Binding componentTypeBinding = componentTypeContractBindings.get(binding.getName()); if (binding instanceof PolicySubject) { - inherit((PolicySubject)binding, false, componentTypeBinding, context); + inherit((PolicySubject)binding, null, false, componentTypeBinding, context); } } } @@ -168,35 +188,64 @@ public class ComponentPolicyBuilderImpl { protected void configure(ComponentReference componentReference, BuilderContext context) { Reference reference = componentReference.getReference(); if (reference != null) { - configure(componentReference, reference, context); + configure(componentReference, reference, null, context); configureBindings(componentReference, reference, context); } } protected void configure(CompositeService compositeService, BuilderContext context) { - configure(compositeService, compositeService.getPromotedService(), context); + configure(compositeService, compositeService.getPromotedService(), null, context); } protected void configure(CompositeReference compositeReference, BuilderContext context) { for (ComponentReference reference : compositeReference.getPromotedReferences()) { - configure(compositeReference, reference, context); + configure(compositeReference, reference, null, context); } } public void configure(Component component, BuilderContext context) { - // Inherit the intents and policySets from the componentType - configure(component, component.getImplementation(), context); + // fix up the component type by copying all implementation level + // interaction intents to *all* the component type services + for (ComponentService componentService : component.getServices()) { + configure(componentService, component.getImplementation(), Intent.Type.interaction, context); + } + // Inherit the intents and policySets from the componentType for (ComponentReference componentReference : component.getReferences()) { configure(componentReference, context); } + for (ComponentService componentService : component.getServices()) { configure(componentService, context); } } + + protected boolean checkQualifiedMutualExclusion(List excludedIntentList, Intent intent){ + for (Intent excludedIntent : excludedIntentList){ + if (intent.getQualifiableIntent() != null && + excludedIntent != null && + intent.getQualifiableIntent().equals(excludedIntent)){ + return true; + } + } + return false; + } + + protected boolean checkMutualExclusion(Intent i1, Intent i2, BuilderContext context){ + if ((i1 != i2) && + (i1.getExcludedIntents().contains(i2) || + i2.getExcludedIntents().contains(i1) || + checkQualifiedMutualExclusion(i1.getExcludedIntents(), i2) || + checkQualifiedMutualExclusion(i2.getExcludedIntents(), i1))) { + error(context.getMonitor(), "MutuallyExclusiveIntents", this, i1, i2); + return true; + } + + return false; + } /** - * Check if a single policy subject requires multually exclusive intents + * Check if a single policy subject requires mutually exclusive intents * @param subject1 - the policy subject to check * @param context - context containing useful things like the monitor instance * @return true if the policy subject contains mutually exclusive intents @@ -207,17 +256,26 @@ public class ComponentPolicyBuilderImpl { } for (Intent i1 : subject1.getRequiredIntents()) { for (Intent i2 : subject1.getRequiredIntents()) { - if ((i1 != i2) && (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1))) { + if (checkMutualExclusion(i1, i2, context)){ + return true; + } +/* + if ((i1 != i2) && + (i1.getExcludedIntents().contains(i2) || + i2.getExcludedIntents().contains(i1) || + matchQualifiedMutualExclusion(i1.getExcludedIntents(), i2) || + matchQualifiedMutualExclusion(i2.getExcludedIntents(), i1))) { error(context.getMonitor(), "MutuallyExclusiveIntents", new Object[] {subject1}, i1, i2); return true; } +*/ } } return false; } /** - * Check if two policy subjects requires multually exclusive intents + * Check if two policy subjects requires mutually exclusive intents * @param subject1 * @param subject2 * @param monitor @@ -229,10 +287,18 @@ public class ComponentPolicyBuilderImpl { } for (Intent i1 : subject1.getRequiredIntents()) { for (Intent i2 : subject2.getRequiredIntents()) { - if (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) { + if (checkMutualExclusion(i1, i2, context)){ + return true; + } +/* + if (i1.getExcludedIntents().contains(i2) || + i2.getExcludedIntents().contains(i1) || + matchQualifiedMutualExclusion(i1.getExcludedIntents(), i2) || + matchQualifiedMutualExclusion(i2.getExcludedIntents(), i1)) { error(context.getMonitor(), "MutuallyExclusiveIntents", new Object[] {subject1, subject2}, i1, i2); return true; } +*/ } } return false; @@ -250,10 +316,15 @@ public class ComponentPolicyBuilderImpl { for (int j = i + 1; j < size; j++) { Intent i1 = intents.get(i); Intent i2 = intents.get(j); + if (checkMutualExclusion(i1, i2, context)){ + return true; + } +/* if (i1 != i2 && i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) { error(context.getMonitor(), "MutuallyExclusiveIntents", subject, i1, i2); return true; } +*/ } } return false; diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java index eed032ba6d..c8cd50f11e 100644 --- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java +++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java @@ -77,7 +77,7 @@ public class CompositePolicyBuilderImpl extends ComponentPolicyBuilderImpl imple try { Implementation implementation = component.getImplementation(); - + for (ComponentService componentService : component.getServices()) { monitor.pushContext("Service: " + componentService.getName()); @@ -94,12 +94,14 @@ public class CompositePolicyBuilderImpl extends ComponentPolicyBuilderImpl imple for (Endpoint ep : componentService.getEndpoints()) { if (componentService.getInterfaceContract() != null) { // Inherit from the component.service.interface - inherit(ep, true, componentService.getInterfaceContract().getInterface()); + inherit(ep, null, true, componentService.getInterfaceContract().getInterface()); } + // Inherit from composite/component/service - inherit(ep, true, composite, ep.getComponent(), ep.getService()); + inherit(ep, null, true, composite, ep.getComponent(), ep.getService()); + // Inherit from binding - inherit(ep, true, ep.getBinding()); + inherit(ep, null, true, ep.getBinding()); // Replace profile intents with their required intents // Remove the intents whose @contraints do not include the current element @@ -131,12 +133,14 @@ public class CompositePolicyBuilderImpl extends ComponentPolicyBuilderImpl imple // Inherit from the component.reference.interface if (componentReference.getInterfaceContract() != null) { - inherit(epr, true, componentReference.getInterfaceContract().getInterface()); + inherit(epr, null, true, componentReference.getInterfaceContract().getInterface()); } - // Inherit from composite/component/reference/binding - inherit(epr, true, composite, epr.getComponent(), epr.getReference()); - inherit(epr, true, epr.getBinding()); + // Inherit from composite/component/reference + inherit(epr, null, true, composite, epr.getComponent(), epr.getReference()); + + // Inherit from binding + inherit(epr, null, true, epr.getBinding()); // Replace profile intents with their required intents // Remove the intents whose @contraints do not include the current element @@ -153,12 +157,12 @@ public class CompositePolicyBuilderImpl extends ComponentPolicyBuilderImpl imple } if (implementation instanceof Composite) { - inherit(implementation, true, component, composite); + inherit(implementation, null, true, component, composite); computePolicies((Composite)implementation, context); } else { resolveAndCheck(implementation, context); if (implementation != null) { - inherit(implementation, true, component, composite); + inherit(implementation, null, true, component, composite); } } } finally { diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java index 8771a204eb..2dd21fe3e6 100644 --- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java +++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java @@ -271,6 +271,18 @@ public class EndpointReferenceBuilderImpl { endpointRef.setTargetEndpoint(createEndpoint(component, target.getName())); endpointRef.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); + + // There is a special case where the user has defined policies on a + // non-targetted, i.e. no URI, binding.sca in order to control the + // intended QoS of the wire when matching takes place. If any other + // bindings are specified then the test later on will complain about + // mixing targts with bindings + if (reference.getBindings().size() == 1){ + Binding binding = reference.getBindings().get(0); + if ((binding instanceof SCABinding) && (binding.getURI() == null)){ + endpointRef.setBinding(binding); + } + } } } -- cgit v1.2.3