diff options
author | vamsic007 <vamsic007@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-10 10:00:36 +0000 |
---|---|---|
committer | vamsic007 <vamsic007@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-10 10:00:36 +0000 |
commit | a04b4006ead34956b17554fa8dfdc0b04bd43e7d (patch) | |
tree | 88f8b9cdfb16122895b1e887cf8635b02a8634b2 /branches/sca-java-1.x | |
parent | 681aadb9518499598a08167620cefc02de332482 (diff) |
Create an SCA Reference from EJB reference only if there is no @Reference annotation on that field or method.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
2 files changed, 41 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/contribution-jee/pom.xml b/branches/sca-java-1.x/modules/contribution-jee/pom.xml index 1deefc9c8e..f43b95a3b6 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/pom.xml +++ b/branches/sca-java-1.x/modules/contribution-jee/pom.xml @@ -30,6 +30,12 @@ <dependencies> <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-ejb_3.0_spec</artifactId> + <version>1.0.1</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-contribution</artifactId> <version>1.6-SNAPSHOT</version> diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java index e07b6e8aba..117af07369 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java @@ -18,6 +18,8 @@ */ package org.apache.tuscany.sca.contribution.jee.impl; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -40,6 +42,7 @@ import org.apache.tuscany.sca.contribution.jee.EjbInfo; import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; import org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo; import org.apache.tuscany.sca.contribution.jee.EnvEntryInfo; +import org.apache.tuscany.sca.contribution.jee.InjectionTarget; import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; import org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension; import org.apache.tuscany.sca.contribution.jee.WebImplementationGenerated; @@ -93,6 +96,10 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { // Process Remote EJB References for(Map.Entry<String, EjbReferenceInfo> entry : webModule.getEjbReferences().entrySet()) { EjbReferenceInfo ejbRef = entry.getValue(); + // If the EJB reference has @Reference SCA annotation, then skip that reference + if(!hasReferenceAnnotation(ejbRef.injectionTarget)) { + continue; + } String referenceName = entry.getKey(); referenceName = referenceName.replace("/", "_"); Reference reference = assemblyFactory.createComponentReference(); @@ -129,6 +136,7 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { return componentType; } + public ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName) { ComponentType componentType = assemblyFactory.createComponentType(); EjbInfo ejbInfo = ejbModule.getEjbInfo(ejbName); @@ -356,4 +364,31 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { compositeReference.setName(reference.getName()); compositeReference.getPromotedReferences().add(reference); } + + private boolean hasReferenceAnnotation(InjectionTarget injectionTarget) { + if(injectionTarget.targetClass != null || injectionTarget.targetClass.equals("")) { + return false; + } + try { + Class<?> clazz = Class.forName(injectionTarget.targetClass); + try { + Method method = clazz.getDeclaredMethod("set"+injectionTarget.targetName); + if(method.isAnnotationPresent(javax.ejb.EJB.class)) { + return method.isAnnotationPresent(org.osoa.sca.annotations.Reference.class); + } else { + // The method does not have @EJB annotation. So, the method is not good for us. + throw new NoSuchMethodException("set"+injectionTarget.targetName); + } + } catch(NoSuchMethodException nsme) { + try { + Field field = clazz.getDeclaredField(injectionTarget.targetName); + return field.isAnnotationPresent(org.osoa.sca.annotations.Reference.class); + } catch(NoSuchFieldException nsfe) { + return false; + } + } + } catch(ClassNotFoundException cnfe) { + return false; + } + } } |