You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/12/10 09:08:18 UTC

svn commit: r602803 [1/2] - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/assembler/classic/ main/java/org/apache/openejb/config/ main/java/org/apache/openejb/util/ main/resources/org/apache/openejb/config/rules/ t...

Author: dblevins
Date: Mon Dec 10 00:07:48 2007
New Revision: 602803

URL: http://svn.apache.org/viewvc?rev=602803&view=rev
Log:
Cleanup of AppInfo creation and JndiEncInfo creation.
In-progress refactor of EntityManagerFactory linking code. Now resolution is also done in ConfigurationFactory.  Still also done in Assembler, this will move.
Several new validations for @EJB, @Resource, @PersistenceContext, and @PersistenceUnit references


Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ApplyOpenejbJar.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/URISupportTest.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LinkResolver.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceUnitInfo.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
    openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Mon Dec 10 00:07:48 2007
@@ -330,7 +330,7 @@
         for (AppInfo appInfo : containerSystemInfo.applications) {
 
             try {
-                createApplication(appInfo, null, createAppClassLoader(appInfo));
+                createApplication(appInfo, createAppClassLoader(appInfo));
             } catch (DuplicateDeploymentIdException e) {
                 // already logged.
             } catch (Throwable e) {
@@ -412,7 +412,7 @@
     }
 
     public void createApplication(AppInfo appInfo, ClassLoader classLoader) throws OpenEJBException, IOException, NamingException {
-        createApplication(appInfo, null, classLoader);        
+        createApplication(appInfo, null, classLoader);
     }
 
     public void createApplication(AppInfo appInfo, LinkResolver<EntityManagerFactory> emfLinkResolver, ClassLoader classLoader) throws OpenEJBException, IOException, NamingException {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LinkResolver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LinkResolver.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LinkResolver.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LinkResolver.java Mon Dec 10 00:07:48 2007
@@ -21,6 +21,7 @@
 import java.util.Collection;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.Collections;
 import java.net.URI;
 
 public class LinkResolver<E> {
@@ -46,6 +47,15 @@
         values.add(value);
 
         return true;
+    }
+
+    public Collection<E> values() {
+        return byFullName.values();
+    }
+
+    public Collection<E> values(String shortName) {
+        Collection<E> es = byShortName.get(shortName);
+        return es != null? es: Collections.EMPTY_LIST;
     }
 
     public E resolveLink(String link, String moduleId) {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceUnitInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceUnitInfo.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceUnitInfo.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceUnitInfo.java Mon Dec 10 00:07:48 2007
@@ -23,6 +23,7 @@
 import java.util.TreeSet;
 
 public class PersistenceUnitInfo extends InfoObject {
+    public String id;
     public String name;
     public String provider;
     public String transactionType;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Mon Dec 10 00:07:48 2007
@@ -117,6 +117,8 @@
 import javax.persistence.PersistenceContexts;
 import javax.persistence.PersistenceUnit;
 import javax.persistence.PersistenceUnits;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.WebServiceRef;
 import javax.xml.ws.WebServiceRefs;
@@ -143,6 +145,7 @@
 public class AnnotationDeployer implements DynamicDeployer {
     public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, AnnotationDeployer.class.getPackage().getName());
 
+    private static final ThreadLocal<ValidationContext> validationContext = new ThreadLocal<ValidationContext>();
 
     private final DiscoverAnnotatedBeans discoverAnnotatedBeans;
     private final ProcessAnnotatedBeans processAnnotatedBeans;
@@ -155,17 +158,15 @@
     }
 
     public AppModule deploy(AppModule appModule) throws OpenEJBException {
-        appModule = discoverAnnotatedBeans.deploy(appModule);
-        appModule = envEntriesPropertiesDeployer.deploy(appModule);
-        appModule = processAnnotatedBeans.deploy(appModule);
-        return appModule;
-    }
-
-    public WebModule deploy(WebModule webModule) throws OpenEJBException {
-        webModule = discoverAnnotatedBeans.deploy(webModule);
-        webModule = envEntriesPropertiesDeployer.deploy(webModule);
-        webModule = processAnnotatedBeans.deploy(webModule);
-        return webModule;
+        validationContext.set(appModule.getValidation());
+        try {
+            appModule = discoverAnnotatedBeans.deploy(appModule);
+            appModule = envEntriesPropertiesDeployer.deploy(appModule);
+            appModule = processAnnotatedBeans.deploy(appModule);
+            return appModule;
+        } finally {
+            validationContext.remove();
+        }
     }
 
     public static class DiscoverAnnotatedBeans implements DynamicDeployer {
@@ -1291,10 +1292,12 @@
             if (refName.equals("")) {
                 refName = (member == null) ? null : member.getDeclaringClass().getName() + "/" + member.getName();
             }
-            if (refName == null) {
-                throw new OpenEJBException("The name attribute is not specified for the class level annotation @PersistenceUnit with unitName=" + persistenceUnit.unitName()
-                        + ". It is mandatory for all class level PersistenceUnit annotations.");
+
+            if (refName == null && member == null) {
+                validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceUnitAnnotation.onClassWithNoName", persistenceUnit.unitName());
+                return;
             }
+
             PersistenceUnitRef persistenceUnitRef = consumer.getPersistenceUnitRefMap().get(refName);
             if (persistenceUnitRef == null) {
                 persistenceUnitRef = new PersistenceUnitRef();
@@ -1303,11 +1306,18 @@
                 consumer.getPersistenceUnitRef().add(persistenceUnitRef);
             }
             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());
-                persistenceUnitRef.getInjectionTarget().add(target);
+                Class type = member.getType();
+                if (EntityManager.class.isAssignableFrom(type)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceUnitAnnotation.onEntityManager", persistenceUnitRef.getName());
+                } else if (!EntityManagerFactory.class.isAssignableFrom(type)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceUnitAnnotation.onNonEntityManagerFactory", persistenceUnitRef.getName());
+                } else {
+                    // Set the member name where this will be injected
+                    InjectionTarget target = new InjectionTarget();
+                    target.setInjectionTargetClass(member.getDeclaringClass().getName());
+                    target.setInjectionTargetName(member.getName());
+                    persistenceUnitRef.getInjectionTarget().add(target);
+                }
             }
 
             if (persistenceUnitRef.getPersistenceUnitName() == null && !persistenceUnit.unitName().equals("")) {
@@ -1322,8 +1332,30 @@
                 refName = (member == null) ? null : member.getDeclaringClass().getName() + "/" + member.getName();
             }
 
+            if (member == null) {
+                boolean shouldReturn = false;
+                if (resource.name().equals("")){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "resourceAnnotation.onClassWithNoName");
+                    shouldReturn = true;
+                }
+                if (resource.type().equals(Object.class)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "resourceAnnotation.onClassWithNoType");
+                    shouldReturn = true;
+                }
+                if (shouldReturn) return;
+            }
+
             JndiReference reference = consumer.getEnvEntryMap().get(refName);
             if (reference == null) {
+
+                { // Little quick validation for common mistake
+                    Class type = member.getType();
+                    if (EntityManager.class.isAssignableFrom(type)){
+                        validationContext.get().fail(consumer.getJndiConsumerName(), "resourceRef.onEntityManager", refName);
+                    } else if (EntityManagerFactory.class.isAssignableFrom(type)){
+                        validationContext.get().fail(consumer.getJndiConsumerName(), "resourceRef.onEntityManagerFactory", refName);
+                    }
+                }
                 String type;
                 if (resource.type() != java.lang.Object.class) {
                     type = resource.type().getName();
@@ -1521,10 +1553,11 @@
                 refName = (member == null) ? null : member.getDeclaringClass().getName() + "/" + member.getName();
             }
 
-            if (refName == null) {
-                throw new OpenEJBException("The name attribute is not specified for the class level annotation @PersistenceContext with unitName="
-                        + persistenceContext.unitName() + ". It is mandatory for all class level PersistenceContext annotations.");
+            if (refName == null && member == null) {
+                validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onClassWithNoName", persistenceContext.unitName());
+                return;
             }
+
             PersistenceContextRef persistenceContextRef = consumer.getPersistenceContextRefMap().get(refName);
             if (persistenceContextRef == null) {
                 persistenceContextRef = new PersistenceContextRef();
@@ -1572,15 +1605,36 @@
             }
 
             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());
-                persistenceContextRef.getInjectionTarget().add(target);
+                Class type = member.getType();
+                if (EntityManagerFactory.class.isAssignableFrom(type)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onEntityManagerFactory", persistenceContextRef.getName());
+                } else if (!EntityManager.class.isAssignableFrom(type)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "presistenceContextAnnotation.onNonEntityManager", persistenceContextRef.getName());
+                } else {
+                    // Set the member name where this will be injected
+                    InjectionTarget target = new InjectionTarget();
+                    target.setInjectionTargetClass(member.getDeclaringClass().getName());
+                    target.setInjectionTargetName(member.getName());
+                    persistenceContextRef.getInjectionTarget().add(target);
+                }
             }
         }
 
         private void buildEjbRef(JndiConsumer consumer, EJB ejb, Member member) {
+
+            if (member == null) {
+                boolean shouldReturn = false;
+                if (ejb.name().equals("")){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "ejbAnnotation.onClassWithNoName");
+                    shouldReturn = true;
+                }
+                if (ejb.beanInterface().equals(Object.class)){
+                    validationContext.get().fail(consumer.getJndiConsumerName(), "ejbAnnotation.onClassWithNoBeanInterface");
+                    shouldReturn = true;
+                }
+                if (shouldReturn) return;
+            }
+
             EjbRef ejbRef = new EjbRef();
 
             // This is how we deal with the fact that we don't know

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=602803&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java Mon Dec 10 00:07:48 2007
@@ -0,0 +1,484 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
+import org.apache.openejb.assembler.classic.JndiEncInfo;
+import org.apache.openejb.assembler.classic.ClientInfo;
+import org.apache.openejb.assembler.classic.ConnectorInfo;
+import org.apache.openejb.assembler.classic.ResourceInfo;
+import org.apache.openejb.assembler.classic.MdbContainerInfo;
+import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.assembler.classic.ServletInfo;
+import org.apache.openejb.assembler.classic.PortInfo;
+import org.apache.openejb.assembler.classic.HandlerChainInfo;
+import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Messages;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.jee.jpa.unit.Property;
+import org.apache.openejb.jee.jpa.JpaJaxbUtil;
+import org.apache.openejb.jee.jpa.EntityMappings;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.jee.Connector;
+import org.apache.openejb.jee.ResourceAdapter;
+import org.apache.openejb.jee.ConfigProperty;
+import org.apache.openejb.jee.OutboundResourceAdapter;
+import org.apache.openejb.jee.ConnectionDefinition;
+import org.apache.openejb.jee.InboundResource;
+import org.apache.openejb.jee.MessageListener;
+import org.apache.openejb.jee.AdminObject;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.Servlet;
+import org.apache.openejb.jee.Webservices;
+import org.apache.openejb.jee.WebserviceDescription;
+import org.apache.openejb.jee.PortComponent;
+import org.apache.openejb.jee.ServiceImplBean;
+
+import javax.xml.bind.JAXBException;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.net.URL;
+import java.io.File;
+
+/**
+ * @version $Rev$ $Date$
+ */
+class AppInfoBuilder {
+
+    private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources");
+    private static final Messages messages = new Messages("org.apache.openejb.util.resources");
+
+    private final ConfigurationFactory configFactory;
+
+    private EjbJarInfoBuilder ejbJarInfoBuilder = new EjbJarInfoBuilder();
+
+    public AppInfoBuilder(ConfigurationFactory configFactory) {
+        this.configFactory = configFactory;
+    }
+
+    public AppInfo build(AppModule appModule) throws OpenEJBException {
+        AppInfo appInfo = new AppInfo();
+
+        //
+        //  Persistence Units
+        //
+
+        buildPersistenceModules(appModule, appInfo);
+
+
+        //
+        //  EJB Jars
+        //
+
+        Map<String,EjbJarInfo> ejbJarInfos = new TreeMap<String,EjbJarInfo>();
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+            try {
+                EjbJarInfo ejbJarInfo = ejbJarInfoBuilder.buildInfo(ejbModule);
+
+                Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
+
+                for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
+                    EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
+
+                    if (!configFactory.getContainerIds().contains(d.getContainerId()) && !skipMdb(bean)) {
+                        String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName());
+                        logger.fatal(msg);
+                        throw new OpenEJBException(msg);
+                    }
+
+                    bean.containerId = d.getContainerId();
+                }
+
+                ejbJarInfo.portInfos.addAll(configureWebservices(ejbModule.getWebservices()));
+
+                ejbJarInfos.put(ejbJarInfo.moduleId, ejbJarInfo);
+
+                appInfo.ejbJars.add(ejbJarInfo);
+
+
+            } catch (OpenEJBException e) {
+                ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
+                throw e;
+            }
+        }
+
+        // Create the JNDI info builder
+        JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo);
+
+        // Build the JNDI tree for each ejb
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+
+            EjbJarInfo ejbJar = ejbJarInfos.get(ejbModule.getModuleId());
+
+            Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
+
+            for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
+
+                // Get the ejb-jar.xml object
+                EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);
+
+                // Build the JNDI info tree for the EJB
+                JndiEncInfo jndi = jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleId);
+
+                beanInfo.jndiEnc = jndi;
+            }
+        }
+
+        //
+        //  Application Clients
+        //
+
+        buildClientModules(appModule, appInfo, jndiEncInfoBuilder);
+
+        //
+        //  J2EE Connectors
+        //
+
+        buildConnectorModules(appModule, appInfo);
+
+        //
+        //  Webapps
+        //
+
+        buildWebModules(appModule, jndiEncInfoBuilder, appInfo);
+
+
+        //
+        //  Final AppInfo creation
+        //
+
+        appInfo.jarPath = appModule.getJarLocation();
+        appInfo.watchedResources.addAll(appModule.getWatchedResources());
+        List<URL> additionalLibraries = appModule.getAdditionalLibraries();
+        for (URL url : additionalLibraries) {
+            File file = new File(url.getPath());
+            appInfo.libs.add(file.getAbsolutePath());
+        }
+
+        if (appModule.getCmpMappings() != null) {
+            try {
+                String cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
+                appInfo.cmpMappingsXml = cmpMappingsXml;
+            } catch (JAXBException e) {
+                throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
+            }
+        }
+
+        ReportValidationResults reportValidationResults = new ReportValidationResults();
+        reportValidationResults.deploy(appModule);
+
+        logger.info("Loaded Module: " + appInfo.jarPath);
+        return appInfo;
+
+    }
+
+    private void buildClientModules(AppModule appModule, AppInfo appInfo, JndiEncInfoBuilder jndiEncInfoBuilder) throws OpenEJBException {
+        for (ClientModule clientModule : appModule.getClientModules()) {
+            ApplicationClient applicationClient = clientModule.getApplicationClient();
+            ClientInfo clientInfo = new ClientInfo();
+            clientInfo.description = applicationClient.getDescription();
+            clientInfo.displayName = applicationClient.getDisplayName();
+            clientInfo.codebase = clientModule.getJarLocation();
+            clientInfo.mainClass = clientModule.getMainClass();
+            clientInfo.callbackHandler = applicationClient.getCallbackHandler();
+            clientInfo.moduleId = getClientModuleId(clientModule);
+            clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
+
+            clientInfo.jndiEnc = jndiEncInfoBuilder.build(applicationClient, clientModule.getJarLocation(), clientInfo.moduleId);
+            appInfo.clients.add(clientInfo);
+        }
+    }
+
+    private void buildWebModules(AppModule appModule, JndiEncInfoBuilder jndiEncInfoBuilder, AppInfo appInfo) throws OpenEJBException {
+        for (WebModule webModule : appModule.getWebModules()) {
+            WebApp webApp = webModule.getWebApp();
+            WebAppInfo webAppInfo = new WebAppInfo();
+            webAppInfo.description = webApp.getDescription();
+            webAppInfo.displayName = webApp.getDisplayName();
+            webAppInfo.codebase = webModule.getJarLocation();
+            webAppInfo.moduleId = webModule.getModuleId();
+            webAppInfo.watchedResources.addAll(webModule.getWatchedResources());
+
+            webAppInfo.host = webModule.getHost();
+            webAppInfo.contextRoot = webModule.getContextRoot();
+
+            webAppInfo.jndiEnc = jndiEncInfoBuilder.build(webApp, webModule.getJarLocation(), webAppInfo.moduleId);
+
+            webAppInfo.portInfos.addAll(configureWebservices(webModule.getWebservices()));
+
+            for (Servlet servlet : webModule.getWebApp().getServlet()) {
+                ServletInfo servletInfo = new ServletInfo();
+                servletInfo.servletName = servlet.getServletName();
+                servletInfo.servletClass = servlet.getServletClass();
+                webAppInfo.servlets.add(servletInfo);
+            }
+
+            appInfo.webApps.add(webAppInfo);
+        }
+    }
+
+    private void buildConnectorModules(AppModule appModule, AppInfo appInfo) {
+        for (ConnectorModule connectorModule : appModule.getResourceModules()) {
+            //
+            // DEVELOPERS NOTE:  if you change the id generation code here, you must change
+            // the id generation code in AutoConfig$AppResources
+            //
+
+            Connector connector = connectorModule.getConnector();
+
+            ConnectorInfo connectorInfo = new ConnectorInfo();
+            connectorInfo.description = connector.getDescription();
+            connectorInfo.displayName = connector.getDisplayName();
+            connectorInfo.codebase = connectorModule.getJarLocation();
+            connectorInfo.moduleId = connectorModule.getModuleId();
+            connectorInfo.watchedResources.addAll(connectorModule.getWatchedResources());
+
+            List<URL> libraries = connectorModule.getLibraries();
+            for (URL url : libraries) {
+                File file = new File(url.getPath());
+                connectorInfo.libs.add(file.getAbsolutePath());
+            }
+
+            ResourceAdapter resourceAdapter = connector.getResourceAdapter();
+            if (resourceAdapter.getResourceAdapterClass() != null) {
+                ResourceInfo resourceInfo = new ResourceInfo();
+                resourceInfo.service = "Resource";
+                if (resourceAdapter.getId() != null) {
+                    resourceInfo.id = resourceAdapter.getId();
+                } else {
+                    resourceInfo.id = connectorModule.getModuleId() + "RA";
+                }
+                resourceInfo.className = resourceAdapter.getResourceAdapterClass();
+                resourceInfo.properties = new Properties();
+                for (ConfigProperty property : resourceAdapter.getConfigProperty()) {
+                    String name = property.getConfigPropertyName();
+                    String value = property.getConfigPropertyValue();
+                    if (value != null) {
+                        resourceInfo.properties.setProperty(name, value);
+                    }
+                }
+                resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
+                connectorInfo.resourceAdapter = resourceInfo;
+            }
+
+            OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
+            if (outbound != null) {
+                String transactionSupport = "none";
+                switch (outbound.getTransactionSupport()) {
+                    case LOCAL_TRANSACTION:
+                        transactionSupport = "local";
+                        break;
+                    case NO_TRANSACTION:
+                        transactionSupport = "none";
+                        break;
+                    case XA_TRANSACTION:
+                        transactionSupport = "xa";
+                        break;
+                }
+                for (ConnectionDefinition connection : outbound.getConnectionDefinition()) {
+                    ResourceInfo resourceInfo = new ResourceInfo();
+                    resourceInfo.service = "Resource";
+                    if (connection.getId() != null) {
+                        resourceInfo.id = connection.getId();
+                    } else if (outbound.getConnectionDefinition().size() == 1) {
+                        resourceInfo.id = connectorModule.getModuleId();
+                    } else {
+                        resourceInfo.id = connectorModule.getModuleId() + "-" + connection.getConnectionFactoryInterface();
+                    }
+                    resourceInfo.className = connection.getManagedConnectionFactoryClass();
+                    resourceInfo.types.add(connection.getConnectionFactoryInterface());
+                    resourceInfo.properties = new Properties();
+                    for (ConfigProperty property : connection.getConfigProperty()) {
+                        String name = property.getConfigPropertyName();
+                        String value = property.getConfigPropertyValue();
+                        if (value != null) {
+                            resourceInfo.properties.setProperty(name, value);
+                        }
+                    }
+                    resourceInfo.properties.setProperty("TransactionSupport", transactionSupport);
+                    resourceInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
+                    resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
+                    connectorInfo.outbound.add(resourceInfo);
+                }
+            }
+
+            InboundResource inbound = resourceAdapter.getInboundResourceAdapter();
+            if (inbound != null) {
+                for (MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
+                    MdbContainerInfo mdbContainerInfo = new MdbContainerInfo();
+                    mdbContainerInfo.service = "Container";
+                    if (messageListener.getId() != null) {
+                        mdbContainerInfo.id = messageListener.getId();
+                    } else if (inbound.getMessageAdapter().getMessageListener().size() == 1) {
+                        mdbContainerInfo.id = connectorModule.getModuleId();
+                    } else {
+                        mdbContainerInfo.id = connectorModule.getModuleId() + "-" + messageListener.getMessageListenerType();
+                    }
+
+                    mdbContainerInfo.properties = new Properties();
+                    mdbContainerInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
+                    mdbContainerInfo.properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
+                    mdbContainerInfo.properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
+
+                    // todo provider system should fill in this information
+                    mdbContainerInfo.types.add("MESSAGE");
+                    mdbContainerInfo.className = "org.apache.openejb.core.mdb.MdbContainer";
+                    mdbContainerInfo.constructorArgs.addAll(Arrays.asList("id", "transactionManager", "securityService", "ResourceAdapter", "MessageListenerInterface", "ActivationSpecClass", "InstanceLimit"));
+                    mdbContainerInfo.properties.setProperty("InstanceLimit", "10");
+
+                    mdbContainerInfo.properties.putAll(ConfigurationFactory.getSystemProperties(mdbContainerInfo.id, "CONTAINER"));
+                    connectorInfo.inbound.add(mdbContainerInfo);
+                }
+            }
+
+            for (AdminObject adminObject : resourceAdapter.getAdminObject()) {
+                ResourceInfo resourceInfo = new ResourceInfo();
+                resourceInfo.service = "Resource";
+                if (adminObject.getId() != null) {
+                    resourceInfo.id = adminObject.getId();
+                } else if (resourceAdapter.getAdminObject().size() == 1) {
+                    resourceInfo.id = connectorModule.getModuleId();
+                } else {
+                    resourceInfo.id = connectorModule.getModuleId() + "-" + adminObject.getAdminObjectInterface();
+                }
+                resourceInfo.className = adminObject.getAdminObjectClass();
+                resourceInfo.types.add(adminObject.getAdminObjectInterface());
+                resourceInfo.properties = new Properties();
+                for (ConfigProperty property : adminObject.getConfigProperty()) {
+                    String name = property.getConfigPropertyName();
+                    String value = property.getConfigPropertyValue();
+                    if (value != null) {
+                        resourceInfo.properties.setProperty(name, value);
+                    }
+                }
+                resourceInfo.properties.putAll(ConfigurationFactory.getSystemProperties(resourceInfo.id, "RESOURCE"));
+                connectorInfo.adminObject.add(resourceInfo);
+            }
+
+            appInfo.connectors.add(connectorInfo);
+        }
+    }
+
+    private void buildPersistenceModules(AppModule appModule, AppInfo appInfo) {
+        for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
+            String rootUrl = persistenceModule.getRootUrl();
+            Persistence persistence = persistenceModule.getPersistence();
+            for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
+                PersistenceUnitInfo info = new PersistenceUnitInfo();
+                info.id = persistenceUnit.getName() + " " + rootUrl.hashCode();
+                info.name = persistenceUnit.getName();
+                info.watchedResources.addAll(persistenceModule.getWatchedResources());
+                info.persistenceUnitRootUrl = rootUrl;
+                info.provider = persistenceUnit.getProvider();
+                info.transactionType = persistenceUnit.getTransactionType().toString();
+
+                Boolean excludeUnlistedClasses = persistenceUnit.isExcludeUnlistedClasses();
+                info.excludeUnlistedClasses = excludeUnlistedClasses != null && excludeUnlistedClasses;
+
+                info.jtaDataSource = persistenceUnit.getJtaDataSource();
+                info.nonJtaDataSource = persistenceUnit.getNonJtaDataSource();
+
+                info.jarFiles.addAll(persistenceUnit.getJarFile());
+                info.classes.addAll(persistenceUnit.getClazz());
+                info.mappingFiles.addAll(persistenceUnit.getMappingFile());
+
+                // Handle Properties
+                org.apache.openejb.jee.jpa.unit.Properties puiProperties = persistenceUnit.getProperties();
+                if (puiProperties != null) {
+                    for (Property property : puiProperties.getProperty()) {
+                        info.properties.put(property.getName(), property.getValue());
+                    }
+                }
+
+                logger.info("Configuring PersistenceUnit(name="+info.name+", provider="+info.provider+")");
+                // Persistence Unit Root Url
+                appInfo.persistenceUnits.add(info);
+            }
+        }
+    }
+
+    private static String getClientModuleId(ClientModule clientModule) {
+        String jarLocation = clientModule.getJarLocation();
+        File file = new File(jarLocation);
+        String name = file.getName();
+        if (name.endsWith(".jar") || name.endsWith(".zip")) {
+            name = name.replaceFirst("....$", "");
+        }
+        return name;
+    }
+
+
+    private List<PortInfo> configureWebservices(Webservices webservices) {
+        List<PortInfo> portMap = new ArrayList<PortInfo>();
+        if (webservices == null) {
+            return portMap;
+        }
+
+        for (WebserviceDescription desc : webservices.getWebserviceDescription()) {
+            String wsdlFile = desc.getWsdlFile();
+            String serviceName = desc.getWebserviceDescriptionName();
+
+            for (PortComponent port : desc.getPortComponent()) {
+                PortInfo portInfo = new PortInfo();
+
+                ServiceImplBean serviceImplBean = port.getServiceImplBean();
+                portInfo.serviceId = desc.getId();
+                portInfo.portId = port.getId();
+                portInfo.serviceLink = serviceImplBean.getEjbLink();
+                if (portInfo.serviceLink == null) {
+                    portInfo.serviceLink = serviceImplBean.getServletLink();
+                }
+
+                portInfo.seiInterfaceName = port.getServiceEndpointInterface();
+                portInfo.portName = port.getPortComponentName();
+                portInfo.binding = port.getProtocolBinding();
+                portInfo.serviceName = serviceName;
+                portInfo.wsdlFile = wsdlFile;
+                portInfo.mtomEnabled = port.isEnableMtom();
+                portInfo.wsdlPort = port.getWsdlPort();
+                portInfo.wsdlService = port.getWsdlService();
+                portInfo.location = port.getLocation();
+
+                List<HandlerChainInfo> handlerChains = ConfigurationFactory.toHandlerChainInfo(port.getHandlerChains());
+                portInfo.handlerChains.addAll(handlerChains);
+
+                // todo configure jaxrpc mappings here
+
+                portMap.add(portInfo);
+            }
+        }
+        return portMap;
+    }
+
+    private static boolean skipMdb(EnterpriseBeanInfo bean) {
+        return bean instanceof MessageDrivenBeanInfo && System.getProperty("duct tape") != null;
+    }
+
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ApplyOpenejbJar.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ApplyOpenejbJar.java?rev=602803&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ApplyOpenejbJar.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ApplyOpenejbJar.java Mon Dec 10 00:07:48 2007
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.ResourceRef;
+import org.apache.openejb.jee.ResourceEnvRef;
+import org.apache.openejb.jee.MessageDestinationRef;
+import org.apache.openejb.jee.EjbRef;
+import org.apache.openejb.jee.EjbLocalRef;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.oejb3.ResourceLink;
+import org.apache.openejb.jee.oejb3.EjbLink;
+
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ApplyOpenejbJar implements DynamicDeployer {
+
+    public AppModule deploy(AppModule appModule) throws OpenEJBException {
+
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+
+            Map<String, EjbDeployment> ejbDeployments = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
+
+            for (EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
+
+                // Get the OpenEJB deployment from openejb-jar.xml
+                EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
+
+                // Copy all links over to mappedName
+
+                for (ResourceRef ref : enterpriseBean.getResourceRef()) {
+                    ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
+                    if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
+                        ref.setMappedName(resourceLink.getResId());
+                    }
+                }
+
+                for (ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
+                    ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
+                    if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
+                        ref.setMappedName(resourceLink.getResId());
+                    }
+                }
+
+                for (MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
+                    ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
+                    if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
+                        ref.setMappedName(resourceLink.getResId());
+                    }
+                }
+
+                for (EjbRef ref : enterpriseBean.getEjbRef()) {
+                    EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
+                    if (ejbLink != null && ejbLink.getDeployentId() != null /* don't overwrite with null */) {
+                        ref.setMappedName(ejbLink.getDeployentId());
+                    }
+                }
+
+                for (EjbLocalRef ref : enterpriseBean.getEjbLocalRef()) {
+                    EjbLink ejbLink = ejbDeployment.getEjbLink(ref.getName());
+                    if (ejbLink != null && ejbLink.getDeployentId() != null /* don't overwrite with null */) {
+                        ref.setMappedName(ejbLink.getDeployentId());
+                    }
+                }
+            }
+        }
+
+        return appModule;
+    }
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java Mon Dec 10 00:07:48 2007
@@ -22,6 +22,7 @@
 import org.apache.openejb.assembler.classic.ContainerInfo;
 import org.apache.openejb.assembler.classic.ResourceInfo;
 import org.apache.openejb.assembler.classic.LinkResolver;
