diff options
Diffstat (limited to 'java')
3 files changed, 65 insertions, 14 deletions
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java index ca644168ef..ac7187b1c7 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java @@ -21,7 +21,10 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.xml.namespace.QName; @@ -41,6 +44,7 @@ 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; /** @@ -196,10 +200,32 @@ public class PolicyProcessor extends BaseJavaClassVisitor { } else { qname = new QName(intentAnnotation.targetNamespace(), intentAnnotation.localPart()); } - Intent intent = policyFactory.createIntent(); - intent.setUnresolved(true); - intent.setName(qname); - requiredIntents.add(intent); + Set<String> qualifiers = new HashSet<String>(); + for(Method m: a.annotationType().getMethods()) { + Qualifier qualifier = m.getAnnotation(Qualifier.class); + if (qualifier != null && m.getReturnType() == String[].class) { + try { + qualifiers.addAll(Arrays.asList((String[]) m.invoke(a))); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + qualifiers.remove(""); + if (qualifiers.isEmpty()) { + Intent intent = policyFactory.createIntent(); + intent.setUnresolved(true); + intent.setName(qname); + requiredIntents.add(intent); + } else { + for (String q : qualifiers) { + Intent intent = policyFactory.createIntent(); + intent.setUnresolved(true); + qname = new QName(qname.getNamespaceURI(), qname.getLocalPart() + "." + q); + intent.setName(qname); + requiredIntents.add(intent); + } + } } } diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java index b41c0b318d..cda87188be 100644 --- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java +++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java @@ -20,7 +20,10 @@ package org.apache.tuscany.sca.interfacedef.java.impl; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.xml.namespace.QName; @@ -33,6 +36,7 @@ import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySet; import org.oasisopen.sca.annotation.PolicySets; +import org.oasisopen.sca.annotation.Qualifier; import org.oasisopen.sca.annotation.Requires; /** @@ -151,10 +155,9 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { for (Operation op : operations) { JavaOperation operation = (JavaOperation)op; Method method = operation.getJavaMethod(); - if (method.getAnnotation(Requires.class) != null || method.getAnnotation(PolicySets.class) != null) { - readIntents(method.getAnnotation(Requires.class), op.getRequiredIntents()); - readPolicySets(method.getAnnotation(PolicySets.class), op.getPolicySets()); - } + readIntents(method.getAnnotation(Requires.class), op.getRequiredIntents()); + readSpecificIntents(method.getAnnotations(), op.getRequiredIntents()); + readPolicySets(method.getAnnotation(PolicySets.class), op.getPolicySets()); } } } @@ -173,10 +176,32 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { } else { qname = new QName(intentAnnotation.targetNamespace(), intentAnnotation.localPart()); } - Intent intent = policyFactory.createIntent(); - intent.setUnresolved(true); - intent.setName(qname); - requiredIntents.add(intent); + Set<String> qualifiers = new HashSet<String>(); + for(Method m: a.annotationType().getMethods()) { + Qualifier qualifier = m.getAnnotation(Qualifier.class); + if (qualifier != null && m.getReturnType() == String[].class) { + try { + qualifiers.addAll(Arrays.asList((String[]) m.invoke(a))); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + qualifiers.remove(""); + if (qualifiers.isEmpty()) { + Intent intent = policyFactory.createIntent(); + intent.setUnresolved(true); + intent.setName(qname); + requiredIntents.add(intent); + } else { + for (String q : qualifiers) { + Intent intent = policyFactory.createIntent(); + intent.setUnresolved(true); + qname = new QName(qname.getNamespaceURI(), qname.getLocalPart() + "." + q); + intent.setName(qname); + requiredIntents.add(intent); + } + } } } diff --git a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java index 8d1eb9796e..925fe90f1c 100644 --- a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java +++ b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java @@ -52,7 +52,7 @@ public class PolicyProcessorTestCase { JavaInterface type = factory.createJavaInterface(Interface2.class); policyProcessor.visitInterface(type); assertEquals(0, type.getRequiredIntents().size()); - assertEquals(1, type.getOperations().get(0).getRequiredIntents().size()); + assertEquals(3, type.getOperations().get(0).getRequiredIntents().size()); assertEquals(1, type.getOperations().get(1).getRequiredIntents().size()); assertEquals(0, type.getPolicySets().size()); assertEquals(1, type.getOperations().get(0).getPolicySets().size()); @@ -92,7 +92,7 @@ public class PolicyProcessorTestCase { private interface Interface2 { @Requires( {"transaction.global"}) - @Confidentiality({"message"}) + @Confidentiality({"message", "transport"}) @PolicySets( {"{http://ns1}PS1"}) int method1(); |