summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java23
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java3
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());
}