+import org.apache.openejb.assembler.classic.UniqueDefaultLinkResolver;
 import org.apache.openejb.jee.MessageDrivenBean;
 import org.apache.openejb.jee.ActivationConfig;
 import org.apache.openejb.jee.EnterpriseBean;
@@ -40,6 +41,8 @@
 import org.apache.openejb.jee.InboundResource;
 import org.apache.openejb.jee.MessageListener;
 import org.apache.openejb.jee.AdminObject;
+import org.apache.openejb.jee.PersistenceContextRef;
+import org.apache.openejb.jee.PersistenceRef;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
@@ -47,6 +50,8 @@
 import org.apache.openejb.jee.oejb3.ResourceLink;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.URISupport;
+import static org.apache.openejb.util.Join.join;
 
 import javax.sql.DataSource;
 import javax.jms.Queue;
@@ -60,6 +65,7 @@
 import java.util.TreeMap;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Collection;
 import java.net.URI;
 
 public class AutoConfig implements DynamicDeployer {
@@ -115,6 +121,8 @@
         }
         resolveDestinationLinks(appModule);
 
+        resolvePersistenceRefs(appModule);
+
         for (EjbModule ejbModule : appModule.getEjbModules()) {
             deploy(ejbModule, appResources);
         }
@@ -133,6 +141,131 @@
         return appModule;
     }
 
