diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding')
2 files changed, 30 insertions, 5 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java index 0003e7d46f..ef46a2b3c7 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java @@ -19,8 +19,10 @@ package org.apache.tuscany.sca.databinding.sdo; +import java.lang.reflect.ParameterizedType; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Collection; import javax.xml.namespace.QName; @@ -62,7 +64,7 @@ public class SDODataBinding extends BaseDataBinding { @Override public boolean introspect(DataType dataType, final Operation operation) { - final Class javaType = dataType.getPhysical(); + Class javaType = dataType.getPhysical(); // Allow privileged access to read system properties. Requires PropertyPermission // java.specification.version read in security policy. final HelperContext context = AccessController.doPrivileged(new PrivilegedAction<HelperContext>() { @@ -74,11 +76,33 @@ public class SDODataBinding extends BaseDataBinding { final Type type = context.getTypeHelper().getType(javaType); if (type == null) { // FIXME: Need a better to test dynamic SDO + // TUSCANY-3298: get underlying element type for collections + boolean isMany = false; + if (Collection.class.isAssignableFrom(javaType)) { + java.lang.reflect.Type genericType = dataType.getGenericType(); + if (genericType instanceof ParameterizedType) { + java.lang.reflect.Type actualType = ((ParameterizedType)genericType).getActualTypeArguments()[0]; + if (actualType instanceof Class) { + javaType = (Class)actualType; + isMany = true; + } + } + } if (DataObject.class.isAssignableFrom(javaType)) { // Dynamic SDO dataType.setDataBinding(getName()); - if (dataType.getLogical() == null) { - dataType.setLogical(XMLType.UNKNOWN); + // TUSCANY-3298: use XMLType many value to indicate a collection + Object logical = dataType.getLogical(); + if (logical == null) { + if (!isMany) { + dataType.setLogical(XMLType.UNKNOWN); + } else { + XMLType xmlType = new XMLType(null, null); + xmlType.setMany(true); + dataType.setLogical(xmlType); + } + } else if (logical instanceof XMLType && isMany) { + ((XMLType)logical).setMany(true); } return true; } diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java index dc1b3fc4fa..4c2075fcc4 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.XMLTypeHelper; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; @@ -91,8 +92,8 @@ public class SDOTypeHelper implements XMLTypeHelper { xmlType = ((XMLType)logical).getTypeName(); } if (xmlType == null) { - xmlType = - new QName(JavaXMLMapper.getNamespace(javaType), Introspector.decapitalize(javaType.getSimpleName())); + // TUSCANY-3298: dynamic SDO or collection of dynamic SDO + return new TypeInfo(SimpleTypeMapperImpl.XSD_ANYTYPE, true, null); } return new TypeInfo(xmlType, false, null); } |