From 09befddffa67da83fc1e82285a4698043ea1f145 Mon Sep 17 00:00:00 2001 From: bdaniel Date: Tue, 17 Aug 2010 18:19:18 +0000 Subject: Handle inheritance of intents and policy sets on java interfaces git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@986433 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/impl/PolicyJavaInterfaceVisitor.java | 40 +++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'sca-java-2.x/trunk/modules/interface-java/src/main/java') diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java index 34ea4db3e9..1c0333f833 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.interfacedef.java.impl; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -41,6 +42,7 @@ import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; import org.oasisopen.sca.annotation.PolicySets; import org.oasisopen.sca.annotation.Qualifier; import org.oasisopen.sca.annotation.Requires; @@ -78,7 +80,7 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { * @param clazz * @param requiredIntents */ - private void readIntentsAndPolicySets(Class clazz, List requiredIntents, List policySets) { + private void readIntentsAndPolicySets(Class clazz, PolicySubject subject) { Requires intentAnnotation = clazz.getAnnotation(Requires.class); if (intentAnnotation != null) { String[] intentNames = intentAnnotation.value(); @@ -88,12 +90,12 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { // Add each intent to the list Intent intent = policyFactory.createIntent(); intent.setName(getQName(intentName)); - requiredIntents.add(intent); + subject.getRequiredIntents().add(intent); } } } - readSpecificIntents(clazz.getAnnotations(), requiredIntents); + readSpecificIntents(clazz.getAnnotations(), subject.getRequiredIntents()); PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class); if (policySetAnnotation != null) { @@ -104,7 +106,7 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { // Add each intent to the list PolicySet policySet = policyFactory.createPolicySet(); policySet.setName(getQName(policySetName)); - policySets.add(policySet); + subject.getPolicySets().add(policySet); } } } @@ -113,7 +115,7 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { // add soap intent Intent intent = policyFactory.createIntent(); intent.setName(Constants.SOAP_INTENT); - requiredIntents.add(intent); + subject.getRequiredIntents().add(intent); } @@ -192,23 +194,45 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { if (javaInterface.getJavaClass() != null) { - readIntentsAndPolicySets(javaInterface.getJavaClass(), javaInterface.getRequiredIntents(), javaInterface - .getPolicySets()); + readIntentsAndPolicySets(javaInterface.getJavaClass(), javaInterface); // Read intents on the service interface methods List operations = javaInterface.getOperations(); for (Operation op : operations) { JavaOperation operation = (JavaOperation)op; Method method = operation.getJavaMethod(); + readIntents(method.getAnnotation(Requires.class), op.getRequiredIntents()); readSpecificIntents(method.getAnnotations(), op.getRequiredIntents()); readPolicySets(method.getAnnotation(PolicySets.class), op.getPolicySets()); readWebServicesAnnotations(method, javaInterface.getJavaClass(), javaInterface.getRequiredIntents()); + inherit(javaInterface, op); } } + + + + } - private void readSpecificIntents(Annotation[] annotations, List requiredIntents) { + private void inherit(JavaInterface javaInterface, Operation op) { + List interfaceIntents = new ArrayList(javaInterface.getRequiredIntents()); + for ( Intent intent : javaInterface.getRequiredIntents() ) { + + for ( Intent operationIntent : op.getRequiredIntents() ) { + if ( intent.getExcludedIntents().contains(operationIntent) || + operationIntent.getExcludedIntents().contains(intent) ) { + interfaceIntents.remove(intent); + continue; + } + } + } + op.getRequiredIntents().addAll(interfaceIntents); + + op.getPolicySets().addAll(javaInterface.getPolicySets()); + } + + private void readSpecificIntents(Annotation[] annotations, List requiredIntents) { for (Annotation a : annotations) { org.oasisopen.sca.annotation.Intent intentAnnotation = a.annotationType().getAnnotation(org.oasisopen.sca.annotation.Intent.class); -- cgit v1.2.3