summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java5
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java15
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF1
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java46
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java51
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java4
6 files changed, 81 insertions, 41 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
index 3cf109c8cf..22879c2beb 100644
--- a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
+++ b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
@@ -29,6 +29,7 @@ import static org.apache.tuscany.sca.assembly.xml.Constants.COMPONENT_QNAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.COMPOSITE;
import static org.apache.tuscany.sca.assembly.xml.Constants.COMPOSITE_QNAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.ELEMENT;
+import static org.apache.tuscany.sca.assembly.xml.Constants.EXTENSION_QNAME;
import static org.apache.tuscany.sca.assembly.xml.Constants.FILE;
import static org.apache.tuscany.sca.assembly.xml.Constants.IMPLEMENTATION_COMPOSITE;
import static org.apache.tuscany.sca.assembly.xml.Constants.IMPLEMENTATION_COMPOSITE_QNAME;
@@ -59,7 +60,6 @@ import static org.apache.tuscany.sca.assembly.xml.Constants.URI;
import static org.apache.tuscany.sca.assembly.xml.Constants.WIRE;
import static org.apache.tuscany.sca.assembly.xml.Constants.WIRED_BY_IMPL;
import static org.apache.tuscany.sca.assembly.xml.Constants.WIRE_QNAME;
-import static org.apache.tuscany.sca.assembly.xml.Constants.EXTENSION_QNAME;
import java.util.ArrayList;
import java.util.List;
@@ -1121,7 +1121,8 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt
XSDefinition resolved = contribution.getModelResolver().resolveModel(XSDefinition.class, xsdDefinition, context);
if (resolved == null || resolved.isUnresolved()){
// raise an error
- error(context.getMonitor(), "PropertyTypeNotFound", property, property.getXSDType().toString(), property.getName(), parentName);
+ // [rfeng] The XSD might be not available if we use JAXB annotated classes, report it as a warning for now
+ warning(context.getMonitor(), "PropertyTypeNotFound", property, property.getXSDType().toString(), property.getName(), parentName);
} else {
// store the schema in the property
property.setXSDDefinition(resolved);
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java
index 99a8b6d3d7..16de5bbefb 100644
--- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/databinding/PropertyDataTypeProcessor.java
@@ -29,7 +29,6 @@ import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
import org.apache.tuscany.sca.interfacedef.DataType;
-import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
@@ -53,12 +52,10 @@ public class PropertyDataTypeProcessor extends BaseJavaClassVisitor {
* @param javaElement
* @return
*/
- private DataType<?> introspect(Property property, JavaElementImpl javaElement) {
- XMLType xmlType = new XMLType(property.getXSDElement(), property.getXSDType());
- DataType<XMLType> dt =
- new DataTypeImpl<XMLType>(null, javaElement.getType(), javaElement.getGenericType(), xmlType);
- mediator.getDataBindings().introspectType(dt, null);
- return dt;
+ private void introspect(Property property, JavaElementImpl javaElement) {
+ // XMLType xmlType = new XMLType(property.getXSDElement(), property.getXSDType());
+ // property.getDataType().setLogical(xmlType);
+ mediator.getDataBindings().introspectType(property.getDataType(), null);
}
@Override
@@ -66,8 +63,8 @@ public class PropertyDataTypeProcessor extends BaseJavaClassVisitor {
for (Property property : type.getProperties()) {
String name = property.getName();
JavaElementImpl element = type.getPropertyMembers().get(name);
- DataType dt = introspect(property, element);
- property.setDataType(dt);
+ introspect(property, element);
+ DataType dt = property.getDataType();
if (dt.getLogical() instanceof XMLType) {
XMLType xmlType = (XMLType)dt.getLogical();
property.setXSDType(xmlType.getTypeName());
diff --git a/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
index 44f27a2c5f..7850a30f48 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/implementation-java/META-INF/MANIFEST.MF
@@ -32,6 +32,7 @@ Import-Package: javax.jws,
org.apache.tuscany.sca.implementation.java;version="2.0.0",
org.apache.tuscany.sca.implementation.java.introspect;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.impl;version="2.0.0",
org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
org.apache.tuscany.sca.interfacedef.java.impl;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
index 180ea3e64d..ff70fb89eb 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
@@ -29,6 +30,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
@@ -37,7 +39,9 @@ import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaParameterImpl;
import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor;
import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
-import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
/**
* Base class for ImplementationProcessors that handle annotations that add
@@ -203,21 +207,45 @@ public abstract class AbstractPropertyProcessor<A extends Annotation> extends Ba
protected Property createProperty(String name, JavaElementImpl element) throws IntrospectionException {
+ Type type = element.getGenericType();
+ Class<?> javaType = element.getType();
+
+ return createProperty(assemblyFactory, name, javaType, type);
+
+ }
+
+ public static Property createProperty(AssemblyFactory assemblyFactory, String name, Class<?> javaClass, Type genericType) {
Property property = assemblyFactory.createProperty();
property.setName(name);
-
- Class<?> javaType = element.getType();
- if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
+
+ if (javaClass.isArray() || Collection.class.isAssignableFrom(javaClass)) {
property.setMany(true);
- Type type = element.getGenericType();
- if (type instanceof ParameterizedType){
- property.setXSDType(JavaXMLMapper.getXMLType((Class)((ParameterizedType)type).getActualTypeArguments()[0]));
+ if (javaClass.isArray()) {
+ Class<?> propType = javaClass.getComponentType();
+ Type genericPropType = propType;
+ if (genericType instanceof GenericArrayType) {
+ genericPropType = ((GenericArrayType)genericType).getGenericComponentType();
+ }
+ DataType dt = new DataTypeImpl(null, propType, genericPropType, XMLType.UNKNOWN);
+ property.setDataType(dt);
+ } else {
+ if (genericType instanceof ParameterizedType) {
+ // Collection<BaseType> property;
+ Type genericPropType = ((ParameterizedType)genericType).getActualTypeArguments()[0];
+ Class<?> propType = JavaIntrospectionHelper.getErasure(genericPropType);
+ DataType dt = new DataTypeImpl(null, propType, genericPropType, XMLType.UNKNOWN);
+ property.setDataType(dt);
+ } else {
+ // Collection property;
+ DataType dt = new DataTypeImpl(null, Object.class, Object.class, XMLType.UNKNOWN);
+ property.setDataType(dt);
+ }
}
} else {
- property.setXSDType(JavaXMLMapper.getXMLType(javaType));
+ DataType dt = new DataTypeImpl(null, javaClass, genericType, XMLType.UNKNOWN);
+ property.setDataType(dt);
}
return property;
-
}
protected abstract String getName(A annotation);
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
index 4bb775d17b..f5148fd38f 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
@@ -24,6 +24,7 @@ import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospe
import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.toPropertyName;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
@@ -55,8 +56,8 @@ import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
-import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
import org.oasisopen.sca.annotation.Callback;
+import org.oasisopen.sca.annotation.ComponentName;
import org.oasisopen.sca.annotation.Context;
import org.oasisopen.sca.annotation.Property;
import org.oasisopen.sca.annotation.Reference;
@@ -138,7 +139,19 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
throw new IntrospectionException(e);
}
}
+
+ private static boolean isAnnotatedWithSCA(AnnotatedElement element) {
+ for (Annotation a : element.getAnnotations()) {
+ if (isSCAAnnotation(a)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ private static boolean isSCAAnnotation(Annotation a) {
+ return a.annotationType().getName().startsWith("org.oasisopen.sca.annotation.");
+ }
private <T> void calcPropRefs(Set<Method> methods,
List<org.apache.tuscany.sca.assembly.Service> services,
@@ -152,7 +165,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
if (!isPublicSetter(method)) {
continue;
}
- if (method.isAnnotationPresent(Callback.class) || method.isAnnotationPresent(Context.class)) {
+ if (isAnnotatedWithSCA(method)) {
// Add the property name as others
others.add(toPropertyName(method.getName()));
continue;
@@ -169,7 +182,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
type.getReferences().add(createReference(name, param));
type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
} else {
- type.getProperties().add(createProperty(name, param));
+ type.getProperties().add(createProperty(name, param, genericType));
type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
}
}
@@ -180,12 +193,14 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
if (!isProtectedSetter(method)) {
continue;
}
- if (method.isAnnotationPresent(Callback.class) || method.isAnnotationPresent(Context.class)) {
+ if (isAnnotatedWithSCA(method)) {
// Add the property name as others
others.add(toPropertyName(method.getName()));
continue;
}
Class<?> param = method.getParameterTypes()[0];
+ Type paramType = method.getGenericParameterTypes()[0];
+
String name = toPropertyName(method.getName());
setters.add(name);
// avoid duplicate property or ref names
@@ -196,7 +211,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
} else {
if (!type.getPropertyMembers().containsKey(name)) {
- type.getProperties().add(createProperty(name, param));
+ type.getProperties().add(createProperty(name, param, paramType));
type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
}
}
@@ -207,7 +222,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
// for the same name
Set<Field> fields = getAllPublicAndProtectedFields(clazz, false);
for (Field field : fields) {
- if (field.isAnnotationPresent(Callback.class) || field.isAnnotationPresent(Context.class)) {
+ if (isAnnotatedWithSCA(field)) {
continue;
}
if (setters.contains(field.getName()) || others.contains(field.getName())) {
@@ -215,6 +230,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
String name = field.getName();
Class<?> paramType = field.getType();
+ Type genericType = field.getGenericType();
if (isReferenceType(paramType, field.getGenericType())) {
if (!type.getReferenceMembers().containsKey(name)) {
type.getReferences().add(createReference(name, paramType));
@@ -222,7 +238,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
}
} else {
if (!type.getPropertyMembers().containsKey(name)) {
- type.getProperties().add(createProperty(name, paramType));
+ type.getProperties().add(createProperty(name, paramType, genericType));
type.getPropertyMembers().put(name, new JavaElementImpl(field));
}
}
@@ -362,7 +378,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
p.setClassifer(Reference.class);
type.getReferenceMembers().put(name, p);
} else {
- type.getProperties().add(createProperty(name, p.getType()));
+ type.getProperties().add(createProperty(name, p.getType(), p.getGenericType()));
p.setClassifer(Property.class);
type.getPropertyMembers().put(name, p);
}
@@ -452,11 +468,8 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
* @param name the property name
* @param paramType the property type
*/
- private org.apache.tuscany.sca.assembly.Property createProperty(String name, Class<?> paramType) {
- org.apache.tuscany.sca.assembly.Property property = assemblyFactory.createProperty();
- property.setName(name);
- property.setXSDType(JavaXMLMapper.getXMLType(paramType));
- return property;
+ private org.apache.tuscany.sca.assembly.Property createProperty(String name, Class<?> javaClass, Type genericType) {
+ return AbstractPropertyProcessor.createProperty(assemblyFactory, name, javaClass, genericType);
}
private org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType)
@@ -582,6 +595,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
* The name of the reference or of the property is derived from the
* name found on the setter method or on the field.
*/
+ // FIXME: [rfeng] What if it's a collection of references?
private static boolean isReferenceType(Class<?> cls, Type genericType) {
Class<?> baseType = JavaIntrospectionHelper.getBaseType(cls, genericType);
return baseType.isInterface() && baseType.isAnnotationPresent(Remotable.class);
@@ -635,9 +649,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
*/
private static boolean isAnnotated(JavaParameterImpl parameter) {
for (Annotation annotation : parameter.getAnnotations()) {
- Class<? extends Annotation> annotType = annotation.annotationType();
- if (annotType.equals(Property.class) || annotType.equals(Reference.class)
- || annotType.equals(Resource.class)) {
+ if (isSCAAnnotation(annotation)) {
return true;
}
}
@@ -668,8 +680,11 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor {
for (Annotation[] annotations : annots) {
for (Annotation annotation : annotations) {
Class<? extends Annotation> annotType = annotation.annotationType();
- if (annotType.equals(Property.class) || annotType.equals(Reference.class)
- || annotType.equals(Resource.class)) {
+ if (annotType == Property.class || annotType == Reference.class
+ || annotType == Resource.class
+ || annotType == ComponentName.class
+ || annotType == Context.class
+ || annotType == Callback.class) {
return true;
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
index ede71a90dd..a850f86995 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
@@ -27,7 +27,6 @@ import java.util.Collection;
import java.util.List;
import javax.jws.WebService;
-import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
@@ -39,7 +38,6 @@ import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
-import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
import org.junit.Test;
import org.oasisopen.sca.annotation.Property;
import org.oasisopen.sca.annotation.Reference;
@@ -239,7 +237,7 @@ public class HeuristicPojoProcessorTestCase extends AbstractProcessorTest {
processor.visitEnd(PropertyIntTypeOnConstructor.class, type);
org.apache.tuscany.sca.assembly.Property foo = ModelHelper.getProperty(type, "foo");
assertEquals(int.class, type.getPropertyMembers().get("foo").getType());
- assertEquals(new QName(JavaXMLMapper.URI_2001_SCHEMA_XSD, "int"), foo.getXSDType());
+ // assertEquals(new QName(JavaXMLMapper.URI_2001_SCHEMA_XSD, "int"), foo.getXSDType());
}
/**