+    private void resolvePersistenceRefs(AppModule appModule) {
+        LinkResolver<PersistenceUnit> persistenceUnits = new UniqueDefaultLinkResolver<PersistenceUnit>();
+
+        for (PersistenceModule module : appModule.getPersistenceModules()) {
+            String rootUrl = module.getRootUrl();
+            for (PersistenceUnit unit : module.getPersistence().getPersistenceUnit()) {
+                unit.setId(rootUrl + "#" + unit.getName());
+                persistenceUnits.add(rootUrl, unit.getName(), unit);
+            }
+        }
+
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+            URI moduleURI = URI.create(ejbModule.getModuleId());
+
+            for (JndiConsumer component : ejbModule.getEjbJar().getEnterpriseBeans()) {
+                processPersistenceRefs(component, appModule, persistenceUnits, moduleURI);
+            }
+
+        }
+
+        for (ClientModule clientModule : appModule.getClientModules()) {
+            URI moduleURI = URI.create(clientModule.getModuleId());
+            processPersistenceRefs(clientModule.getApplicationClient(), appModule, persistenceUnits, moduleURI);
+        }
+
+        for (WebModule webModule : appModule.getWebModules()) {
+            URI moduleURI = URI.create(webModule.getModuleId());
+            processPersistenceRefs(webModule.getWebApp(), appModule, persistenceUnits, moduleURI);
+        }
+    }
+
+    private void processPersistenceRefs(JndiConsumer component, AppModule appModule, LinkResolver<PersistenceUnit> persistenceUnits, URI moduleURI) {
+
+        String componentName = component.getJndiConsumerName();
+
+        ValidationContext validation = appModule.getValidation();
+
+        for (PersistenceRef ref : component.getPersistenceUnitRef()) {
+
+            resolvePersistenceRef(persistenceUnits, ref, moduleURI, componentName, validation);
+        }
+
+        for (PersistenceRef ref : component.getPersistenceContextRef()) {
+
+            resolvePersistenceRef(persistenceUnits, ref, moduleURI, componentName, validation);
+        }
+    }
+
+    private PersistenceUnit resolvePersistenceRef(LinkResolver<PersistenceUnit> persistenceUnits, PersistenceRef ref, URI moduleURI, String componentName, ValidationContext validation) {
+        PersistenceUnit unit = persistenceUnits.resolveLink(ref.getPersistenceUnitName(), moduleURI);
+
+        // try again using the ref name
+        if (unit == null){
+            unit = persistenceUnits.resolveLink(ref.getName(), moduleURI);
+        }
+
+        // try again using the ref name with any prefix removed
+        if (unit == null){
+            String shortName = ref.getName().replaceFirst(".*/", "");
+            unit = persistenceUnits.resolveLink(shortName, moduleURI);
+        }
+
+        if (unit != null){
+            ref.setMappedName(unit.getId());
+        } else {
+
+            // ----------------------------------------------
+            //  Nothing was found.  Let's try and figure out
+            //  what went wrong and log a validation message
+            // ----------------------------------------------
+
+            String refType = "persistence";
+            if (ref instanceof PersistenceContextRef){
+                refType += "ContextRef";
+            } else refType += "UnitRef";
+
+            String refShortName = ref.getName();
+            if (refShortName.matches(".*\\..*/.*")){
+                refShortName = refShortName.replaceFirst(".*/", "");
+            }
+
+            List<String> availableUnits = new ArrayList<String>();
+            for (PersistenceUnit persistenceUnit : persistenceUnits.values()) {
+                availableUnits.add(persistenceUnit.getName());
+            }
+
+            Collections.sort(availableUnits);
+
+            String unitName = ref.getPersistenceUnitName();
+
+            if (availableUnits.size() == 0){
+                // Print a sample persistence.xml using their data
+                if (unitName == null){
+                    unitName = refShortName;
+                }
+                validation.fail(componentName, refType + ".noPersistenceUnits", refShortName, unitName);
+            } else if (ref.getPersistenceUnitName() == null && availableUnits.size() > 1) {
+                // Print a correct example of unitName in a ref
+                // DMB: Idea, the ability to set a default unit-name in openejb-jar.xml via a property
+                String sampleUnitName = availableUnits.get(0);
+                validation.fail(componentName, refType + ".noUnitName", refShortName, join(", ", availableUnits), sampleUnitName );
+            } else {
+                Collection<PersistenceUnit> vagueMatches = persistenceUnits.values(ref.getPersistenceUnitName());
+                if (vagueMatches.size() != 0) {
+                    // Print the full rootUrls
+
+                    List<String> possibleUnits = new ArrayList<String>();
+                    for (PersistenceUnit persistenceUnit : persistenceUnits.values()) {
+                        URI unitURI = URI.create(persistenceUnit.getId());
+                        unitURI = URISupport.relativize(moduleURI, unitURI);
+                        possibleUnits.add(unitURI.toString());
+                    }
+
+                    Collections.sort(possibleUnits);
+
+                    validation.fail(componentName, refType + ".vagueMatches", refShortName, unitName, possibleUnits.size(), join("\n", possibleUnits));
+                } else {
+                    validation.fail(componentName, refType + ".noMatches", refShortName, unitName, join(", ", availableUnits));
+                }
+            }
+        }
+        return unit;
+    }
+
+
     /**
      * Set destination, destinationType, clientId and subscriptionName in the MDB activation config.
      */
