geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r499336 - in /geronimo/server/trunk: ./ configs/openejb-deployer/src/plan/ modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/ modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/ modu...
Date Wed, 24 Jan 2007 10:16:51 GMT
Author: dain
Date: Wed Jan 24 02:16:48 2007
New Revision: 499336

URL: http://svn.apache.org/viewvc?view=rev&rev=499336
Log:
@EJB annotations now work in web modules

Removed:
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/AbstractEjbRefBuilder.java
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/LocalEjbRefBuilder.java
Modified:
    geronimo/server/trunk/configs/openejb-deployer/src/plan/plan.xml
    geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/resources/META-INF/geronimo-dependency.xml
    geronimo/server/trunk/pom.xml

Modified: geronimo/server/trunk/configs/openejb-deployer/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/configs/openejb-deployer/src/plan/plan.xml?view=diff&rev=499336&r1=499335&r2=499336
==============================================================================
--- geronimo/server/trunk/configs/openejb-deployer/src/plan/plan.xml (original)
+++ geronimo/server/trunk/configs/openejb-deployer/src/plan/plan.xml Wed Jan 24 02:16:48 2007
@@ -94,9 +94,4 @@
             </environment>
         </xml-attribute>
     </gbean>
-
-    <gbean name="OpenEjbLocalRefBuilder" class="org.apache.geronimo.openejb.deployment.ejbref.LocalEjbRefBuilder">
-        <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee</attribute>
-    </gbean>
-
 </module>

Modified: geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java?view=diff&rev=499336&r1=499335&r2=499336
==============================================================================
--- geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ejbref/RemoteEjbRefBuilder.java
Wed Jan 24 02:16:48 2007
@@ -17,39 +17,65 @@
 
 package org.apache.geronimo.openejb.deployment.ejbref;
 
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import javax.xml.namespace.QName;
+import javax.ejb.EJB;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.Local;
+import javax.ejb.Remote;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.WebModule;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.MultiParentClassLoader;
 import org.apache.geronimo.kernel.repository.Environment;
-import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefDocument;
+import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
+import org.apache.geronimo.openejb.deployment.EjbModuleBuilder;
+import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
 import org.apache.geronimo.xbeans.javaee.EjbRefType;
 import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
-import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.alt.config.AnnotationDeployer;
+import org.apache.openejb.alt.config.JndiEncInfoBuilder;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.JndiEncBuilder;
+import org.apache.openejb.assembler.classic.JndiEncInfo;
+import org.apache.openejb.jee.EjbLocalRef;
 import org.apache.openejb.jee.EjbRef;
 import org.apache.openejb.jee.InjectionTarget;
 import org.apache.openejb.jee.JndiConsumer;
+import org.apache.openejb.jee.SessionBean;
+import org.apache.xbean.finder.ClassFinder;
+import org.apache.xbean.finder.UrlSet;
 import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.XmlObject;
 
 /**
  * @version $Revision: 475950 $ $Date: 2006-11-16 14:18:14 -0800 (Thu, 16 Nov 2006) $
  */
