From 8699192185597c315eda4af2b318eabe5b2bad8b Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 30 Jul 2010 20:59:14 +0000 Subject: Allow spring beans to use @Reference without a property element git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980959 13f79535-47bb-0310-9956-ffa450edef68 --- .../introspect/SpringXMLComponentTypeLoader.java | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring') 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 ec44bc591a..5e83136629 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 @@ -32,9 +32,11 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.jar.Attributes; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -738,13 +740,16 @@ public class SpringXMLComponentTypeLoader { List beanReferences = beanComponentType.getReferences(); List beanProperties = beanComponentType.getProperties(); + Set excludedNames = new HashSet(); Iterator itp = beanElement.getProperties().iterator(); while (itp.hasNext()) { SpringPropertyElement propertyElement = itp.next(); + // Exclude the reference that is also known as a spring property + excludedNames.add(propertyElement.getName()); for (String propertyRef : propertyElement.getRefs()) { if (propertyRefUnresolved(propertyRef, beans, references, scaproperties)) { // This means an unresolved reference from the spring bean... - for (Reference reference : beanReferences) { + for (Reference reference: beanReferences) { if (propertyElement.getName().equals(reference.getName())) { // The name of the reference in this case is the string in // the @ref attribute of the Spring property element, NOT the @@ -784,11 +789,15 @@ public class SpringXMLComponentTypeLoader { // type attribute OR index attribute declared... if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) || (conArgElement .getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex()))) { - if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Reference")) { + // [rfeng] Commenting out the following code as the constructor parameter based SCA + // references are added already + /* + if (parameter.getClassifer() == org.oasisopen.sca.annotation.Reference.class) { Reference theReference = createReference(interfaze, constructorArgRef); componentType.getReferences().add(theReference); } - if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Property")) { + */ + if (parameter.getClassifer() == org.oasisopen.sca.annotation.Property.class) { // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type // we might need to verify with the component definition later. Reference theReference = createReference(interfaze, constructorArgRef); @@ -799,7 +808,15 @@ public class SpringXMLComponentTypeLoader { } // end if } // end for } // end while - + + // [rfeng] Add the remaining introspected references (w/ @Reference but without Spring property ref) + for (Reference ref : beanReferences) { + if (!excludedNames.contains(ref.getName()) && componentType.getReference(ref.getName()) == null) { + // Only add the ones that not listed by sca:reference + componentType.getReferences().add(ref); + } + } + } // end while } catch (ClassNotFoundException e) { -- cgit v1.2.3