@@ -175,7 +308,7 @@
                     link.setResRefName("openejb/destination");
                     ejbDeployment.addResourceLink(link);
                 }
-                                
+
                 // destination type
                 String destinationType = properties.getProperty("destinationType");
                 if (destinationType == null && mdb.getMessageDestinationType() != null) {
@@ -287,7 +420,7 @@
                 }
             }
         }
-        
+
         // resolve all message destination refs with links and assign a ref id to the reference
         for (EjbModule ejbModule : appModule.getEjbModules()) {
             AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
@@ -979,7 +1112,7 @@
                 }
                 return allResourceIds;
             }
-            
+
             List<String> resourceIds = resourceIdsByType.get(type);
             if (resourceIds != null) {
                 return resourceIds;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Mon Dec 10 00:07:48 2007
@@ -23,17 +23,15 @@
 import org.apache.openejb.assembler.classic.ClientInfo;
 import org.apache.openejb.assembler.classic.CmpEntityContainerInfo;
 import org.apache.openejb.assembler.classic.ConnectionManagerInfo;
+import org.apache.openejb.assembler.classic.ConnectorInfo;
 import org.apache.openejb.assembler.classic.ContainerInfo;
 import org.apache.openejb.assembler.classic.ContainerSystemInfo;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
 import org.apache.openejb.assembler.classic.FacilitiesInfo;
 import org.apache.openejb.assembler.classic.JndiContextInfo;
 import org.apache.openejb.assembler.classic.MdbContainerInfo;
-import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
 import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory;
-import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
 import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
 import org.apache.openejb.assembler.classic.ResourceInfo;
 import org.apache.openejb.assembler.classic.SecurityServiceInfo;
@@ -41,14 +39,14 @@
 import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
 import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
 import org.apache.openejb.assembler.classic.TransactionServiceInfo;
-import org.apache.openejb.assembler.classic.ConnectorInfo;
 import org.apache.openejb.assembler.classic.WebAppInfo;
-import org.apache.openejb.assembler.classic.PortInfo;
 import org.apache.openejb.assembler.classic.HandlerChainInfo;
 import org.apache.openejb.assembler.classic.HandlerInfo;
-import org.apache.openejb.assembler.classic.ServletInfo;
+import org.apache.openejb.config.sys.AbstractService;
 import org.apache.openejb.config.sys.ConnectionManager;
 import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.sys.Deployments;
+import org.apache.openejb.config.sys.JaxbOpenejb;
 import org.apache.openejb.config.sys.JndiProvider;
 import org.apache.openejb.config.sys.Openejb;
 import org.apache.openejb.config.sys.ProxyFactory;
@@ -56,44 +54,18 @@
 import org.apache.openejb.config.sys.SecurityService;
 import org.apache.openejb.config.sys.ServiceProvider;
 import org.apache.openejb.config.sys.TransactionManager;
-import org.apache.openejb.config.sys.JaxbOpenejb;
-import org.apache.openejb.config.sys.AbstractService;
-import org.apache.openejb.config.sys.Deployments;
-import org.apache.openejb.jee.ApplicationClient;
 import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.Connector;
-import org.apache.openejb.jee.WebApp;
-import org.apache.openejb.jee.ResourceAdapter;
-import org.apache.openejb.jee.ConfigProperty;
-import org.apache.openejb.jee.OutboundResourceAdapter;
-import org.apache.openejb.jee.ConnectionDefinition;
-import org.apache.openejb.jee.InboundResource;
-import org.apache.openejb.jee.MessageListener;
-import org.apache.openejb.jee.AdminObject;
-import org.apache.openejb.jee.Webservices;
-import org.apache.openejb.jee.WebserviceDescription;
-import org.apache.openejb.jee.PortComponent;
-import org.apache.openejb.jee.ServiceImplBean;
+import org.apache.openejb.jee.HandlerChains;
 import org.apache.openejb.jee.HandlerChain;
 import org.apache.openejb.jee.Handler;
 import org.apache.openejb.jee.ParamValue;
-import org.apache.openejb.jee.HandlerChains;
-import org.apache.openejb.jee.Servlet;
-import org.apache.openejb.jee.jpa.EntityMappings;
-import org.apache.openejb.jee.jpa.JpaJaxbUtil;
-import org.apache.openejb.jee.jpa.unit.Persistence;
-import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
-import org.apache.openejb.jee.jpa.unit.Property;
-import org.apache.openejb.jee.oejb3.EjbDeployment;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.Messages;
 import org.apache.openejb.util.URISupport;
 
-import javax.xml.bind.JAXBException;
 import java.io.File;
-import java.net.URL;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -113,7 +85,6 @@
 
     private OpenEjbConfiguration sys;
 
-    private EjbJarInfoBuilder ejbJarInfoBuilder = new EjbJarInfoBuilder();
 
     private Openejb openejb;
 
@@ -130,6 +101,31 @@
         sys = configuration;
     }
 
