tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r724302 - in /tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl: JavaInterfaceIntrospectorImpl.java JavaInterfaceUtil.java
Date Mon, 08 Dec 2008 10:23:05 GMT
Author: antelder
Date: Mon Dec  8 02:23:04 2008
New Revision: 724302

URL: http://svn.apache.org/viewvc?rev=724302&view=rev
Log:
TUSCANY-2681: 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.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
    tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java

Modified: tuscany/branches/sca-java-1.x/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.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?rev=724302&r1=724301&r2=724302&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
(original)
+++ tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
Mon Dec  8 02:23:04 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.x/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.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java?rev=724302&r1=724301&r2=724302&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
(original)
+++ tuscany/branches/sca-java-1.x/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
Mon Dec  8 02:23:04 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



Mime
View raw message