You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/08/06 19:01:53 UTC

svn commit: r983054 - in /tuscany/sca-java-2.x/trunk/modules: assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/ implementation-java/src/main/java/org/apache/tuscan...

Author: rfeng
Date: Fri Aug  6 17:01:52 2010
New Revision: 983054

URL: http://svn.apache.org/viewvc?rev=983054&view=rev
Log:
Allow HeuristicPojoProcessor to differentiate implementation.java against other java based implementation types such as implementation.spring
Check for duplicate import in spring xml definitions

Modified:
    tuscany/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java

Modified: tuscany/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java?rev=983054&r1=983053&r2=983054&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java Fri Aug  6 17:01:52 2010
@@ -36,9 +36,9 @@ import org.apache.tuscany.sca.policy.Pol
  * @tuscany.spi.extension.inheritfrom
  */
 public abstract class ImplementationImpl extends ComponentTypeImpl implements Implementation, PolicySubject {
-    private QName type;
-    private ExtensionType extensionType;
-    private List<Operation> operations = new ArrayList<Operation>();
+    protected QName type;
+    protected ExtensionType extensionType;
+    protected List<Operation> operations = new ArrayList<Operation>();
 
     protected ImplementationImpl(QName type) {
         super();

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.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/BaseJavaImplementation.java?rev=983054&r1=983053&r2=983054&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java Fri Aug  6 17:01:52 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.sca.implementation.java;
 
+import javax.xml.namespace.QName;
+
 import org.apache.tuscany.sca.assembly.Extensible;
 import org.apache.tuscany.sca.assembly.Implementation;
 
@@ -55,5 +57,12 @@ public interface BaseJavaImplementation 
      * @param javaClass the Java implementation class
      */
     void setJavaClass(Class<?> javaClass);
+    
+    /**
+     * Customize the implementation type so that components are implemented using Java based framework such as
+     * implementation.spring or implementation.jaxrs can leverage the introspection
+     * @param type
+     */
+    void setType(QName type);
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.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/impl/BaseJavaImplementationImpl.java?rev=983054&r1=983053&r2=983054&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java Fri Aug  6 17:01:52 2010
@@ -89,4 +89,9 @@ abstract class BaseJavaImplementationImp
             return false;
         }
     }
+
+    @Override
+    public void setType(QName type) {
+       this.type = type;
+    }
 }

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=983054&r1=983053&r2=983054&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 Fri Aug  6 17:01:52 2010
@@ -133,6 +133,11 @@ public class HeuristicPojoProcessor exte
         evaluateConstructor(type, clazz);
     }
 
+    // Check if the implementation is implementation.java
+    private boolean isImplementationJava(JavaImplementation type) {
+        return JavaImplementation.TYPE.equals(type.getType());
+    }
+
     private void addService(JavaImplementation type, Class<?> clazz) throws IntrospectionException {
         try {
             org.apache.tuscany.sca.assembly.Service service = createService(clazz);
@@ -287,6 +292,10 @@ public class HeuristicPojoProcessor exte
             explict = true;
             constructor = definition.getConstructor();
         } else {
+            if (!isImplementationJava(type)) {
+                // FIXME: [rfeng] Don't process the constructors for non implementation.java types
+                return;
+            }
             // no definition, heuristically determine constructor
             Constructor[] constructors = clazz.getConstructors();
             if (constructors.length == 0) {

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java?rev=983054&r1=983053&r2=983054&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java Fri Aug  6 17:01:52 2010
@@ -28,6 +28,7 @@ import org.apache.tuscany.sca.implementa
 import org.apache.tuscany.sca.implementation.java.JavaImplementation;
 import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
 import org.apache.tuscany.sca.implementation.spring.SpringConstructorArgElement;
+import org.apache.tuscany.sca.implementation.spring.SpringImplementation;
 
 /**
  * Provides introspection functions for Spring beans
@@ -70,6 +71,8 @@ public class SpringBeanIntrospector {
 
         // Create a Java implementation ready for the introspection
         JavaImplementation javaImplementation = javaImplementationFactory.createJavaImplementation();
+        // Set the type to be implementation.spring to avoid heuristic introspection
+        javaImplementation.setType(SpringImplementation.TYPE);
 
         try {
             // Introspect the bean...the results of the introspection are placed into the Java implementation

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java?rev=983054&r1=983053&r2=983054&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java Fri Aug  6 17:01:52 2010
@@ -208,9 +208,11 @@ public class SpringXMLComponentTypeLoade
                 List<SpringSCAPropertyElement> appCxtProperties = new ArrayList<SpringSCAPropertyElement>();
                 reader = xmlInputFactory.createXMLStreamReader(contextResource.openStream());
                 // Read the beans, services, references and properties for individual application context
+                Set<String> visited = new HashSet<String>();
                 readContextDefinition(resolver,
                                       reader,
                                       contextPath,
+                                      visited,
                                       appCxtBeans,
                                       appCxtServices,
                                       appCxtReferences,
@@ -295,12 +297,18 @@ public class SpringXMLComponentTypeLoade
     private void readContextDefinition(ModelResolver resolver,
                                        XMLStreamReader reader,
                                        String contextPath,
+                                       Set<String> visited,
                                        List<SpringBeanElement> beans,
                                        List<SpringSCAServiceElement> services,
                                        List<SpringSCAReferenceElement> references,
                                        List<SpringSCAPropertyElement> scaproperties,
                                        ProcessorContext context) throws ContributionReadException {
 
+        if (visited.contains(contextPath)) {
+            log.warning("Duplicate Spring bean definition file is skipped: " + contextPath);
+            return;
+        }
+        visited.add(contextPath);
         SpringBeanElement bean = null;
 
         try {
@@ -320,6 +328,7 @@ public class SpringXMLComponentTypeLoade
                                 XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath, context);
                                 // Read the context definition for the identified imported resource
                                 readContextDefinition(resolver, ireader, resourcePath, // The new context path
+                                                      visited,
                                                       beans,
                                                       services,
                                                       references,
@@ -757,8 +766,10 @@ public class SpringXMLComponentTypeLoade
                                     // name of the field in the Spring bean....
                                     reference.setName(propertyRef);
                                     componentType.getReferences().add(reference);
+                                    break;
                                 } // end if
                             } // end for
+                            
 
                             // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
                             for (Property scaproperty : beanProperties) {
@@ -772,6 +783,7 @@ public class SpringXMLComponentTypeLoade
                                                      context);
                                     Reference theReference = createReference(interfaze, propertyRef);
                                     implementation.setUnresolvedBeanRef(propertyRef, theReference);
+                                    break;
                                 } // end if
                             } // end for
                         } // end if