+    public static List<HandlerChainInfo> toHandlerChainInfo(HandlerChains chains) {
+        List<HandlerChainInfo> handlerChains = new ArrayList<HandlerChainInfo>();
+        if (chains == null) return handlerChains;
+
+        for (HandlerChain handlerChain : chains.getHandlerChain()) {
+            HandlerChainInfo handlerChainInfo = new HandlerChainInfo();
+            handlerChainInfo.serviceNamePattern = handlerChain.getServiceNamePattern();
+            handlerChainInfo.portNamePattern = handlerChain.getPortNamePattern();
+            handlerChainInfo.protocolBindings.addAll(handlerChain.getProtocolBindings());
+            for (Handler handler : handlerChain.getHandler()) {
+                HandlerInfo handlerInfo = new HandlerInfo();
+                handlerInfo.handlerName = handler.getHandlerName();
+                handlerInfo.handlerClass = handler.getHandlerClass();
+                handlerInfo.soapHeaders.addAll(handler.getSoapHeader());
+                handlerInfo.soapRoles.addAll(handler.getSoapRole());
+                for (ParamValue param : handler.getInitParam()) {
+                    handlerInfo.initParams.setProperty(param.getParamName(), param.getParamValue());
+                }
+                handlerChainInfo.handlers.add(handlerInfo);
+            }
+            handlerChains.add(handlerChainInfo);
+        }
+        return handlerChains;
+    }
+
     public static class Chain implements DynamicDeployer{
         private final List<DynamicDeployer> chain = new ArrayList<DynamicDeployer>();
 
@@ -190,6 +186,8 @@
             chain.add(new AutoConfig(this));
         }
 
