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/interface-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/interface-java/src')
2 files changed, 31 insertions, 2 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 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"}) |