summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-10-15 17:05:45 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-10-15 17:05:45 +0000
commita5f1f82a1a35d131a48a034cc747dffb1c58a037 (patch)
tree9a7c6468517b4d20041ef68448b945c114ba690f
parentd1dcca2183c5470878370e7ad896dbc3138ae388 (diff)
Fixes for otests JCA 3006, 3007, and 3008
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825565 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java123
-rw-r--r--java/sca/modules/interface-java/src/main/resources/interface-javaxml-validation-messages.properties4
2 files changed, 126 insertions, 1 deletions
diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java
index b7c953813a..d32db1be52 100644
--- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java
+++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java
@@ -21,6 +21,12 @@ package org.apache.tuscany.sca.interfacedef.java.xml;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -40,6 +46,20 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.oasisopen.sca.annotation.AllowsPassByReference;
+import org.oasisopen.sca.annotation.Callback;
+import org.oasisopen.sca.annotation.ComponentName;
+import org.oasisopen.sca.annotation.Constructor;
+import org.oasisopen.sca.annotation.Context;
+import org.oasisopen.sca.annotation.Destroy;
+import org.oasisopen.sca.annotation.EagerInit;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Intent;
+import org.oasisopen.sca.annotation.Property;
+import org.oasisopen.sca.annotation.Qualifier;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
/**
*
@@ -179,7 +199,7 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa
}
return javaInterface;
}
-
+
public void resolve(JavaInterfaceContract javaInterfaceContract, ModelResolver resolver) throws ContributionResolveException {
try {
// Resolve the interface and callback interface
@@ -188,11 +208,112 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa
JavaInterface javaCallbackInterface = resolveJavaInterface((JavaInterface)javaInterfaceContract.getCallbackInterface(), resolver);
javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
+
+ checkForbiddenAnnotations(javaInterfaceContract);
+
} catch (Exception e) {
throw new ContributionResolveException( "Resolving Java Interface " + javaInterfaceContract.getInterface().toString(), e );
} // end try
}
+ private static List<Class<?>> JCA30006_ANNOTATIONS =
+ Arrays.asList(new Class<?>[] {AllowsPassByReference.class, ComponentName.class, Constructor.class, Context.class,
+ Destroy.class, EagerInit.class, Init.class, Intent.class, Property.class, Qualifier.class,
+ Reference.class, Scope.class, Service.class});
+ private static List<Class<?>> JCA30007_ANNOTATIONS =
+ Arrays.asList(new Class<?>[] {AllowsPassByReference.class, Callback.class, ComponentName.class, Constructor.class,
+ Context.class, Destroy.class, EagerInit.class, Init.class, Intent.class,
+ Property.class, Qualifier.class, Reference.class, Scope.class, Service.class});
+ private static List<Class<?>> JCA30008_ANNOTATIONS = Arrays.asList(new Class<?>[] {Intent.class, Qualifier.class});
+
+ private void checkForbiddenAnnotations(JavaInterfaceContract javaInterfaceContract) {
+ if (javaInterfaceContract.getInterface() != null) {
+ Class<?> ifc = ((JavaInterface) javaInterfaceContract.getInterface()).getJavaClass();
+ if (ifc != null) {
+ for (Annotation a : ifc.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30006_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30006", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ for (Method m : ifc.getMethods()) {
+ for (Annotation a : m.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30006_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30006", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ for (Field f : ifc.getFields()) {
+ for (Annotation a : f.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30006_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30006", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ }
+
+ if (javaInterfaceContract.getCallbackInterface() != null) {
+ Class<?> ifc = ((JavaInterface) javaInterfaceContract.getCallbackInterface()).getJavaClass();
+ if (ifc != null) {
+ for (Annotation a : ifc.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30007_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30007", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ for (Method m : ifc.getMethods()) {
+ for (Annotation a : m.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30007_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30007", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ for (Field f : ifc.getFields()) {
+ for (Annotation a : f.getAnnotations()) {
+ if (ifc.isInterface()) {
+ if (JCA30007_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30007", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ } else {
+ if (JCA30008_ANNOTATIONS.contains(a.annotationType())) {
+ error("ForbiddenAnnotationJCA30008", javaInterfaceContract, a.annotationType(), ifc.getName());
+ }
+ }
+ }
+ }
+ }
+ }
+
public QName getArtifactType() {
return INTERFACE_JAVA_QNAME;
}
diff --git a/java/sca/modules/interface-java/src/main/resources/interface-javaxml-validation-messages.properties b/java/sca/modules/interface-java/src/main/resources/interface-javaxml-validation-messages.properties
index 4f55c0b3e1..3aef8f69ac 100644
--- a/java/sca/modules/interface-java/src/main/resources/interface-javaxml-validation-messages.properties
+++ b/java/sca/modules/interface-java/src/main/resources/interface-javaxml-validation-messages.properties
@@ -21,3 +21,7 @@
ClassNotFoundException = Class Not Found Exception: {0}
ContributionResolveException = ContributionResolveException occurred due to: {0}
InvalidInterfaceException = InvalidInterfaceException due to: {0}
+ForbiddenAnnotationJCA30006 = JCA30006 Forbidden annotation {0} found in class {1}
+ForbiddenAnnotationJCA30007 = JCA30007 Forbidden annotation {0} found in class {1}
+ForbiddenAnnotationJCA30008 = JCA30008 Forbidden annotation {0} found in class {1}
+