+        chain.add(new ApplyOpenejbJar());
+
         // TODO: How do we want this plugged in?
         //chain.add(new OutputGeneratedDescriptors());
         this.deployer = chain;
@@ -428,357 +426,9 @@
 
         logger.info(messages.format("config.configApp", appModule.getJarLocation()));
         deployer.deploy(appModule);
+        AppInfoBuilder appInfoBuilder = new AppInfoBuilder(this);
 
-        AppInfo appInfo = new AppInfo();
-        for (EjbModule ejbModule : appModule.getEjbModules()) {
-            try {
-                EjbJarInfo ejbJarInfo = ejbJarInfoBuilder.buildInfo(ejbModule);
-
-                Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
-
-                for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
-                    EjbDeployment d = deploymentsByEjbName.get(bean.ejbName);
-
-                    if (!getContainerIds().contains(d.getContainerId()) && !skipMdb(bean)) {
-                        String msg = messages.format("config.noContainerFound", d.getContainerId(), d.getEjbName());
-                        logger.fatal(msg);
-                        throw new OpenEJBException(msg);
-                    }
-
-                    bean.containerId = d.getContainerId();
-                }
-
-                ejbJarInfo.portInfos.addAll(configureWebservices(ejbModule.getWebservices()));
-
-                appInfo.ejbJars.add(ejbJarInfo);
-
-            } catch (OpenEJBException e) {
-                ConfigUtils.logger.warning("conf.0004", ejbModule.getJarLocation(), e.getMessage());
-                throw e;
-            }
-        }
-
-        for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
-            String rootUrl = persistenceModule.getRootUrl();
-            Persistence persistence = persistenceModule.getPersistence();
-            for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
-                PersistenceUnitInfo info = new PersistenceUnitInfo();
-                info.name = persistenceUnit.getName();
-                info.watchedResources.addAll(persistenceModule.getWatchedResources());
-                info.persistenceUnitRootUrl = rootUrl;
-                info.provider = persistenceUnit.getProvider();
-                info.transactionType = persistenceUnit.getTransactionType().toString();
-
-                Boolean excludeUnlistedClasses = persistenceUnit.isExcludeUnlistedClasses();
-                info.excludeUnlistedClasses = excludeUnlistedClasses != null && excludeUnlistedClasses;
-
-                info.jtaDataSource = persistenceUnit.getJtaDataSource();
-                info.nonJtaDataSource = persistenceUnit.getNonJtaDataSource();
-
-                info.jarFiles.addAll(persistenceUnit.getJarFile());
-                info.classes.addAll(persistenceUnit.getClazz());
-                info.mappingFiles.addAll(persistenceUnit.getMappingFile());
-
-                // Handle Properties
-                org.apache.openejb.jee.jpa.unit.Properties puiProperties = persistenceUnit.getProperties();
-                if (puiProperties != null) {
-                    for (Property property : puiProperties.getProperty()) {
-                        info.properties.put(property.getName(), property.getValue());
-                    }
-                }
-
-                logger.info("Configuring PersistenceUnit(name="+info.name+", provider="+info.provider+")");
-                // Persistence Unit Root Url
-                appInfo.persistenceUnits.add(info);
-            }
-        }
-
-        // process JNDI refs... all JNDI refs for the whole application
-        // must be processed at the same time
-        JndiEncInfoBuilder.initJndiReferences(appModule, appInfo);
-
-        for (ClientModule clientModule : appModule.getClientModules()) {
-            ApplicationClient applicationClient = clientModule.getApplicationClient();
-            ClientInfo clientInfo = new ClientInfo();
-            clientInfo.description = applicationClient.getDescription();
-            clientInfo.displayName = applicationClient.getDisplayName();
-            clientInfo.codebase = clientModule.getJarLocation();
-            clientInfo.mainClass = clientModule.getMainClass();
-            clientInfo.callbackHandler = applicationClient.getCallbackHandler();
-            clientInfo.moduleId = getClientModuleId(clientModule);
-            clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
-
-            JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo.ejbJars);
-            clientInfo.jndiEnc = jndiEncInfoBuilder.build(applicationClient, clientModule.getJarLocation(), clientInfo.moduleId);
-            appInfo.clients.add(clientInfo);
-        }
-
-        for (ConnectorModule connectorModule : appModule.getResourceModules()) {
-            //
-            // DEVELOPERS NOTE:  if you change the id generation code here, you must change
-            // the id generation code in AutoConfig$AppResources
-            //
-
-            Connector connector = connectorModule.getConnector();
-
-            ConnectorInfo connectorInfo = new ConnectorInfo();
-            connectorInfo.description = connector.getDescription();
-            connectorInfo.displayName = connector.getDisplayName();
-            connectorInfo.codebase = connectorModule.getJarLocation();
-            connectorInfo.moduleId = connectorModule.getModuleId();
-            connectorInfo.watchedResources.addAll(connectorModule.getWatchedResources());
-
-            List<URL> libraries = connectorModule.getLibraries();
-            for (URL url : libraries) {
-                File file = new File(url.getPath());
-                connectorInfo.libs.add(file.getAbsolutePath());
-            }
-
-            ResourceAdapter resourceAdapter = connector.getResourceAdapter();
-            if (resourceAdapter.getResourceAdapterClass() != null) {
-                ResourceInfo resourceInfo = new ResourceInfo();
-                resourceInfo.service = "Resource";
-                if (resourceAdapter.getId() != null) {
-                    resourceInfo.id = resourceAdapter.getId();
-                } else {
-                    resourceInfo.id = connectorModule.getModuleId() + "RA";
-                }
-                resourceInfo.className = resourceAdapter.getResourceAdapterClass();
-                resourceInfo.properties = new Properties();
-                for (ConfigProperty property : resourceAdapter.getConfigProperty()) {
-                    String name = property.getConfigPropertyName();
-                    String value = property.getConfigPropertyValue();
-                    if (value != null) {
-                        resourceInfo.properties.setProperty(name, value);
-                    }
-                }
-                resourceInfo.properties.putAll(getSystemProperties(resourceInfo.id, "RESOURCE"));
-                connectorInfo.resourceAdapter = resourceInfo;
-            }
-
-            OutboundResourceAdapter outbound = resourceAdapter.getOutboundResourceAdapter();
-            if (outbound != null) {
-                String transactionSupport = "none";
-                switch (outbound.getTransactionSupport()) {
-                    case LOCAL_TRANSACTION:
-                        transactionSupport = "local";
-                        break;
-                    case NO_TRANSACTION:
-                        transactionSupport = "none";
-                        break;
-                    case XA_TRANSACTION:
-                        transactionSupport = "xa";
-                        break;
-                }
-                for (ConnectionDefinition connection : outbound.getConnectionDefinition()) {
-                    ResourceInfo resourceInfo = new ResourceInfo();
-                    resourceInfo.service = "Resource";
-                    if (connection.getId() != null) {
-                        resourceInfo.id = connection.getId();
-                    } else if (outbound.getConnectionDefinition().size() == 1) {
-                        resourceInfo.id = connectorModule.getModuleId();
-                    } else {
-                        resourceInfo.id = connectorModule.getModuleId() + "-" + connection.getConnectionFactoryInterface();
-                    }
-                    resourceInfo.className = connection.getManagedConnectionFactoryClass();
-                    resourceInfo.types.add(connection.getConnectionFactoryInterface());
-                    resourceInfo.properties = new Properties();
-                    for (ConfigProperty property : connection.getConfigProperty()) {
-                        String name = property.getConfigPropertyName();
-                        String value = property.getConfigPropertyValue();
-                        if (value != null) {
-                            resourceInfo.properties.setProperty(name, value);
-                        }
-                    }
-                    resourceInfo.properties.setProperty("TransactionSupport", transactionSupport);
-                    resourceInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
-                    resourceInfo.properties.putAll(getSystemProperties(resourceInfo.id, "RESOURCE"));
-                    connectorInfo.outbound.add(resourceInfo);
-                }
-            }
-
-            InboundResource inbound = resourceAdapter.getInboundResourceAdapter();
-            if (inbound != null) {
-                for (MessageListener messageListener : inbound.getMessageAdapter().getMessageListener()) {
-                    MdbContainerInfo mdbContainerInfo = new MdbContainerInfo();
-                    mdbContainerInfo.service = "Container";
-                    if (messageListener.getId() != null) {
-                        mdbContainerInfo.id = messageListener.getId();
-                    } else if (inbound.getMessageAdapter().getMessageListener().size() == 1) {
-                        mdbContainerInfo.id = connectorModule.getModuleId();
-                    } else {
-                        mdbContainerInfo.id = connectorModule.getModuleId() + "-" + messageListener.getMessageListenerType();
-                    }
-
-                    mdbContainerInfo.properties = new Properties();
-                    mdbContainerInfo.properties.setProperty("ResourceAdapter", connectorInfo.resourceAdapter.id);
-                    mdbContainerInfo.properties.setProperty("MessageListenerInterface", messageListener.getMessageListenerType());
-                    mdbContainerInfo.properties.setProperty("ActivationSpecClass", messageListener.getActivationSpec().getActivationSpecClass());
-
-                    // todo provider system should fill in this information
-                    mdbContainerInfo.types.add("MESSAGE");
-                    mdbContainerInfo.className = "org.apache.openejb.core.mdb.MdbContainer";
-                    mdbContainerInfo.constructorArgs.addAll(Arrays.asList("id", "transactionManager", "securityService", "ResourceAdapter", "MessageListenerInterface", "ActivationSpecClass", "InstanceLimit"));
-                    mdbContainerInfo.properties.setProperty("InstanceLimit", "10");
-
-                    mdbContainerInfo.properties.putAll(getSystemProperties(mdbContainerInfo.id, "CONTAINER"));
-                    connectorInfo.inbound.add(mdbContainerInfo);
-                }
-            }
-
-            for (AdminObject adminObject : resourceAdapter.getAdminObject()) {
-                ResourceInfo resourceInfo = new ResourceInfo();
-                resourceInfo.service = "Resource";
-                if (adminObject.getId() != null) {
-                    resourceInfo.id = adminObject.getId();
-                } else if (resourceAdapter.getAdminObject().size() == 1) {
-                    resourceInfo.id = connectorModule.getModuleId();
-                } else {
-                    resourceInfo.id = connectorModule.getModuleId() + "-" + adminObject.getAdminObjectInterface();
-                }
-                resourceInfo.className = adminObject.getAdminObjectClass();
-                resourceInfo.types.add(adminObject.getAdminObjectInterface());
-                resourceInfo.properties = new Properties();
-                for (ConfigProperty property : adminObject.getConfigProperty()) {
-                    String name = property.getConfigPropertyName();
-                    String value = property.getConfigPropertyValue();
-                    if (value != null) {
-                        resourceInfo.properties.setProperty(name, value);
-                    }
-                }
-                resourceInfo.properties.putAll(getSystemProperties(resourceInfo.id, "RESOURCE"));
-                connectorInfo.adminObject.add(resourceInfo);
-            }
-
-            appInfo.connectors.add(connectorInfo);
-        }
-
-        for (WebModule webModule : appModule.getWebModules()) {
-            WebApp webApp = webModule.getWebApp();
-            WebAppInfo webAppInfo = new WebAppInfo();
-            webAppInfo.description = webApp.getDescription();
-            webAppInfo.displayName = webApp.getDisplayName();
-            webAppInfo.codebase = webModule.getJarLocation();
-            webAppInfo.moduleId = webModule.getModuleId();
-            webAppInfo.watchedResources.addAll(webModule.getWatchedResources());
-
-            webAppInfo.host = webModule.getHost();
-            webAppInfo.contextRoot = webModule.getContextRoot();
-
-            JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo.ejbJars);
-            webAppInfo.jndiEnc = jndiEncInfoBuilder.build(webApp, webModule.getJarLocation(), webAppInfo.moduleId);
-
-            webAppInfo.portInfos.addAll(configureWebservices(webModule.getWebservices()));
-
-            for (Servlet servlet : webModule.getWebApp().getServlet()) {
-                ServletInfo servletInfo = new ServletInfo();
-                servletInfo.servletName = servlet.getServletName();
-                servletInfo.servletClass = servlet.getServletClass();
-                webAppInfo.servlets.add(servletInfo);
-            }
-
-            appInfo.webApps.add(webAppInfo);
-        }
-
-        appInfo.jarPath = appModule.getJarLocation();
-        appInfo.watchedResources.addAll(appModule.getWatchedResources());
-        List<URL> additionalLibraries = appModule.getAdditionalLibraries();
-        for (URL url : additionalLibraries) {
-            File file = new File(url.getPath());
-            appInfo.libs.add(file.getAbsolutePath());
-        }
-
-        if (appModule.getCmpMappings() != null) {
-            try {
-                String cmpMappingsXml = JpaJaxbUtil.marshal(EntityMappings.class, appModule.getCmpMappings());
-                appInfo.cmpMappingsXml = cmpMappingsXml;
-            } catch (JAXBException e) {
-                throw new OpenEJBException("Unable to marshal cmp entity mappings", e);
-            }
-        }
-
-        ReportValidationResults reportValidationResults = new ReportValidationResults();
-        reportValidationResults.deploy(appModule);
-
-        logger.info("Loaded Module: " + appInfo.jarPath);
-        return appInfo;
-    }
-
-    private List<PortInfo> configureWebservices(Webservices webservices) {
-        List<PortInfo> portMap = new ArrayList<PortInfo>();
-        if (webservices == null) {
-            return portMap;
-        }
-
-        for (WebserviceDescription desc : webservices.getWebserviceDescription()) {
-            String wsdlFile = desc.getWsdlFile();
-            String serviceName = desc.getWebserviceDescriptionName();
-
-            for (PortComponent port : desc.getPortComponent()) {
-                PortInfo portInfo = new PortInfo();
-
-                ServiceImplBean serviceImplBean = port.getServiceImplBean();
-                portInfo.serviceId = desc.getId();
-                portInfo.portId = port.getId();
-                portInfo.serviceLink = serviceImplBean.getEjbLink();
-                if (portInfo.serviceLink == null) {
-                    portInfo.serviceLink = serviceImplBean.getServletLink();
-                }
-
-                portInfo.seiInterfaceName = port.getServiceEndpointInterface();
-                portInfo.portName = port.getPortComponentName();
-                portInfo.binding = port.getProtocolBinding();
-                portInfo.serviceName = serviceName;
-                portInfo.wsdlFile = wsdlFile;
-                portInfo.mtomEnabled = port.isEnableMtom();
-                portInfo.wsdlPort = port.getWsdlPort();
-                portInfo.wsdlService = port.getWsdlService();
-                portInfo.location = port.getLocation();
-
-                List<HandlerChainInfo> handlerChains = toHandlerChainInfo(port.getHandlerChains());
-                portInfo.handlerChains.addAll(handlerChains);
-
-                // todo configure jaxrpc mappings here
-
-                portMap.add(portInfo);
-            }
-        }
-        return portMap;
-    }
-
-    public static List<HandlerChainInfo> toHandlerChainInfo(HandlerChains chains) {
-        List<HandlerChainInfo> handlerChains = new ArrayList<HandlerChainInfo>();
-        if (chains == null) return handlerChains;
-
-        for (HandlerChain handlerChain : chains.getHandlerChain()) {
-            HandlerChainInfo handlerChainInfo = new HandlerChainInfo();
-            handlerChainInfo.serviceNamePattern = handlerChain.getServiceNamePattern();
-            handlerChainInfo.portNamePattern = handlerChain.getPortNamePattern();
-            handlerChainInfo.protocolBindings.addAll(handlerChain.getProtocolBindings());
-            for (Handler handler : handlerChain.getHandler()) {
-                HandlerInfo handlerInfo = new HandlerInfo();
-                handlerInfo.handlerName = handler.getHandlerName();
-                handlerInfo.handlerClass = handler.getHandlerClass();
-                handlerInfo.soapHeaders.addAll(handler.getSoapHeader());
-                handlerInfo.soapRoles.addAll(handler.getSoapRole());
-                for (ParamValue param : handler.getInitParam()) {
-                    handlerInfo.initParams.setProperty(param.getParamName(), param.getParamValue());
-                }
-                handlerChainInfo.handlers.add(handlerInfo);
-            }
-            handlerChains.add(handlerChainInfo);
-        }
-        return handlerChains;
-    }
-
-    private static String getClientModuleId(ClientModule clientModule) {
-        String jarLocation = clientModule.getJarLocation();
-        File file = new File(jarLocation);
-        String name = file.getName();
-        if (name.endsWith(".jar") || name.endsWith(".zip")) {
-            name = name.replaceFirst("....$", "");
-        }
-        return name;
+        return appInfoBuilder.build(appModule);
     }
 
     private static class DefaultService {
@@ -940,7 +590,7 @@
         return configureService(service, type);
     }
 
