summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 10:47:36 +0000
committerramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 10:47:36 +0000
commita6cb76239fe7e25565515fd6621ff82dc8c603f8 (patch)
treeed2e41be8e6c10b21c14f25e8cedc009e1f04fe6
parent1db9c0136867e3ed83097365bb7d80a368b4d11e (diff)
Fixes for TUSCANY-2941
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758591 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java13
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java38
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java11
-rw-r--r--branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java108
4 files changed, 59 insertions, 111 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java
index df85e4f302..5b6cfcab5b 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.sca.implementation.spring.xml;
+import java.util.List;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
@@ -26,21 +27,17 @@ 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.java.introspect.JavaClassVisitor;
-import org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;
-import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;
-import org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;
-import org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;
import org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.policy.PolicyFactory;
@@ -65,7 +62,8 @@ public class SpringBeanIntrospector {
*/
public SpringBeanIntrospector(AssemblyFactory assemblyFactory,
JavaInterfaceFactory javaFactory,
- PolicyFactory policyFactory) {
+ PolicyFactory policyFactory,
+ List<SpringConstructorArgElement> conArgs) {
javaImplementationFactory = new DefaultJavaImplementationFactory();
@@ -73,19 +71,16 @@ public class SpringBeanIntrospector {
BaseJavaClassVisitor[] extensions =
new BaseJavaClassVisitor[] {
new ConstructorProcessor(assemblyFactory),
- new AllowsPassByReferenceProcessor(assemblyFactory),
new ComponentNameProcessor(assemblyFactory),
new ContextProcessor(assemblyFactory),
- new ConversationProcessor(assemblyFactory),
new DestroyProcessor(assemblyFactory),
new EagerInitProcessor(assemblyFactory),
new InitProcessor(assemblyFactory),
new PropertyProcessor(assemblyFactory),
new ReferenceProcessor(assemblyFactory, javaFactory),
new ResourceProcessor(assemblyFactory),
- new ScopeProcessor(assemblyFactory),
new ServiceProcessor(assemblyFactory, javaFactory),
- new SpringBeanPojoProcessor(assemblyFactory, javaFactory),
+ new SpringBeanPojoProcessor(assemblyFactory, javaFactory, conArgs),
new PolicyProcessor(assemblyFactory, policyFactory)};
for (JavaClassVisitor extension : extensions) {
javaImplementationFactory.addClassVisitor(extension);
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java
index 0510a6d338..fe632190ee 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java
@@ -81,10 +81,12 @@ import org.apache.tuscany.sca.implementation.java.introspect.impl.Resource;
*/
public class SpringBeanPojoProcessor extends BaseJavaClassVisitor {
private JavaInterfaceFactory javaFactory;
+ private List<SpringConstructorArgElement> conArgs;
- public SpringBeanPojoProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) {
+ public SpringBeanPojoProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory, List<SpringConstructorArgElement> conArgs) {
super(assemblyFactory);
this.javaFactory = javaFactory;
+ this.conArgs = conArgs;
}
@Override
@@ -280,6 +282,8 @@ public class SpringBeanPojoProcessor extends BaseJavaClassVisitor {
private <T> void evaluateConstructor(JavaImplementation type, Class<T> clazz) throws IntrospectionException {
// determine constructor if one is not annotated
JavaConstructorImpl<?> definition = type.getConstructor();
+ Map<String, JavaElementImpl> props = type.getPropertyMembers();
+ Map<String, JavaElementImpl> refs = type.getReferenceMembers();
Constructor constructor;
boolean explict = false;
if (definition != null && definition.getConstructor()
@@ -298,37 +302,41 @@ public class SpringBeanPojoProcessor extends BaseJavaClassVisitor {
// Only one constructor, take it
constructor = constructors[0];
} else {
- // FIXME multiple constructors, none yet done
- Constructor<T> selected = null;
- int sites = type.getPropertyMembers().size() + type.getReferenceMembers().size();
+ // multiple constructors scenario
+ Constructor<T> selected = null;
for (Constructor<T> ctor : constructors) {
if (ctor.getParameterTypes().length == 0) {
selected = ctor;
- }
- if (ctor.getParameterTypes().length == sites) {
- // TODO finish
- // selected = constructor;
- // select constructor
- // break;
+ } else if (ctor.getParameterTypes().length == conArgs.size()) {
+ // we will find a constructor which has atleast one
+ // reference or property as its parameter types.
+ Class<?>[] parametersTypes = ctor.getParameterTypes();
+ for (Class<?> pType: parametersTypes) {
+ for (JavaElementImpl property : props.values()) {
+ if (pType.equals(property.getType()))
+ selected = ctor;
+ }
+ for (JavaElementImpl reference : refs.values()) {
+ if (pType.equals(reference.getType()))
+ selected = ctor;
+ }
+ }
}
}
if (selected == null) {
throw new NoConstructorException();
}
constructor = selected;
- definition = type.getConstructors().get(selected);
- type.setConstructor(definition);
- // return;
}
definition = type.getConstructors().get(constructor);
type.setConstructor(definition);
}
+
JavaParameterImpl[] parameters = definition.getParameters();
if (parameters.length == 0) {
return;
}
- Map<String, JavaElementImpl> props = type.getPropertyMembers();
- Map<String, JavaElementImpl> refs = type.getReferenceMembers();
+
Annotation[][] annotations = constructor.getParameterAnnotations();
if (!explict) {
// the constructor wasn't defined by an annotation, so check to see
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java
index ce83baee05..553b3d33dd 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringConstructorArgElement.java
@@ -31,7 +31,8 @@ public class SpringConstructorArgElement {
private String ref;
private String type;
- private int index;
+ private int autoIndex = -1;
+ private int index = -1;
private List<String> values = new ArrayList<String>();
public SpringConstructorArgElement(String ref, String type) {
@@ -59,6 +60,14 @@ public class SpringConstructorArgElement {
this.index = index;
}
+ public int getAutoIndex() {
+ return this.autoIndex;
+ }
+
+ public void setAutoIndex(int index) {
+ this.autoIndex = index;
+ }
+
public List<String> getValues() {
return this.values;
}
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
index 0100bb8fc5..ef42e8c610 100644
--- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
+++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
@@ -72,6 +72,7 @@ public class SpringXMLComponentTypeLoader {
private AssemblyFactory assemblyFactory;
private JavaInterfaceFactory javaFactory;
+ private PolicyFactory policyFactory;
private ClassLoader cl;
private SpringBeanIntrospector beanIntrospector;
@@ -83,8 +84,7 @@ public class SpringXMLComponentTypeLoader {
super();
this.assemblyFactory = assemblyFactory;
this.javaFactory = javaFactory;
- beanIntrospector =
- new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory);
+ this.policyFactory = policyFactory;
}
protected Class<SpringImplementation> getImplementationClass() {
@@ -260,6 +260,7 @@ public class SpringXMLComponentTypeLoader {
SpringBeanElement innerbean = null;
SpringPropertyElement property = null;
SpringConstructorArgElement constructorArg = null;
+ int autoConstructorIndex = -1;
try {
boolean completed = false;
@@ -280,6 +281,8 @@ public class SpringXMLComponentTypeLoader {
} else if (Constants.CONSTRUCTORARG_ELEMENT.equals(qname)) {
constructorArg = new SpringConstructorArgElement(reader.getAttributeValue(null, "ref"),
reader.getAttributeValue(null, "type"));
+ autoConstructorIndex++;
+ constructorArg.setAutoIndex(autoConstructorIndex);
if (reader.getAttributeValue(null, "index") != null)
constructorArg.setIndex((new Integer(reader.getAttributeValue(null, "index"))).intValue());
if (reader.getAttributeValue(null, "value") != null) {
@@ -413,7 +416,9 @@ public class SpringXMLComponentTypeLoader {
if (beanElement.isInnerBean()) continue;
// Load the Spring bean class
Class<?> beanClass = cl.loadClass(beanElement.getClassName());
- // Introspect the bean
+ // Introspect the bean
+ beanIntrospector =
+ new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs());
ComponentType beanComponentType = assemblyFactory.createComponentType();
javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
// Get the service interface defined by this Spring Bean and add to
@@ -435,7 +440,9 @@ public class SpringXMLComponentTypeLoader {
continue;
Class<?> beanClass = cl.loadClass(beanElement.getClassName());
- // Introspect the bean
+ // Introspect the bean
+ beanIntrospector =
+ new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs());
ComponentType beanComponentType = assemblyFactory.createComponentType();
javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
Map<String, JavaElementImpl> propertyMap = javaImplementation.getPropertyMembers();
@@ -482,98 +489,27 @@ public class SpringXMLComponentTypeLoader {
String paramType = parameter.getType().getName();
Class<?> interfaze = cl.loadClass(paramType);
// Create a component type reference/property if the constructor-arg element has a
- // type attribute declared...
- if (conArgElement.getType() != null && paramType.equals(conArgElement.getType())) {
+ // type attribute OR index attribute declared...
+ if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) ||
+ (conArgElement.getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex())) ||
+ (conArgElement.getAutoIndex() == parameter.getIndex()))
+ {
if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Reference")) {
Reference theReference = createReference(interfaze, conArgElement.getRef());
componentType.getReferences().add(theReference);
}
if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Property")) {
- Property theProperty = assemblyFactory.createProperty();
- theProperty.setName(conArgElement.getRef());
- theProperty.setXSDType(JavaXMLMapper.getXMLType(interfaze));
- componentType.getProperties().add(theProperty);
- // Remember the Java Class (ie the type) for this property
- implementation.setPropertyClass(theProperty.getName(), interfaze);
+ // 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, conArgElement.getRef());
+ implementation.setUnresolvedBeanRef(conArgElement.getRef(), theReference);
}
- }
-
- // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
- // if the type attribute is absent in the contructor-arg element...
- if (conArgElement.getType() == null) {
- Reference theReference = createReference(interfaze, conArgElement.getRef());
- implementation.setUnresolvedBeanRef(conArgElement.getRef(), theReference);
- }
- } // end for
+ }
+ } // end for
} // end if
} // end while
} // end while
-
-
- // Now check to see if there are any more references from beans that are not satisfied
- /*itb = beans.iterator();
- while (itb.hasNext()) {
- SpringBeanElement beanElement = itb.next();
- boolean unresolvedProperties = false;
- if (!beanElement.getProperties().isEmpty()) {
- // Scan through the properties
- Iterator<SpringPropertyElement> itp = beanElement.getProperties().iterator();
- while (itp.hasNext()) {
- SpringPropertyElement propertyElement = itp.next();
- if (propertyRefUnresolved(propertyElement.getRef(), beans, references, scaproperties)) {
- // This means an unresolved reference from the spring bean...
- unresolvedProperties = true;
- } // end if
- } // end while
- // If there are unresolved properties, then find which ones are references
- if (unresolvedProperties) {
- Class<?> beanClass = cl.loadClass(beanElement.getClassName());
- // Introspect the bean
- ComponentType beanComponentType = assemblyFactory.createComponentType();
- javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
- Map<String, JavaElementImpl> propertyMap = javaImplementation.getPropertyMembers();
- // Get the references by this Spring Bean and add the unresolved ones to
- // the component type of the Spring Assembly
- List<Reference> beanReferences = beanComponentType.getReferences();
- List<Property> beanProperties = beanComponentType.getProperties();
- itp = beanElement.getProperties().iterator();
- while (itp.hasNext()) {
- SpringPropertyElement propertyElement = itp.next();
- if (propertyRefUnresolved(propertyElement.getRef(), beans, references, scaproperties)) {
- boolean resolved = false;
- // This means an unresolved reference from the spring bean...add it to
- // the references for the Spring application context
- 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
- // name of the field in the Spring bean....
- reference.setName(propertyElement.getRef());
- componentType.getReferences().add(reference);
- resolved = true;
- } // end if
- } // end for
- if (!resolved) {
- // If the bean property is not already resolved as a reference
- // then it may be an SCA reference OR a SCA property, it really depends
- // on how the SCDL has defined references and properties for this component.
- // So lets assume all unresolved bean properties as references.
- for (Property scaproperty : beanProperties) {
- if (propertyElement.getName().equals(scaproperty.getName())) {
- Class<?> interfaze = cl.loadClass((propertyMap.get(propertyElement.getName()).getType()).getName());
- Reference theReference = createReference(interfaze, propertyElement.getRef());
- implementation.setUnresolvedBeanRef(propertyElement.getRef(), theReference);
- resolved = true;
- }
- }
-
- } // end if
- } // end if
- } // end while
- } // end if
- } // end if
- } // end while*/
} catch (ClassNotFoundException e) {
// Means that either an interface class, property class or a bean was not found