geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1081259 - in /geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment: EjbModuleBuilder.java EjbRefBuilder.java
Date Mon, 14 Mar 2011 04:34:03 GMT
Author: genspring
Date: Mon Mar 14 04:34:03 2011
New Revision: 1081259

URL: http://svn.apache.org/viewvc?rev=1081259&view=rev
Log:
Merge trunk@1080143 trunk@1079747 trunk@1079750 trunk@1080101 to m2 build.  All of these revisions
are changes on openejb module.

Modified:
    geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
    geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java

Modified: geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?rev=1081259&r1=1081258&r2=1081259&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
(original)
+++ geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Mon Mar 14 04:34:03 2011
@@ -16,14 +16,19 @@
  */
 package org.apache.geronimo.openejb.deployment;
 
+import javax.ejb.EntityContext;
+import javax.ejb.TimerService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceContext;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -32,12 +37,9 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.jar.Attributes;
 import java.util.jar.JarFile;
-
-import javax.ejb.EntityContext;
-import javax.ejb.TimerService;
-import javax.xml.namespace.QName;
-import javax.xml.ws.WebServiceContext;
+import java.util.jar.Manifest;
 
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.connector.wrapper.ResourceAdapterWrapperGBean;
@@ -82,6 +84,8 @@ import org.apache.geronimo.openejb.xbean
 import org.apache.geronimo.openwebbeans.SharedOwbContext;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
 import org.apache.geronimo.security.jacc.ComponentPermissions;
+import org.apache.openejb.ClassLoaderUtil;
+import org.apache.openejb.OpenEJB;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.Vendor;
 import org.apache.openejb.assembler.classic.AppInfo;
@@ -102,8 +106,6 @@ import org.apache.openejb.config.AutoCon
 import org.apache.openejb.config.ClearEmptyMappedName;
 import org.apache.openejb.config.CmpJpaConversion;
 import org.apache.openejb.config.ConfigurationFactory;
-import org.apache.openejb.config.DeploymentLoader;
-import org.apache.openejb.config.DeploymentModule;
 import org.apache.openejb.config.DynamicDeployer;
 import org.apache.openejb.config.FinderFactory;
 import org.apache.openejb.config.GeneratedClientModules;
@@ -115,8 +117,6 @@ import org.apache.openejb.config.OpenEjb
 import org.apache.openejb.config.OutputGeneratedDescriptors;
 import org.apache.openejb.config.ReadDescriptors;
 import org.apache.openejb.config.SunConversion;
-import org.apache.openejb.config.UnknownModuleTypeException;
-import org.apache.openejb.config.UnsupportedModuleTypeException;
 import org.apache.openejb.config.ValidateModules;
 import org.apache.openejb.config.ValidationError;
 import org.apache.openejb.config.ValidationFailedException;
@@ -144,8 +144,10 @@ import org.apache.openejb.jee.oejb2.Reso
 import org.apache.openejb.loader.Options;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.osgi.core.BundleFinderFactory;
+import org.apache.openejb.util.AnnotationFinder;
 import org.apache.openejb.util.LinkResolver;
 import org.apache.openejb.util.UniqueDefaultLinkResolver;
+import org.apache.xbean.finder.ResourceFinder;
 import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
@@ -264,6 +266,7 @@ public class EjbModuleBuilder implements
     }
 
     //ModuleBuilderExtension entry points