-    private Properties getSystemProperties(String serviceId, String serviceType) {
+    protected static Properties getSystemProperties(String serviceId, String serviceType) {
         String fullPrefix = serviceType.toUpperCase() + "." + serviceId + ".";
         String fullPrefix2 = serviceType.toUpperCase() + "." + serviceId + "|";
         String shortPrefix = serviceId + ".";
@@ -1097,10 +747,6 @@
 
     private OpenEjbConfiguration getRunningConfig() {
         return SystemInstance.get().getComponent(OpenEjbConfiguration.class);
-    }
-
-    private static boolean skipMdb(EnterpriseBeanInfo bean) {
-        return bean instanceof MessageDrivenBeanInfo && System.getProperty("duct tape") != null;
     }
 
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java Mon Dec 10 00:07:48 2007
@@ -33,9 +33,9 @@
 import org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo;
 import org.apache.openejb.assembler.classic.ResourceReferenceInfo;
 import org.apache.openejb.assembler.classic.ServiceReferenceInfo;
+import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
 import org.apache.openejb.jee.EjbLocalRef;
 import org.apache.openejb.jee.EjbRef;
-import org.apache.openejb.jee.EnterpriseBean;
 import org.apache.openejb.jee.EnvEntry;
 import org.apache.openejb.jee.Injectable;
 import org.apache.openejb.jee.InjectionTarget;
@@ -51,9 +51,6 @@
 import org.apache.openejb.jee.ResourceEnvRef;
 import org.apache.openejb.jee.ResourceRef;
 import org.apache.openejb.jee.ServiceRef;
-import org.apache.openejb.jee.oejb3.EjbDeployment;
-import org.apache.openejb.jee.oejb3.EjbLink;
-import org.apache.openejb.jee.oejb3.ResourceLink;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.Messages;
@@ -61,7 +58,6 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -71,78 +67,7 @@
  * @version $Rev$ $Date$
  */
 public class JndiEncInfoBuilder {
-    protected static void initJndiReferences(AppModule appModule, AppInfo appInfo) throws OpenEJBException {
-        // index ejb modules
-        Map<String, EjbModule> ejbModules = new TreeMap<String, EjbModule>();
-        for (EjbModule ejbModule : appModule.getEjbModules()) {
-            ejbModules.put(ejbModule.getModuleId(), ejbModule);
-        }
-
-        // Create the JNDI info builder
-        JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(appInfo.ejbJars);
-
-        // Build the JNDI tree for each ejb
-        for (EjbJarInfo ejbJar : appInfo.ejbJars) {
-            EjbModule ejbModule = ejbModules.get(ejbJar.moduleId);
-
-            // index jaxb objects
-            Map<String, EnterpriseBean> beanData = new TreeMap<String, EnterpriseBean>();
-            for (EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
-                beanData.put(enterpriseBean.getEjbName(), enterpriseBean);
-            }
-            Map<String, EjbDeployment> ejbDeployments = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
-
-            for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
-                String ejbName = beanInfo.ejbName;
-
-                // Get the ejb-jar.xml object
-                EnterpriseBean enterpriseBean = beanData.get(ejbName);
-
-                // Get the OpenEJB deployment
-                EjbDeployment ejbDeployment = ejbDeployments.get(ejbName);
-
-                // build the tree
-                initJndiReferences(enterpriseBean, ejbDeployment, beanInfo, jndiEncInfoBuilder, ejbJar.moduleId);
-            }
-        }
-    }
-
 
-    private static void initJndiReferences(EnterpriseBean enterpriseBean, EjbDeployment ejbDeployment, EnterpriseBeanInfo beanInfo, JndiEncInfoBuilder jndiEncInfoBuilder, String moduleId) throws OpenEJBException {
-        // Link all the resource refs
-        for (ResourceRef res : enterpriseBean.getResourceRef()) {
-            ResourceLink resourceLink = ejbDeployment.getResourceLink(res.getResRefName());
-            if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
-                res.setMappedName(resourceLink.getResId());
-            }
-        }
-
-        for (ResourceEnvRef ref : enterpriseBean.getResourceEnvRef()) {
-            ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getResourceEnvRefName());
-            if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
-                ref.setMappedName(resourceLink.getResId());
-            }
-        }
-
-        for (MessageDestinationRef ref : enterpriseBean.getMessageDestinationRef()) {
-            ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getMessageDestinationRefName());
-            if (resourceLink != null && resourceLink.getResId() != null /* don't overwrite with null */) {
-                ref.setMappedName(resourceLink.getResId());
-            }
-        }
-
-        // Link all the ejb refs
-        for (EjbRef ejbRef : enterpriseBean.getEjbRef()) {
-            EjbLink ejbLink = ejbDeployment.getEjbLink(ejbRef.getEjbRefName());
-            if (ejbLink != null && ejbLink.getDeployentId() != null /* don't overwrite with null */) {
-                ejbRef.setMappedName(ejbLink.getDeployentId());
-            }
-        }
-
-        // Build the JNDI info tree for the EJB
-        JndiEncInfo jndi = jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, moduleId);
-        beanInfo.jndiEnc = jndi;
-    }
 
     public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, JndiEncInfoBuilder.class);
     protected static final Messages messages = new Messages(JndiEncInfoBuilder.class);
