diff options
author | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-17 21:22:24 +0000 |
---|---|---|
committer | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-17 21:22:24 +0000 |
commit | f75a5166c0b4a053e2a0505b535e9c885892a401 (patch) | |
tree | 173ecc852619c8dc0fc89422687c947b9104771e /sca-java-2.x/trunk/modules | |
parent | f922d1b271fb45ad5b32e3ad0753f0afbd5e95a4 (diff) |
Only create tx impl interceptors for valid policies
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1137033 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
2 files changed, 24 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java index d4fcc0e8fc..ab1b33ac3c 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyContainer; import org.apache.tuscany.sca.policy.PolicyExpression; import org.apache.tuscany.sca.policy.PolicySet; @@ -52,9 +53,29 @@ public abstract class BasePolicyProvider<T> implements PolicyProvider { this.subject = subject; } + protected List<T> findPoliciesWithProvidedIntents(List<Intent> intents) { + List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>(); + List<PolicySet> policySets = subject.getPolicySets(); + for ( PolicySet ps : policySets ) { + List<Intent> provided = ps.getProvidedIntents(); + for ( Intent intent : intents ) { + if ( provided.contains(intent) ) { + applicablePolicySets.add(ps); + continue; + } + + } + } + return findPolicies(applicablePolicySets); + } + protected List<T> findPolicies() { + return findPolicies(subject.getPolicySets()); + } + + private List<T> findPolicies(List<PolicySet> policySets) { List<T> policies = new ArrayList<T>(); - List<PolicySet> policySets = subject.getPolicySets(); + for (PolicySet ps : policySets) { for (Object p : ps.getPolicies()) { if (policyType.isInstance(p)) { diff --git a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java index bd75472256..9254d74c4f 100644 --- a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java @@ -40,7 +40,8 @@ public class TransactionImplementationPolicyProvider extends BasePolicyProvider< } public PhasedInterceptor createInterceptor(Operation operation) { - List<TransactionPolicy> policies = findPolicies(); + // Only create an interceptor for the policy that matches the required intent. + List<TransactionPolicy> policies = findPoliciesWithProvidedIntents(subject.getRequiredIntents()); return policies.isEmpty() ? null : new TransactionInterceptor(helper, false, null, policies.get(0), getPhase()); } |