summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-07 21:37:19 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-07 21:37:19 +0000
commitb0de81edb24b9247af5120bef1a06ed0e250957c (patch)
treebf3609e1f483b9041c9a5ea8c123fe148e7ab1b7 /java/sca
parent29826fcbbbe819fdb05b45e45f9e93f90fe47cfd (diff)
Add support to introspect intents from specific annotations such as @Authentication
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@791984 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java26
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java13
-rw-r--r--java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java24
-rw-r--r--java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java9
4 files changed, 66 insertions, 6 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 f48358eddf..ca644168ef 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
@@ -18,6 +18,7 @@
*/
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.List;
@@ -72,6 +73,7 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
Reference reference = null;
if ( (reference = getReferenceByName(name, type)) != null ) {
readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readSpecificIntents(field.getAnnotations(), reference.getRequiredIntents());
readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
}
}
@@ -81,6 +83,7 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
Reference reference = null;
if ( (reference = getReference(method, type)) != null ) {
readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readSpecificIntents(method.getAnnotations(), reference.getRequiredIntents());
readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
} else {
/*
@@ -178,6 +181,27 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
}
}
}
+
+ private void readSpecificIntents(Annotation[] annotations, List<Intent> requiredIntents) {
+ for (Annotation a : annotations) {
+ org.oasisopen.sca.annotation.Intent intentAnnotation =
+ a.annotationType().getAnnotation(org.oasisopen.sca.annotation.Intent.class);
+ if (intentAnnotation == null) {
+ continue;
+ }
+ QName qname = null;
+ String value = intentAnnotation.value();
+ if (!value.equals("")) {
+ qname = getQName(value);
+ } else {
+ qname = new QName(intentAnnotation.targetNamespace(), intentAnnotation.localPart());
+ }
+ Intent intent = policyFactory.createIntent();
+ intent.setUnresolved(true);
+ intent.setName(qname);
+ requiredIntents.add(intent);
+ }
+ }
/**
* Read policy intents on the given interface or class
@@ -201,6 +225,8 @@ public class PolicyProcessor extends BaseJavaClassVisitor {
}
}
+ readSpecificIntents(clazz.getAnnotations(), requiredIntents);
+
PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
if (policySetAnnotation != null) {
String[] policySetNames = policySetAnnotation.value();
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
index 6c9ffc7975..1a7889366e 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
@@ -53,28 +53,33 @@ public class PolicyProcessorTestCase {
// This actually is a test for PolicyJavaInterfaceProcessor. It will get
// invoked via the call to ImplementationProcessorServiceImpl.createService in
// ServiceProcessor. Of course ServiceProcessor class has to be working.
- public void stestSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ @Test
+ public void testSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
serviceProcessor.visitClass(Service1.class, type);
visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
policyProcessor.visitClass(Service1.class, type);
verifyIntents(Service1.class, type);
}
- public void stestMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ @Test
+ public void testMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
serviceProcessor.visitClass(Service2.class, type);
visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ visitor.visitInterface((JavaInterface)type.getServices().get(1).getInterfaceContract().getInterface());
policyProcessor.visitClass(Service2.class, type);
verifyIntents(Service2.class, type);
}
- public void stestSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
+ @Test
+ public void testSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
serviceProcessor.visitClass(Service3.class, type);
visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
policyProcessor.visitClass(Service3.class, type);
verifyIntents(Service3.class, type);
}
- public void stestMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
+ @Test
+ public void testMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
serviceProcessor.visitClass(Service4.class, type);
visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
policyProcessor.visitClass(Service4.class, type);
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 bf80bef175..b41c0b318d 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
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.sca.interfacedef.java.impl;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
@@ -82,6 +83,8 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor {
}
}
+ readSpecificIntents(clazz.getAnnotations(), requiredIntents);
+
PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
if (policySetAnnotation != null) {
String[] policySetNames = policySetAnnotation.value();
@@ -156,4 +159,25 @@ public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor {
}
}
+ private void readSpecificIntents(Annotation[] annotations, List<Intent> requiredIntents) {
+ for (Annotation a : annotations) {
+ org.oasisopen.sca.annotation.Intent intentAnnotation =
+ a.annotationType().getAnnotation(org.oasisopen.sca.annotation.Intent.class);
+ if (intentAnnotation == null) {
+ continue;
+ }
+ QName qname = null;
+ String value = intentAnnotation.value();
+ if (!value.equals("")) {
+ qname = getQName(value);
+ } else {
+ qname = new QName(intentAnnotation.targetNamespace(), intentAnnotation.localPart());
+ }
+ Intent intent = policyFactory.createIntent();
+ intent.setUnresolved(true);
+ 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 3833699421..8d1eb9796e 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
@@ -27,6 +27,8 @@ import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor;
import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
import org.junit.Before;
import org.junit.Test;
+import org.oasisopen.sca.annotation.Authentication;
+import org.oasisopen.sca.annotation.Confidentiality;
import org.oasisopen.sca.annotation.PolicySets;
import org.oasisopen.sca.annotation.Requires;
@@ -41,7 +43,7 @@ public class PolicyProcessorTestCase {
public void testInterfaceLevel() throws Exception {
JavaInterface type = factory.createJavaInterface(Interface1.class);
policyProcessor.visitInterface(type);
- assertEquals(1, type.getRequiredIntents().size());
+ assertEquals(2, type.getRequiredIntents().size());
assertEquals(1, type.getPolicySets().size());
}
@@ -61,7 +63,7 @@ public class PolicyProcessorTestCase {
public void testInterfaceAndMethodLevel() throws Exception {
JavaInterface type = factory.createJavaInterface(Interface3.class);
policyProcessor.visitInterface(type);
- assertEquals(1, type.getRequiredIntents().size());
+ assertEquals(2, type.getRequiredIntents().size());
assertEquals(1, type.getOperations().get(0).getRequiredIntents().size());
assertEquals(1, type.getOperations().get(1).getRequiredIntents().size());
assertEquals(1, type.getPolicySets().size());
@@ -77,6 +79,7 @@ public class PolicyProcessorTestCase {
// @Remotable
@Requires( {"transaction.global"})
@PolicySets( {"{http://ns1}PS1"})
+ @Authentication
private interface Interface1 {
int method1();
@@ -89,6 +92,7 @@ public class PolicyProcessorTestCase {
private interface Interface2 {
@Requires( {"transaction.global"})
+ @Confidentiality({"message"})
@PolicySets( {"{http://ns1}PS1"})
int method1();
@@ -99,6 +103,7 @@ public class PolicyProcessorTestCase {
@Requires( {"transaction.global.Interface6"})
@PolicySets( {"{http://ns1}PS1"})
+ @Authentication
private interface Interface3 {
@Requires( {"transaction.global.Interface6.method1"})
@PolicySets( {"{http://ns1}PS2"})