@@ -153,12 +78,9 @@
     private final Map<Interfaces, String> remoteInterfaces = new TreeMap<Interfaces, String>();
     private final Map<Interfaces, String> localInterfaces = new TreeMap<Interfaces, String>();
 
-    public JndiEncInfoBuilder(EjbJarInfo... ejbJarInfos) {
-        this(Arrays.asList(ejbJarInfos));
-    }
+    public JndiEncInfoBuilder(AppInfo appInfo) {
 
-    public JndiEncInfoBuilder(Collection<EjbJarInfo> ejbJarInfos) {
-        for (EjbJarInfo ejbJarInfo : ejbJarInfos) {
+        for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
             for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
                 index(ejbJarInfo.moduleId, bean);
             }
@@ -218,9 +140,9 @@
 
         jndi.ejbLocalReferences.addAll(buildEjbLocalRefInfos(jndiConsumer, ejbName, moduleUri));
 
-        jndi.persistenceUnitRefs.addAll(buildPersistenceUnitRefInfos(jndiConsumer));
+        jndi.persistenceUnitRefs.addAll(buildPersistenceUnitRefInfos(jndiConsumer, moduleUri));
 
-        jndi.persistenceContextRefs.addAll(buildPersistenceContextRefInfos(jndiConsumer));
+        jndi.persistenceContextRefs.addAll(buildPersistenceContextRefInfos(jndiConsumer, moduleUri));
 
         jndi.serviceRefs.addAll(buildServiceRefInfos(jndiConsumer));
 
@@ -257,7 +179,7 @@
         return infos;
     }
 
-    private List<PersistenceUnitReferenceInfo> buildPersistenceUnitRefInfos(JndiConsumer jndiConsumer) {
+    private List<PersistenceUnitReferenceInfo> buildPersistenceUnitRefInfos(JndiConsumer jndiConsumer, URI moduleId) {
         ArrayList<PersistenceUnitReferenceInfo> infos = new ArrayList<PersistenceUnitReferenceInfo>();
         for (PersistenceUnitRef puRef : jndiConsumer.getPersistenceUnitRef()) {
             PersistenceUnitReferenceInfo info = new PersistenceUnitReferenceInfo();
@@ -270,7 +192,7 @@
         return infos;
     }
 
-    private List<PersistenceContextReferenceInfo> buildPersistenceContextRefInfos(JndiConsumer jndiConsumer) {
+    private List<PersistenceContextReferenceInfo> buildPersistenceContextRefInfos(JndiConsumer jndiConsumer, URI moduleId) {
         ArrayList<PersistenceContextReferenceInfo> infos = new ArrayList<PersistenceContextReferenceInfo>();
 
         for (PersistenceContextRef contextRef : jndiConsumer.getPersistenceContextRef()) {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?rev=602803&r1=602802&r2=602803&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Mon Dec 10 00:07:48 2007
@@ -61,6 +61,8 @@
         this.classLoader = classLoader;
         this.jarLocation = jarLocation;
 
+        if (webApp != null) webApp.setContextRoot(contextRoot);
+
         if (moduleId == null){
             if (webApp != null && webApp.getId() != null){
                 moduleId = webApp.getId();
@@ -95,6 +97,7 @@
 
     public void setWebApp(WebApp webApp) {
         this.webApp = webApp;
+        if (webApp != null) webApp.setContextRoot(contextRoot);
     }
 
     public Webservices getWebservices() {
@@ -127,6 +130,7 @@
     }
 
     public void setContextRoot(String contextRoot) {
+        if (webApp != null) webApp.setContextRoot(contextRoot);
         this.contextRoot = contextRoot;
     }