From 9016bc13af1401d89cc3940741b28c941cac796d Mon Sep 17 00:00:00 2001 From: antelder Date: Wed, 23 Feb 2011 12:42:38 +0000 Subject: Handle the case where the sca service type attribute is not specified. I'm going to raise a spec querry about the bean improspection rules in this situation git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1073721 13f79535-47bb-0310-9956-ffa450edef68 --- .../introspect/SpringXMLComponentTypeLoader.java | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'sca-java-2.x/trunk/modules/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 4fbe5da43d..49d458ce1f 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 @@ -49,6 +49,7 @@ import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.common.java.reflection.JavaIntrospectionHelper; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; @@ -81,6 +82,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySet; +import org.oasisopen.sca.annotation.Remotable; /** * Introspects a Spring XML application-context configuration file to create @@ -99,6 +101,8 @@ public class SpringXMLComponentTypeLoader { private SpringBeanIntrospector beanIntrospector; private SpringXMLBeanDefinitionLoader xmlBeanDefinitionLoader; + + private JavaIntrospectionHelper javaIntrospectionHelper; public SpringXMLComponentTypeLoader(ExtensionPointRegistry registry) { super(); @@ -110,6 +114,7 @@ public class SpringXMLComponentTypeLoader { this.contributionFactory = factories.getFactory(ContributionFactory.class); this.xmlBeanDefinitionLoader = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(SpringXMLBeanDefinitionLoader.class); + this.javaIntrospectionHelper = JavaIntrospectionHelper.getInstance(registry); } /** @@ -340,7 +345,14 @@ public class SpringXMLComponentTypeLoader { Iterator its = services.iterator(); while (its.hasNext()) { SpringSCAServiceElement serviceElement = its.next(); - Class interfaze = resolveClass(resolver, serviceElement.getType(), context); + + Class interfaze; + if (serviceElement.getType() != null) { + interfaze = resolveClass(resolver, serviceElement.getType(), context); + } else { + interfaze = getBeanInterface(resolver, serviceElement.getTarget(), beans, context); + } + Service theService = createService(interfaze, serviceElement.getName()); // Spring allows duplication of bean definitions in multiple context scenario, // in such cases, the latest bean definition overrides the older ones, hence @@ -594,7 +606,31 @@ public class SpringXMLComponentTypeLoader { return; } // end method generateComponentType - /* + private Class getBeanInterface(ModelResolver resolver, String target, List beans, ProcessorContext context) throws ClassNotFoundException { + SpringBeanElement bean = null; + for (SpringBeanElement sbe : beans) { + if (sbe.getId().equals(target)) { + bean = sbe; + break; + } + } + if (bean == null) { + error(context.getMonitor(), "TargetBeanDoesNotExist", null, target); + return null; + } + + Class beanClass = resolveClass(resolver, bean.getClassName(), context); + Set> ifaces = javaIntrospectionHelper.getAllInterfaces(beanClass); + for (Class interfaze : ifaces) { + if (interfaze.isAnnotationPresent(Remotable.class)) { + return interfaze; + } + } + + return beanClass; + } + + /* * Determines whether a reference attribute of a Spring property element is resolved either * by a bean in the application context or by an SCA reference element or by an SCA property * element -- cgit v1.2.3