diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-06 17:01:52 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-06 17:01:52 +0000 |
commit | b4444cd5c30014125df44e54a317e38474446cbd (patch) | |
tree | 10abc167eb58c25e53cac3e8fd1dde7da514d736 /sca-java-2.x/trunk | |
parent | 34d2607ebd63b775f4a2aba06b66bec2f94babb7 (diff) |
Allow HeuristicPojoProcessor to differentiate implementation.java against other java based implementation types such as implementation.spring
Check for duplicate import in spring xml definitions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@983054 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
6 files changed, 41 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java index 677e86c759..f943438a9f 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java @@ -36,9 +36,9 @@ import org.apache.tuscany.sca.policy.PolicySubject; * @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(); diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java index c8b7c072ac..a3b0343d51 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java @@ -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 extends Implementation, Extensible { * @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); } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java index 0d9187c14f..7cbb4d7a0c 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java @@ -89,4 +89,9 @@ abstract class BaseJavaImplementationImpl extends ImplementationImpl implements return false; } } + + @Override + public void setType(QName type) { + this.type = type; + } } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java index 16d8f4e67e..31cee72aa4 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java @@ -133,6 +133,11 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor { 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 extends BaseJavaClassVisitor { 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) { diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java index 0d446a9fa7..f163a75581 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringBeanIntrospector.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.implementation.java.IntrospectionException; 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 diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java index c8cc4360e3..51b5852407 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java @@ -208,9 +208,11 @@ public class SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { // 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 SpringXMLComponentTypeLoader { context); Reference theReference = createReference(interfaze, propertyRef); implementation.setUnresolvedBeanRef(propertyRef, theReference); + break; } // end if } // end for } // end if |