-public class RemoteEjbRefBuilder extends AbstractEjbRefBuilder {
-    private static final QName GER_EJB_REF_QNAME = GerEjbRefDocument.type.getDocumentElementName();
-    private static final QNameSet GER_EJB_REF_QNAME_SET = QNameSet.singleton(GER_EJB_REF_QNAME);
+public class RemoteEjbRefBuilder extends AbstractNamingBuilder {
+    private static final Log log = LogFactory.getLog(RemoteEjbRefBuilder.class);
 
     private final QNameSet ejbRefQNameSet;
+    private final QNameSet ejbLocalRefQNameSet;
 
     public RemoteEjbRefBuilder(Environment defaultEnvironment, String[] eeNamespaces) {
         super(defaultEnvironment);
         ejbRefQNameSet = buildQNameSet(eeNamespaces, "ejb-ref");
+        ejbLocalRefQNameSet = buildQNameSet(eeNamespaces, "ejb-local-ref");
+        ejbRefQNameSet.union(ejbLocalRefQNameSet);
     }
 
     public QNameSet getSpecQNameSet() {
@@ -57,23 +83,59 @@
     }
 
     public QNameSet getPlanQNameSet() {
-        return GER_EJB_REF_QNAME_SET;
+        return QNameSet.EMPTY;
     }
 
     protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) {
-        return specDD.selectChildren(ejbRefQNameSet).length > 0;
+        return specDD.selectChildren(ejbRefQNameSet).length > 0 || specDD.selectChildren(ejbLocalRefQNameSet).length
> 0;
     }
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        JndiConsumer jndiConsumer = createJndiConsumer(specDD);
-        bindContext(module, jndiConsumer, componentContext);
+        JndiConsumer consumer = createJndiConsumer(specDD);
+        processWebEjbAnnotations(module, consumer);
+
+        Map<String, Object> map = null;
+        try {
+            EjbModuleBuilder.EarData earData = (EjbModuleBuilder.EarData) module.getRootEarContext().getGeneralData().get(EjbModuleBuilder.EarData.class);
+            Collection<EjbJarInfo> ejbJars = Collections.emptySet();
+            if (earData != null) {
+                ejbJars = earData.getEjbJars();
+            }
+            JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(ejbJars);
+            JndiEncInfo jndiEncInfo = jndiEncInfoBuilder.build(consumer, "GeronimoEnc");
+            JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(jndiEncInfo);
+            map = jndiEncBuilder.buildMap();
+        } catch (OpenEJBException e) {
+            throw new DeploymentException(e);
+        }
+
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            String name = entry.getKey();
+            Object value = entry.getValue();
+
+            // work with names prefixed with java:comp/
+            if (name.startsWith("java:comp/")) {
+                name = name.substring("java:comp/".length());
+            }
+
+            // if this is a ref it will be prefixed with env/
+            if (name.startsWith("env/")) {
+                getJndiContextMap(componentContext).put(name, wrapReference(value));
+            }
+        }
+    }
+
+    // this method exists so client refs can be made remote
+    protected Object wrapReference(Object value) {
+        return value;
     }
 
     protected JndiConsumer createJndiConsumer(XmlObject specDD) throws DeploymentException
{
         List<EjbRefType> ejbRefs = convert(specDD.selectChildren(ejbRefQNameSet), J2EE_CONVERTER,
EjbRefType.class, EjbRefType.type);
+        List<EjbLocalRefType> ejbLocalRefs = convert(specDD.selectChildren(ejbLocalRefQNameSet),
J2EE_CONVERTER, EjbLocalRefType.class, EjbLocalRefType.type);
 
         // build jndi consumer
-        JndiConsumer jndiConsumer = new ApplicationClient();
+        JndiConsumer jndiConsumer = new SessionBean();
         for (EjbRefType xmlbeansRef : ejbRefs) {
             // create the ejb-ref
             EjbRef ref = new EjbRef();
@@ -112,7 +174,169 @@
                 }
             }
         }
+
+        for (EjbLocalRefType xmlbeansRef : ejbLocalRefs) {
+            // create the ejb-ref
+            EjbLocalRef ref = new EjbLocalRef();
+            jndiConsumer.getEjbLocalRef().add(ref);
+
+            // ejb-ref-name
+            ref.setEjbRefName(getStringValue(xmlbeansRef.getEjbRefName()));
+
+            // ejb-ref-type
+            String refType = getStringValue(xmlbeansRef.getEjbRefType());
+            if ("SESSION".equalsIgnoreCase(refType)) {
+                ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.SESSION);
+            } else if ("ENTITY".equalsIgnoreCase(refType)) {
+                ref.setEjbRefType(org.apache.openejb.jee.EjbRefType.ENTITY);
+            }
+
+            // home
+            ref.setLocalHome(getStringValue(xmlbeansRef.getLocalHome()));
+
+            // remote
+            ref.setLocal(getStringValue(xmlbeansRef.getLocal()));
+
+            // ejb-link
+            ref.setEjbLink(getStringValue(xmlbeansRef.getEjbLink()));
+
+            // mapped-name
+            ref.setMappedName(getStringValue(xmlbeansRef.getMappedName()));
+
+            // injection-targets
+            if (xmlbeansRef.getInjectionTargetArray() != null) {
+                for (InjectionTargetType injectionTargetType : xmlbeansRef.getInjectionTargetArray())
{
+                    InjectionTarget injectionTarget = new InjectionTarget();
+                    injectionTarget.setInjectionTargetClass(getStringValue(injectionTargetType.getInjectionTargetClass()));
+                    injectionTarget.setInjectionTargetName(getStringValue(injectionTargetType.getInjectionTargetName()));
+                    ref.getInjectionTarget().add(injectionTarget);
+                }
+            }
+        }
         return jndiConsumer;
