diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-26 10:47:36 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-26 10:47:36 +0000 |
commit | a6cb76239fe7e25565515fd6621ff82dc8c603f8 (patch) | |
tree | ed2e41be8e6c10b21c14f25e8cedc009e1f04fe6 /branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java | |
parent | 1db9c0136867e3ed83097365bb7d80a368b4d11e (diff) |
Fixes for TUSCANY-2941
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758591 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanPojoProcessor.java | 38 |
1 files changed, 23 insertions, 15 deletions
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
|