summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2008-12-09 09:34:36 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2008-12-09 09:34:36 +0000
commit3787e390b4067e5c2d354026caba525e8209966e (patch)
tree29191f413c0c42b304910f8445fe4c8e82747d06
parenta41b534e0527ac6280bb09bba778463d30b83f49 (diff)
Merge TUSCANY-2681 fix from 1.x to 1.4 to Apply fix from Rodolfo Dias to fix When a Component class implements an interfaces that extends other interface and use generics occur the error
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@724648 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java14
-rw-r--r--branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java64
2 files changed, 69 insertions, 9 deletions
diff --git a/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
index b1198824fa..126b435989 100644
--- a/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
+++ b/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
@@ -142,15 +142,23 @@ public class JavaInterfaceIntrospectorImpl {
return rawType;
}
+ 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);
+ }
+ }
+
private <T> List<Operation> getOperations(Class<T> clazz,
boolean remotable,
boolean conversational,
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) {
diff --git a/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java b/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
index 2a9e3c5329..2782ffd8db 100644
--- a/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
+++ b/branches/sca-java-1.4/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;
@@ -96,15 +98,65 @@ 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;
}
+
+ /**
+ * 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;
+ }
/**
* Searches a collection of operations for a match against the given method