diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-12-14 13:08:30 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-12-14 13:08:30 +0000 |
commit | c22ac2250370b95585d5b6c99a7f3eef1c2caede (patch) | |
tree | 5f0f79b1fc6e78474bdd41a10968b2c7d17728c1 /sca-java-2.x | |
parent | 6fb07f5e88595ed886b6636895ead5a0603a45fa (diff) |
TUSCANY-2681 - merge changes from 1.x to 2.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1214229 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
2 files changed, 69 insertions, 9 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java index de489c953a..d3b813f7aa 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java @@ -202,9 +202,7 @@ public class JavaInterfaceIntrospectorImpl { String ns) throws InvalidInterfaceException { Set<Type> genericInterfaces = new HashSet<Type>(); - for (Type t : clazz.getGenericInterfaces()) { - genericInterfaces.add(t); - } + collectGenericInterfaces(clazz, genericInterfaces); Map<String, Type> typeBindings = new HashMap<String, Type>(); for (Type genericInterface : genericInterfaces) { if (genericInterface instanceof ParameterizedType) { @@ -428,4 +426,14 @@ public class JavaInterfaceIntrospectorImpl { return null; } + private void collectGenericInterfaces(Class<?> clazz, Set<Type> genericInterfaces) { + for (Type t : clazz.getGenericInterfaces()) { + genericInterfaces.add(t); + } + Class<?>[] interfaces = clazz.getInterfaces(); + for(Class<?> c : interfaces){ + collectGenericInterfaces(c, genericInterfaces); + } + } + } diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java index ed56002044..9e85cf0e61 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java @@ -19,7 +19,9 @@ package org.apache.tuscany.sca.interfacedef.java.impl; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -166,12 +168,8 @@ public final class JavaInterfaceUtil { List<DataType> types = inputType.getLogical(); Class<?>[] javaTypes = new Class<?>[types.size()]; for (int i = 0; i < javaTypes.length; i++) { - Type physical = types.get(i).getPhysical(); - if (physical instanceof Class<?>) { - javaTypes[i] = (Class<?>)physical; - } else { - throw new UnsupportedOperationException(); - } + DataType<?> type = types.get(i); + javaTypes[i] = getClassOfDataType(type); } return javaTypes; } @@ -241,4 +239,58 @@ public final class JavaInterfaceUtil { return ns.toString(); } + /** + * Get the Java Type that represent the DataType informed + * When dataType.getGenericType() is GenericArrayType or WildcardType the Physical type is used, + * because the physical type have the correct information about this DataType. + * @param dataType DataType + * @return The Class<?> that represent the DataType + */ + private static Class<?> getClassOfDataType(DataType<?> dataType){ + Type generic = dataType.getGenericType(); + boolean isGeneric = (generic != null + && generic != dataType.getPhysical() + && (generic instanceof TypeVariable<?> + || generic instanceof ParameterizedType)); + Class<?> javaType = null; + if (isGeneric) { + javaType = getClassOfSimpleGeneric(generic); + }else { + Type physical = dataType.getPhysical(); + javaType = getClassOfPhysical(physical); + } + if (javaType == null) { + throw new UnsupportedOperationException(); + } + return javaType; + } + + /** + * Return Class<?> of Type Generic informed + * @param generic The Generic Type + * @return The Class<?> that represent the Generic + */ + private static Class<?> getClassOfSimpleGeneric(Type generic){ + Class<?> javaType = null; + if (generic instanceof TypeVariable<?>){ + javaType = (Class<?>)Object.class; + } else if (generic instanceof ParameterizedType){ + javaType = (Class<?>)((ParameterizedType)generic).getRawType(); + } + return javaType; + } + + /** + * Return Class<?> of Type Physical informed + * @param physical The Physical + * @return The Class<?> that represent the Physical + */ + private static Class<?> getClassOfPhysical(Type physical){ + Class<?> javaType = null; + if (physical instanceof Class<?>) { + javaType = (Class<?>)physical; + } + return javaType; + } + } |