+
     @Override
     public void createModule(Module module, Bundle bundle, Naming naming, ModuleIDBuilder
moduleIDBuilder) throws DeploymentException {
         //May be implemented for EBA support ?
@@ -299,37 +302,35 @@ public class EjbModuleBuilder implements
         if (targetPath == null) throw new NullPointerException("targetPath is null");
         if (targetPath.endsWith("/")) throw new IllegalArgumentException("targetPath must
not end with a '/'");
 
-        // Load the module file, except for ejb module, ejb web service seems also used the
parsed data by DeploymentLoader
-        Set<Class<? extends DeploymentModule>> loadingRequiredModuleTypes = new
HashSet<Class<? extends DeploymentModule>>();
-        loadingRequiredModuleTypes.add(org.apache.openejb.config.EjbModule.class);
-        loadingRequiredModuleTypes.add(org.apache.openejb.config.WsModule.class);
-        DeploymentLoader loader = new DeploymentLoader(ddDir, loadingRequiredModuleTypes);
-        AppModule appModule;
+        // verify we have a valid file
+        String jarPath = moduleFile.getName();
+
+        URL baseUrl = null;
+        ClassLoader classLoader = null;
+        Map<String, URL> descriptors = null;
         try {
-            appModule = loader.load(new File(moduleFile.getName()));
-        } catch (UnknownModuleTypeException e) {
-            return null;
-        } catch (UnsupportedModuleTypeException e) {
-            return null;
-        } catch (OpenEJBException e) {
-            Throwable t = e.getCause();
-            if (t instanceof UnknownModuleTypeException || t instanceof UnsupportedModuleTypeException)
{
-                return null;
-            }
+            File jarFile = new File(moduleFile.getName());
+
+            baseUrl = jarFile.toURI().toURL();
+
+            classLoader = (ClassLoader) ClassLoaderUtil.createTempClassLoader(ClassLoaderUtil.createClassLoader(jarPath,
new URL[]{baseUrl}, OpenEJB.class.getClassLoader()));
+
+            ResourceFinder finder = new ResourceFinder("", classLoader, baseUrl);
+
+            descriptors = finder.getResourcesMap(ddDir);
+        } catch (IOException e) {
             throw new DeploymentException(e);
         }
 
-        // did we find a ejb jar?
-        if (appModule.getEjbModules().size() == 0) {
+        if (!isEjbModule(baseUrl, classLoader, descriptors)) {
             return null;
         }
 
-        // get the module
-        org.apache.openejb.config.EjbModule ejbModule = appModule.getEjbModules().get(0);
+        // create the EJB Module
+        org.apache.openejb.config.EjbModule ejbModule = new org.apache.openejb.config.EjbModule(classLoader,
null, jarPath, null, null);
+        ejbModule.getAltDDs().putAll(descriptors);
 
-        // add the ejb-jar.xml altDD plan
         if (specDDUrl != null) {
-            ejbModule.setEjbJar(null);
             ejbModule.getAltDDs().put("ejb-jar.xml", specDDUrl);
         }
 
@@ -363,7 +364,7 @@ public class EjbModuleBuilder implements
         // Read in the deploument desiptor files
         ReadDescriptors readDescriptors = new ReadDescriptors();
         try {
-            readDescriptors.deploy(appModule);
+            readDescriptors.deploy(new AppModule(ejbModule));
         } catch (OpenEJBException e) {
             throw new DeploymentException("Failed parsing descriptors for module: " + moduleFile.getName(),
e);
         }
@@ -403,18 +404,30 @@ public class EjbModuleBuilder implements
         // Create XMLBeans version of EjbJarType for the AnnotatedApp interface
         EjbJar ejbJar = ejbModule.getEjbJar();
 
+
+        File file = new File(moduleFile.getName());
+        String packageName = file.getName();
+        
         String name;
+        
         if (subModule) {
             name = parentModule.getName();
         } else if (ejbJar.getModuleName() != null) {
             name = ejbJar.getModuleName().trim();
         } else if (standAlone) {
-            name = FileUtils.removeExtension(new File(moduleFile.getName()).getName(), ".jar");
+            name = FileUtils.removeExtension(packageName, ".jar");
         } else {
             name = FileUtils.removeExtension(targetPath, ".jar");
         }
 
         ejbModule.setModuleId(name);
+        
+        if (standAlone) {
+            ejbModule.setModuleUri(URI.create(packageName));
+        } else {
+            ejbModule.setModuleUri(URI.create(targetPath));
+        }
+
 
         Map<JndiKey, Map<String, Object>> context = null;
         if (subModule) {
@@ -630,7 +643,7 @@ public class EjbModuleBuilder implements
            GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");
 
         // We must set all mapped name references back to null or Geronimo will blow up
-        unmapReferences(ejbJar, geronimoEjbJarType);
+        // unmapReferences(ejbJar, geronimoEjbJarType);
 
         // create a xmlbeans version of the ejb-jar.xml file, because the jndi code is coupled
based on xmlbeans objects
        /* EjbJarType ejbJarType = XmlUtil.convertToXmlbeans(ejbJar);
@@ -802,7 +815,7 @@ public class EjbModuleBuilder implements
         if (!options.get(VALIDATION_SKIP_PROPERTY, false)) {
             chain.add(new ValidateModules());
         } else {
-            DeploymentLoader.logger.info("validationDisabled", VALIDATION_SKIP_PROPERTY);
+            log.info("validationDisabled", VALIDATION_SKIP_PROPERTY);
         }
 
         chain.add(new InitEjbDeployments());
@@ -1011,7 +1024,7 @@ public class EjbModuleBuilder implements
                 StatefulBeanInfo statefulBeanInfo = (StatefulBeanInfo) beanInfo;
                 for (PersistenceContextReferenceInfo refInfo : statefulBeanInfo.jndiEnc.persistenceContextRefs)
{
                     if (refInfo.extended) {
-                        refInfo.unitId = linkResolver.resolveLink(refInfo.persistenceUnitName,
ejbJarInfo.moduleId);
+                        refInfo.unitId = linkResolver.resolveLink(refInfo.persistenceUnitName,
ejbJarInfo.moduleUri);
                     }
                 }
             }
@@ -1152,6 +1165,64 @@ public class EjbModuleBuilder implements
         return new AbstractNameQuery(artifact, nameMap, (Set) null);
     }
 
+    private boolean isEjbModule(URL baseUrl, ClassLoader classLoader, Map<String, URL>
descriptors) {
+        try {
+
+            String path = baseUrl.getPath();
+
+            if (path.endsWith("/")) path = path.substring(0, path.length() - 1);
+
+            if (descriptors.containsKey("application.xml") || path.endsWith(".ear")) {
+                return false;
+            }
+
+            if (descriptors.containsKey("application-client.xml")) {
+                return false;
+            }
+
+            if (descriptors.containsKey("ra.xml") || path.endsWith(".rar")) {
+                return false;
+            }
+
+            if (descriptors.containsKey("ejb-jar.xml")) {
+                return true;
+            }
+
+            URL manifestUrl = descriptors.get("MANIFEST.MF");
+            if (manifestUrl != null) {
+                // In this case scanPotentialClientModules really means "require application-client.xml"
+                InputStream is = manifestUrl.openStream();
+                Manifest manifest = new Manifest(is);
+                String mainClass = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
+                if (mainClass != null) {
+                    return false;
+                }
+            }
+
+            AnnotationFinder classFinder = new AnnotationFinder(classLoader, Arrays.asList(baseUrl));
+
+            AnnotationFinder.Filter filter = new AnnotationFinder.Filter() {
+                public boolean accept(String annotationName) {
+                    if (annotationName.startsWith("javax.ejb.")) {
+                        if ("javax.ejb.Stateful".equals(annotationName)) return true;
+                        if ("javax.ejb.Stateless".equals(annotationName)) return true;
+                        if ("javax.ejb.Singleton".equals(annotationName)) return true;
+                        if ("javax.ejb.MessageDriven".equals(annotationName)) return true;
+                    } else if ("javax.annotation.ManagedBean".equals(annotationName)) {
+                        return true;
+                    }
+                    return false;
+                }
+            };
+
+            return classFinder.find(filter);
+
+        } catch (Exception e) {
+            log.warn("Unable to determine module type for jar: " + baseUrl.toExternalForm(),
e);
+            return false;
+        }
+    }
+
     public static class EarData {
         public static final EARContext.Key<EarData> KEY = new EARContext.Key<EarData>()
{
 

Modified: geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java?rev=1081259&r1=1081258&r2=1081259&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
(original)
+++ geronimo/server/branches/3.0-M2/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbRefBuilder.java
Mon Mar 14 04:34:03 2011
@@ -27,12 +27,15 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.deployment.NamingBuilder;
 import org.apache.geronimo.j2ee.deployment.annotation.EJBAnnotationHelper;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.repository.Environment;
@@ -43,6 +46,7 @@ import org.apache.geronimo.xbeans.geroni
 import org.apache.geronimo.xbeans.geronimo.naming.GerEjbLocalRefType;
 import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefDocument;
 import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
@@ -109,6 +113,8 @@ public class EjbRefBuilder extends Abstr
         if ((module != null) && (module.getClassFinder() != null)) {
             processAnnotations(specDD, module);
         }
+        
+        addRefs(specDD, refMap, localRefMap, sharedContext);
 
         Map<String, List<InjectionTarget>> injectionsMap = new HashMap<String,
List<InjectionTarget>>();
         for (Map.Entry<String, EjbRef> entry: specDD.getEjbRefMap().entrySet()) {
@@ -204,159 +210,143 @@ public class EjbRefBuilder extends Abstr
         return value;
     }
 
-//    private void addRefs(JndiConsumer jndiConsumer,
-//                         List<EjbRefType> ejbRefs,
-//                         Map<String, GerEjbRefType> refMap,
-//                         List<EjbLocalRefType> ejbLocalRefs,
-//                         Map<String, GerEjbLocalRefType> localRefMap,
-//                         Map<EARContext.Key, Object> sharedContext) {
-//        Set<String> declaredEjbRefs = new TreeSet<String>();
-//        for (EjbRef ejbRef : jndiConsumer.getEjbRef()) {
-//            declaredEjbRefs.add(ejbRef.getName());
-//        }
-//        for (EjbRefType xmlbeansRef : ejbRefs) {
-//            // skip refs that have already been declared
-//            String refName = getStringValue(xmlbeansRef.getEjbRefName());
-//            if (declaredEjbRefs.contains(refName)) {
-//                continue;
-//            }
-//
-//            // skip corba refs
-//            GerEjbRefType ejbRefType = refMap.get(refName);
-//            if (ejbRefType != null) {
-//                if (ejbRefType.getNsCorbaloc() != null) {
-//                    continue;
-//                }
-//            }
-//            // create the ejb-ref
-//            EjbRef ref = new EjbRef();
-//            // ejb-ref-name
-//            ref.setEjbRefName(refName);
-//
-//            jndiConsumer.getEjbRef().add(ref);
-//
-//            // 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);
-//            } else {
-//                ref.setRefType(EjbRef.Type.UNKNOWN);
-//            }
-//
-//            // home
-//            ref.setHome(getStringValue(xmlbeansRef.getHome()));
-//
-//            // remote
-//            ref.setRemote(getStringValue(xmlbeansRef.getRemote()));
-//
-//            // ejb-link
-//            ref.setEjbLink(getStringValue(xmlbeansRef.getEjbLink()));
-//
-//            // mapped-name
-//            ref.setMappedName(getStringValue(xmlbeansRef.getMappedName()));
-//
-//            // handle external refs
-//            if (ejbRefType != null) {
-//                if (ejbRefType.getNsCorbaloc() != null) {
-//                    // corba refs are simple delegated back to Geronimo
-//                    ref.setMappedName("jndi:java:comp/geronimo/env/" + ref.getEjbRefName());
-//                } else if (ejbRefType.getPattern() != null) {
-//                    // external ear ref
-//                    // set mapped name to the deploymentId of the external ref
-//                    GerPatternType pattern = ejbRefType.getPattern();
-//                    String module = pattern.getModule();
-//                    if (module == null) {
-//                        module = pattern.getArtifactId();
-//                    }
-//                    String ejbName = pattern.getName();
-//                    String deploymentId = module.trim() + "/" + ejbName;
-//                    ref.setMappedName(deploymentId.trim());
-//                }
-//            }
-//
-//            // openejb handling of 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);
-//                }
-//            }
-//            //geronimo's handling of injection-target
-//            addInjections(refName, xmlbeansRef.getInjectionTargetArray(), sharedContext);
-//
-//        }
-//
-//        Set<String> declaredEjbLocalRefs = new TreeSet<String>();
-//        for (EjbLocalRef ejbLocalRef : jndiConsumer.getEjbLocalRef()) {
-//            declaredEjbLocalRefs.add(ejbLocalRef.getName());
-//        }
-//
-//        for (EjbLocalRefType xmlbeansRef : ejbLocalRefs) {
-//            // skip refs that have already been declared
-//            String refName = getStringValue(xmlbeansRef.getEjbRefName());
-//            if (declaredEjbLocalRefs.contains(refName)) {
-//                continue;
-//            }
-//
-//            // create the ejb-ref
-//            EjbLocalRef ref = new EjbLocalRef();
-//            // ejb-ref-name
-//            ref.setEjbRefName(refName);
-//
-//            jndiConsumer.getEjbLocalRef().add(ref);
-//
-//            // 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()));
-//
-//            // handle external refs
-//            GerEjbLocalRefType ejbLocalRefType = localRefMap.get(ref.getEjbRefName());
-//            if (ejbLocalRefType != null && ejbLocalRefType.getPattern() != null)
{
-//                // external ear ref
-//                // set mapped name to the deploymentId of the external ref
-//                GerPatternType pattern = ejbLocalRefType.getPattern();
-//                String module = pattern.getModule();
-//                if (module == null) {
-//                    module = pattern.getArtifactId();
-//                }
-//                String ejbName = pattern.getName();
-//                String deploymentId = module.trim() + "/" + ejbName;
-//                ref.setMappedName(deploymentId.trim());
-//            }
-//
-//            // openejb handling of 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);
-//                }
-//            }
-//            //geronimo's handling of injection-target
-//            addInjections(refName, xmlbeansRef.getInjectionTargetArray(), sharedContext);
-//        }
-//    }
+    private void addRefs(JndiConsumer jndiConsumer, Map<String, GerEjbRefType> refMap,
+            Map<String, GerEjbLocalRefType> localRefMap, Map<EARContext.Key, Object>
sharedContext) {
+
+        for (EjbRef spec_ejbRef : jndiConsumer.getEjbRef()) {
+
+            String refName = getStringValue(spec_ejbRef.getEjbRefName());
+
+            // skip corba refs
+            GerEjbRefType ejbRefType = refMap.get(refName);
+
+            // merge info in alt-DD to spec DD.
+            if (ejbRefType != null) {
+
+                // ejb-ref-name
+                spec_ejbRef.setEjbRefName(refName);
+
+                // ejb-ref-type
+                String refType = getStringValue(spec_ejbRef.getType());
+                if ("SESSION".equalsIgnoreCase(refType)) {
+                    spec_ejbRef.setEjbRefType(org.apache.openejb.jee.EjbRefType.SESSION);
+                } else if ("ENTITY".equalsIgnoreCase(refType)) {
+                    spec_ejbRef.setEjbRefType(org.apache.openejb.jee.EjbRefType.ENTITY);
+                } else {
+                    spec_ejbRef.setRefType(EjbRef.Type.UNKNOWN);
+                }
+
+                // home
+                spec_ejbRef.setHome(getStringValue(spec_ejbRef.getHome()));
+
+                // remote
+                spec_ejbRef.setRemote(getStringValue(spec_ejbRef.getRemote()));
+
+                // ejb-link
+                spec_ejbRef.setEjbLink(getStringValue(spec_ejbRef.getEjbLink()));
+
+                // mapped-name
+                spec_ejbRef.setMappedName(getStringValue(spec_ejbRef.getMappedName()));
+
+                // handle external refs
+                if (ejbRefType != null) {
+                    if (ejbRefType.getPattern() != null) {
+                        // external ear ref
+                        // set mapped name to the deploymentId of the external ref
+                        GerPatternType pattern = ejbRefType.getPattern();
+                        String module = pattern.getModule();
+                        if (module == null) {
+                            module = pattern.getArtifactId();
+                        }
+                        String ejbName = pattern.getName();
+                        String deploymentId = module.trim() + "/" + ejbName;
+                        spec_ejbRef.setMappedName(deploymentId.trim());
+                    }
+                }
+
+                // openejb handling of injection-targets
+                if (spec_ejbRef.getInjectionTarget() != null) {
+                    for (InjectionTarget injectionTargetType : spec_ejbRef.getInjectionTarget())
{
+                        InjectionTarget newInjectionTarget = new InjectionTarget();
+                        newInjectionTarget.setInjectionTargetClass(getStringValue(injectionTargetType
+                                .getInjectionTargetClass()));
+                        newInjectionTarget.setInjectionTargetName(getStringValue(injectionTargetType
+                                .getInjectionTargetName()));
+                        spec_ejbRef.getInjectionTarget().add(newInjectionTarget);
+                    }
+                }
+
+                // TODO: geronimo's handling of injection-target
+                // addInjections(refName, spec_ejbRef.getInjectionTarget(), NamingBuilder.INJECTION_KEY.get(sharedContext));
+
+            }
+
+        }
+
+        for (EjbLocalRef localRefFromSpecDD : jndiConsumer.getEjbLocalRef()) {
+
+            String refName = getStringValue(localRefFromSpecDD.getEjbRefName());
+
+            // skip corba refs
+            GerEjbLocalRefType ejbLocalRefType = localRefMap.get(refName);
+
+            // merge info in alt-DD to spec DD.
+            if (ejbLocalRefType != null) {
+
+                // ejb-ref-name
+                localRefFromSpecDD.setEjbRefName(refName);
+
+                // ejb-ref-type
+                String refType = getStringValue(localRefFromSpecDD.getType());
+                if ("SESSION".equalsIgnoreCase(refType)) {
+                    localRefFromSpecDD.setEjbRefType(org.apache.openejb.jee.EjbRefType.SESSION);
+                } else if ("ENTITY".equalsIgnoreCase(refType)) {
+                    localRefFromSpecDD.setEjbRefType(org.apache.openejb.jee.EjbRefType.ENTITY);
+                }
+
+                // home
+                localRefFromSpecDD.setLocalHome(getStringValue(localRefFromSpecDD.getLocalHome()));
+
+                // remote
+                localRefFromSpecDD.setLocal(getStringValue(localRefFromSpecDD.getLocal()));
+
+                // ejb-link
+                localRefFromSpecDD.setEjbLink(getStringValue(localRefFromSpecDD.getEjbLink()));
+
+                // mapped-name
+                localRefFromSpecDD.setMappedName(getStringValue(localRefFromSpecDD.getMappedName()));
+
+                // handle external refs
+                if (ejbLocalRefType.getPattern() != null) {
+                    // external ear ref
+                    // set mapped name to the deploymentId of the external ref
+                    GerPatternType pattern = ejbLocalRefType.getPattern();
+                    String module = pattern.getModule();
+                    if (module == null) {
+                        module = pattern.getArtifactId();
+                    }
+                    String ejbName = pattern.getName();
+                    String deploymentId = module.trim() + "/" + ejbName;
+                    localRefFromSpecDD.setMappedName(deploymentId.trim());
+                }
+
+                // openejb handling of injection-targets
+                if (localRefFromSpecDD.getInjectionTarget() != null) {
+                    for (InjectionTarget injectionTargetType : localRefFromSpecDD.getInjectionTarget())
{
+                        InjectionTarget injectionTarget = new InjectionTarget();
+                        injectionTarget.setInjectionTargetClass(getStringValue(injectionTargetType
+                                .getInjectionTargetClass()));
+                        injectionTarget.setInjectionTargetName(getStringValue(injectionTargetType
+                                .getInjectionTargetName()));
+                        localRefFromSpecDD.getInjectionTarget().add(injectionTarget);
+                    }
+                }
+                // TODO: geronimo's handling of injection-target
+                // addInjections(refName, localRefFromSpecDD.getInjectionTarget(), NamingBuilder.INJECTION_KEY.get(sharedContext));
+            }
+
+        }
+    }
 
     private Map<String, GerEjbRefType> mapEjbRefs(XmlObject plan) {
         Map<String, GerEjbRefType> refMap = new HashMap<String, GerEjbRefType>();
@@ -370,7 +360,7 @@ public class EjbRefBuilder extends Abstr
         if (xmlObjects != null) {
             for (XmlObject xmlObject : xmlObjects) {
                 GerEjbRefType ref = (GerEjbRefType) xmlObject.copy().changeType(GerEjbRefType.type);
-                refMap.put(getJndiName(ref.getRefName().trim()), ref);
+                refMap.put(ref.getRefName().trim(), ref);
             }
         }
         return refMap;
@@ -388,7 +378,7 @@ public class EjbRefBuilder extends Abstr
         if (xmlObjects != null) {
             for (XmlObject xmlObject : xmlObjects) {
                 GerEjbLocalRefType ref = (GerEjbLocalRefType) xmlObject.copy().changeType(GerEjbLocalRefType.type);
-                refMap.put(getJndiName(ref.getRefName().trim()), ref);
+                refMap.put(ref.getRefName().trim(), ref);
             }
         }
         return refMap;



Mime
View raw message