summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/interface-java/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-07 21:58:19 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-07 21:58:19 +0000
commit316800505584f2b1645d8d1ea5ce21f87a3785e9 (patch)
tree070e7d54ada523a2850b11de676ef08ef8c63897 /java/sca/modules/interface-java/src
parentb0de81edb24b9247af5120bef1a06ed0e250957c (diff)
Handle the qualifier methods for the specific annotations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@791988 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/interface-java/src')
-rw-r--r--java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java41
-rw-r--r--java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java4
2 files changed, 35 insertions, 10 deletions
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();