+    }
+
+    private void processWebEjbAnnotations(Module module, JndiConsumer consumer) throws DeploymentException
{
+        if (module instanceof WebModule) {
+            try {
+                ClassLoader classLoader = module.getEarContext().getClassLoader();
+                UrlSet urlSet = new UrlSet(classLoader);
+                if (classLoader instanceof MultiParentClassLoader) {
+                    MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader)
classLoader;
+                    for (ClassLoader parent : multiParentClassLoader.getParents()) {
+                        if (parent != null) {
+                            urlSet = urlSet.exclude(parent);
+                        }
+                    }
+                } else {
+                    ClassLoader parent = classLoader.getParent();
+                    if (parent != null) {
+                        urlSet = urlSet.exclude(parent);
+                    }
+                }
+                ClassFinder finder = new ClassFinder(classLoader, urlSet.getUrls());
+                for (Field field : finder.findAnnotatedFields(EJB.class)) {
+                    EJB ejb = field.getAnnotation(EJB.class);
+                    AnnotationDeployer.Member member = new AnnotationDeployer.FieldMember(field);
+                    buildEjbRef(consumer, ejb, member);
+                }
+
+                for (Method method : finder.findAnnotatedMethods(EJB.class)) {
+                    EJB ejb = method.getAnnotation(EJB.class);
+                    AnnotationDeployer.Member member = new AnnotationDeployer.MethodMember(method);
+                    buildEjbRef(consumer, ejb, member);
+                }
+
+            } catch (IOException e) {
+                // ignored... we tried
+                log.warn("Unable to process @EJB annotations for web module" + module.getName(),
e);
+            }
+        }
+    }
+
+    private void buildEjbRef(JndiConsumer consumer, EJB ejb, AnnotationDeployer.Member member)
{
+        EjbRef ejbRef = new EjbRef();
+
+        // This is how we deal with the fact that we don't know
+        // whether to use an EjbLocalRef or EjbRef (remote).
+        // We flag it uknown and let the linking code take care of
+        // figuring out what to do with it.
+        ejbRef.setRefType(EjbRef.Type.UNKNOWN);
+
+        if (member != null) {
+            // Set the member name where this will be injected
+            InjectionTarget target = new InjectionTarget();
+            target.setInjectionTargetClass(member.getDeclaringClass().getName());
+            target.setInjectionTargetName(member.getName());
+            ejbRef.getInjectionTarget().add(target);
+        }
+
+        Class interfce = ejb.beanInterface();
+        if (interfce.equals(Object.class)) {
+            interfce = (member == null) ? null : member.getType();
+        }
+
+        if (interfce != null && !interfce.equals(Object.class)) {
+            if (EJBHome.class.isAssignableFrom(interfce)) {
+                ejbRef.setHome(interfce.getName());
+                Method[] methods = interfce.getMethods();
+                for (Method method : methods) {
+                    if (method.getName().startsWith("create")) {
+                        ejbRef.setRemote(method.getReturnType().getName());
+                        break;
+                    }
+                }
+                ejbRef.setRefType(EjbRef.Type.REMOTE);
+            } else if (EJBLocalHome.class.isAssignableFrom(interfce)) {
+                ejbRef.setHome(interfce.getName());
+                Method[] methods = interfce.getMethods();
+                for (Method method : methods) {
+                    if (method.getName().startsWith("create")) {
+                        ejbRef.setRemote(method.getReturnType().getName());
+                        break;
+                    }
+                }
+                ejbRef.setRefType(EjbRef.Type.LOCAL);
+            } else {
+                ejbRef.setRemote(interfce.getName());
+                if (interfce.getAnnotation(Local.class) != null) {
+                    ejbRef.setRefType(EjbRef.Type.LOCAL);
+                } else if (interfce.getAnnotation(Remote.class) != null) {
+                    ejbRef.setRefType(EjbRef.Type.REMOTE);
+                }
+            }
+        }
+
+        // Get the ejb-ref-name
+        String refName = ejb.name();
+        if (refName.equals("")) {
+            refName = (member == null) ? null : member.getDeclaringClass().getName() + "/"
+ member.getName();
+        }
+        ejbRef.setEjbRefName(refName);
+
+        // Set the ejb-link, if any
+        String ejbName = ejb.beanName();
+        if (ejbName.equals("")) {
+            ejbName = null;
+        }
+        ejbRef.setEjbLink(ejbName);
+
+        // Set the mappedName, if any
+        String mappedName = ejb.mappedName();
+        if (mappedName.equals("")) {
+            mappedName = null;
+        }
+        ejbRef.setMappedName(mappedName);
+
+        switch (ejbRef.getRefType()) {
+            case UNKNOWN:
+            case REMOTE:
+                consumer.getEjbRef().add(ejbRef);
+                break;
+            case LOCAL:
+                consumer.getEjbLocalRef().add(new EjbLocalRef(ejbRef));
+                break;
+        }
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?view=diff&rev=499336&r1=499335&r2=499336
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Wed Jan 24 02:16:48 2007
@@ -23,6 +23,7 @@
 import java.util.Map;
 
 import javax.naming.NamingException;
+import javax.naming.Context;
 import javax.security.auth.Subject;
 import javax.security.jacc.PolicyContext;
 import javax.servlet.Servlet;
@@ -34,6 +35,7 @@
 import org.apache.catalina.Manager;
 import org.apache.catalina.Valve;
 import org.apache.catalina.Wrapper;
+import org.apache.catalina.util.DefaultAnnotationProcessor;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.core.StandardContext;
@@ -93,6 +95,13 @@
             }
         } catch (NamingException ne) {
             log.error(ne);
+        }
+        try {
+            Context env = (Context) enc.lookup("env");
+            setAnnotationProcessor(new DefaultAnnotationProcessor(env));
+        } catch (NamingException e) {
+            // ignored
+            log.warn("Could not find env in enterprise naming context", e);
         }
 
         int index = 0;

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/resources/META-INF/geronimo-dependency.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/resources/META-INF/geronimo-dependency.xml?view=diff&rev=499336&r1=499335&r2=499336
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/resources/META-INF/geronimo-dependency.xml
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/resources/META-INF/geronimo-dependency.xml
Wed Jan 24 02:16:48 2007
@@ -22,7 +22,12 @@
             <dep:groupId>org.apache.tomcat</dep:groupId>
             <dep:artifactId>catalina</dep:artifactId>
         </dep:dependency>
-        
+
+        <dep:dependency>
+            <dep:groupId>org.apache.tomcat</dep:groupId>
+            <dep:artifactId>annotations-api</dep:artifactId>
+        </dep:dependency>
+
         <dep:dependency>
             <dep:groupId>org.apache.tomcat</dep:groupId>
             <dep:artifactId>jasper</dep:artifactId>

Modified: geronimo/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/pom.xml?view=diff&rev=499336&r1=499335&r2=499336
==============================================================================
--- geronimo/server/trunk/pom.xml (original)
+++ geronimo/server/trunk/pom.xml Wed Jan 24 02:16:48 2007
@@ -818,6 +818,12 @@
 
             <dependency>
                 <groupId>org.apache.tomcat</groupId>
+                <artifactId>annotations-api</artifactId>
+                <version>${tomcatVersion}</version>
+            </dependency>
+
+           <dependency>
+                <groupId>org.apache.tomcat</groupId>
                 <artifactId>jasper</artifactId>
                 <version>${tomcatVersion}</version>
             </dependency>



Mime
View raw message