diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-07 21:37:19 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-07 21:37:19 +0000 |
commit | b0de81edb24b9247af5120bef1a06ed0e250957c (patch) | |
tree | bf3609e1f483b9041c9a5ea8c123fe148e7ab1b7 /java/sca/modules/implementation-java/src | |
parent | 29826fcbbbe819fdb05b45e45f9e93f90fe47cfd (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/modules/implementation-java/src')
2 files changed, 35 insertions, 4 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); |