You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2010/07/28 18:26:16 UTC

svn commit: r980115 - /tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java

Author: edwardsmj
Date: Wed Jul 28 16:26:16 2010
New Revision: 980115

URL: http://svn.apache.org/viewvc?rev=980115&view=rev
Log:
Changes to ensure correct introspection of implicit reference setter methods and public fields, as defined in section 8.1 of the OASIS Java POJO specification, detailed in TUSCANY-3636

Modified:
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java?rev=980115&r1=980114&r2=980115&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java Wed Jul 28 16:26:16 2010
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.implement
 import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.getAllInterfaces;
 import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.getAllPublicAndProtectedFields;
 import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.getAllUniquePublicProtectedMethods;
+import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.getBaseType;
 import static org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper.toPropertyName;
 
 import java.lang.annotation.Annotation;
@@ -56,6 +57,7 @@ import org.apache.tuscany.sca.interfaced
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.oasisopen.sca.ServiceReference;
 import org.oasisopen.sca.annotation.Callback;
 import org.oasisopen.sca.annotation.ComponentName;
 import org.oasisopen.sca.annotation.Context;
@@ -179,7 +181,7 @@ public class HeuristicPojoProcessor exte
                     Class<?> param = method.getParameterTypes()[0];
                     Type genericType = method.getGenericParameterTypes()[0];
                     if (isReferenceType(param, genericType)) {
-                        type.getReferences().add(createReference(name, param));
+                        type.getReferences().add(createReference(name, param, genericType));
                         type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
                     } else {
                         type.getProperties().add(createProperty(name, param, genericType));
@@ -206,7 +208,7 @@ public class HeuristicPojoProcessor exte
             // avoid duplicate property or ref names
             if (isReferenceType(param, method.getGenericParameterTypes()[0])) {
                 if (!type.getReferenceMembers().containsKey(name)) {
-                    type.getReferences().add(createReference(name, param));
+                    type.getReferences().add(createReference(name, param, paramType));
                     type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
                 }
             } else {
@@ -233,7 +235,7 @@ public class HeuristicPojoProcessor exte
             Type genericType = field.getGenericType();
             if (isReferenceType(paramType, field.getGenericType())) {
                 if (!type.getReferenceMembers().containsKey(name)) {
-                    type.getReferences().add(createReference(name, paramType));
+                    type.getReferences().add(createReference(name, paramType, genericType));
                     type.getReferenceMembers().put(name, new JavaElementImpl(field));
                 }
             } else {
@@ -374,7 +376,7 @@ public class HeuristicPojoProcessor exte
         for (JavaParameterImpl p : parameters) {
             String name = p.getType().getSimpleName().toLowerCase();
             if (isReferenceType(p.getType(), p.getGenericType())) {
-                type.getReferences().add(createReference(name, p.getType()));
+                type.getReferences().add(createReference(name, p.getType(), p.getGenericType()));
                 p.setClassifer(Reference.class);
                 type.getReferenceMembers().put(name, p);
             } else {
@@ -472,23 +474,40 @@ public class HeuristicPojoProcessor exte
         return AbstractPropertyProcessor.createProperty(assemblyFactory, name, javaClass, genericType);
     }
 
-     private org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType)
+     private org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType,
+    		                                                           Type genericType )
         throws IntrospectionException {
         org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
         reference.setName(name);
         JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
         reference.setInterfaceContract(interfaceContract);
+        // Compute the interface type dealing with array/Collection types and with Generic types
+        Class<?> baseType = getBaseType(paramType, genericType);
+        if (ServiceReference.class.isAssignableFrom(baseType)) {
+            if (Collection.class.isAssignableFrom(paramType)) {
+                genericType = JavaIntrospectionHelper.getParameterType(genericType);
+            }
+            baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, genericType);
+        } // end if
         try {
-            JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(paramType);
+            JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(baseType);
+
             reference.getInterfaceContract().setInterface(callInterface);
             if (callInterface.getCallbackClass() != null) {
                 JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass());
                 reference.getInterfaceContract().setCallbackInterface(callbackInterface);
             }
-            reference.setMultiplicity(Multiplicity.ZERO_ONE);
+            // Multiplicity of an implicit reference is 1..1 for a simple interface type
+            // and 1..n for an array of interface or Collection of interface type
+            // as defined in the OASIS SCA Java POJO specification, section 8.1 : TUSCANY-3636
+            if( isCollectionType( paramType ) || isArrayType( paramType )) {
+            	reference.setMultiplicity(Multiplicity.ONE_N);
+            } else {
+            	reference.setMultiplicity(Multiplicity.ONE_ONE);
+            } // end if 
         } catch (InvalidInterfaceException e1) {
             throw new IntrospectionException(e1);
-        }
+        } // end try
 
         // FIXME:  This part seems to have already been taken care above!!
         try {
@@ -498,6 +517,26 @@ public class HeuristicPojoProcessor exte
         }
         return reference;
     }
+     
+    /**
+     * Reports if a parameter type is a form of java.util.Collection 
+     * @param paramType
+     * @return true if paramType is a form of java.util.Collection, false otherwise
+     */
+    private boolean isCollectionType( Class<?> paramType ) {
+    	if( Collection.class.isAssignableFrom(paramType) ) return true;
+    	return false;
+    }
+    
+    /**
+     * Reports if a parameter type is an array
+     * @param paramType
+     * @return true if paramType is an array
+     */
+    private boolean isArrayType( Class<?> paramType ) {
+    	if( paramType.isArray() ) return true;
+    	return false;
+    }
 
     private org.apache.tuscany.sca.assembly.Service createService(Class<?> interfaze) throws InvalidInterfaceException {
         org.apache.tuscany.sca.assembly.Service service = assemblyFactory.createService();