You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2008/12/09 10:34:36 UTC

svn commit: r724648 - in /tuscany/branches/sca-java-1.4/modules/interface-java: ./ src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/

Author: antelder
Date: Tue Dec  9 01:34:36 2008
New Revision: 724648

URL: http://svn.apache.org/viewvc?rev=724648&view=rev
Log:
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

Modified:
    tuscany/branches/sca-java-1.4/modules/interface-java/   (props changed)
    tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
    tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java

Propchange: tuscany/branches/sca-java-1.4/modules/interface-java/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Dec  9 01:34:36 2008
@@ -0,0 +1,2 @@
+/tuscany/branches/sca-java-1.3/modules/interface-java:671193
+/tuscany/branches/sca-java-1.x/modules/interface-java:724111-724120,724302

Modified: tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?rev=724648&r1=724647&r2=724648&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java (original)
+++ tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java Tue Dec  9 01:34:36 2008
@@ -142,15 +142,23 @@
         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) {

Modified: tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java?rev=724648&r1=724647&r2=724648&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java (original)
+++ tuscany/branches/sca-java-1.4/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java Tue Dec  9 01:34:36 2008
@@ -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 @@
         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