From a04b4006ead34956b17554fa8dfdc0b04bd43e7d Mon Sep 17 00:00:00 2001 From: vamsic007 Date: Tue, 10 Nov 2009 10:00:36 +0000 Subject: 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 --- .../sca-java-1.x/modules/contribution-jee/pom.xml | 6 ++++ .../jee/impl/JavaEEOptionalExtensionImpl.java | 35 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'branches') 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 @@ -29,6 +29,12 @@ Apache Tuscany SCA Java EE + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0.1 + provided + org.apache.tuscany.sca tuscany-contribution 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 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; + } + } } -- cgit v1.2.3