tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r504792 - in /incubator/openejb/trunk/openejb3/container/openejb-core: ./ src/main/java/org/apache/openejb/ src/main/java/org/apache/openejb/assembler/ src/main/java/org/apache/openejb/assembler/classic/ src/main/java/org/apache/openejb/con...
Date Thu, 08 Feb 2007 05:39:05 GMT
Author: dain
Date: Wed Feb  7 21:39:04 2007
New Revision: 504792

URL: http://svn.apache.org/viewvc?view=rev&rev=504792
Log:
Hacked in a system ejb that can do deployment

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/ejb-jar.xml
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ResourceModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml Wed Feb  7 21:39:04 2007
@@ -118,7 +118,7 @@
               <!--<addClasspath>true</addClasspath>-->
             </manifest>
             <manifestEntries>
-              <Class-Path>openejb-loader-${version}.jar xbean-finder-2.8.jar</Class-Path>
+              <Class-Path>openejb-loader-${version}.jar openejb-client-${version}.jar xbean-finder-2.8.jar</Class-Path>
               <J2EE-DeploymentFactory-Implementation-Class>org.apache.openejb.config.VmDeploymentFactory</J2EE-DeploymentFactory-Implementation-Class>
             </manifestEntries>
           </archive>

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java Wed Feb  7 21:39:04 2007
@@ -130,6 +130,8 @@
                 throw new OpenEJBException(msg, t);
             }
 
+            SystemInstance.get().setComponent(Assembler.class, assembler);
+
             try {
                 assembler.init(props);
             } catch (OpenEJBException oe) {
@@ -248,6 +250,8 @@
             if (nobanner == null && (loader == null || (loader != null && loader.startsWith("tomcat")))) {
                 System.out.println(messages.message("startup.ready"));
             }
+
+            // todo hack
 
         }
     }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java Wed Feb  7 21:39:04 2007
@@ -18,6 +18,7 @@
 
 import java.util.List;
 import java.util.ArrayList;
+import java.io.PrintStream;
 
 /**
  * @version $Rev$ $Date$
@@ -43,5 +44,14 @@
 
     public List<Throwable> getCauses() {
         return causes;
+    }
+
+    public void printStackTrace(PrintStream s) {
+        super.printStackTrace(s);
+
+        for (Throwable throwable : causes) {
+            s.print("Nested caused by: ");
+            throwable.printStackTrace(s);
+        }
     }
 }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java?view=auto&rev=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java Wed Feb  7 21:39:04 2007
@@ -0,0 +1,42 @@
+/**
+ * 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.assembler;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import org.apache.openejb.NoSuchApplicationException;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.assembler.classic.AppInfo;
+
+public interface Deployer {
+    String FILENAME = "filename";
+    String ALT_DD = "altDD";
+
+    String getUniqueFile();
+
+    Collection<AppInfo> getDeployedApps();
+
+    AppInfo deploy(String location) throws OpenEJBException;
+
+    AppInfo deploy(Properties properties) throws OpenEJBException;
+
+    AppInfo deploy(String location, Properties properties) throws OpenEJBException;
+
+    void undeploy(String moduleId) throws UndeployException, NoSuchApplicationException;
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?view=auto&rev=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java Wed Feb  7 21:39:04 2007
@@ -0,0 +1,155 @@
+/**
+ * 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.assembler;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.SecureRandom;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.apache.openejb.NoSuchApplicationException;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.DeploymentLoader;
+import org.apache.openejb.config.DeploymentModule;
+import org.apache.openejb.loader.SystemInstance;
+
+@Stateless(name = "openejb/Deployer")
+@Remote(Deployer.class)
+public class DeployerEjb implements Deployer {
+    private final static File uniqueFile;
+
+    static {
+        String uniqueName = "OpenEJB-" + new BigInteger(128, new SecureRandom()).toString(Character.MAX_RADIX);
+        String tempDir = System.getProperty("java.io.tmpdir");
+        uniqueFile = new File(tempDir, uniqueName);
+        try {
+            uniqueFile.createNewFile();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        uniqueFile.deleteOnExit();
+    }
+
+    private final DeploymentLoader deploymentLoader;
+    private final ConfigurationFactory configurationFactory;
+    private final Assembler assembler;
+
+    public DeployerEjb() {
+        deploymentLoader = new DeploymentLoader();
+        configurationFactory = new ConfigurationFactory();
+        assembler = (Assembler) SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
+    }
+
+    public String getUniqueFile() {
+        return uniqueFile.getAbsolutePath();
+    }
+
+    public Collection<AppInfo> getDeployedApps() {
+        return assembler.getDeployedApplications();
+    }
+
+    public AppInfo deploy(String location) throws OpenEJBException {
+        return deploy(location, null);
+    }
+
+    public AppInfo deploy(Properties properties) throws OpenEJBException {
+        return deploy(null, properties);
+    }
+
+    public AppInfo deploy(String location, Properties properties) throws OpenEJBException {
+        if (location == null && properties == null) {
+            throw new NullPointerException("location and properties are null");
+        }
+        if (location == null) {
+            location = properties.getProperty(FILENAME);
+        }
+        if (properties == null) {
+            properties = new Properties();
+        }
+
+        try {
+            File file = new File(location);
+            AppModule appModule = deploymentLoader.load(file);
+
+            // Add any alternate deployment descriptors to the modules
+            Map<String, DeploymentModule> modules = new TreeMap<String, DeploymentModule>();
+            for (DeploymentModule module : appModule.getEjbModules()) {
+                modules.put(module.getModuleId(), module);
+            }
+            for (DeploymentModule module : appModule.getClientModules()) {
+                modules.put(module.getModuleId(), module);
+            }
+            for (DeploymentModule module : appModule.getWebModules()) {
+                modules.put(module.getModuleId(), module);
+            }
+            for (DeploymentModule module : appModule.getResourceModules()) {
+                modules.put(module.getModuleId(), module);
+            }
+
+            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+                String name = (String) entry.getKey();
+                if (name.startsWith(ALT_DD + "/")) {
+                    name = name.substring(ALT_DD.length() + 1);
+
+                    DeploymentModule module;
+                    int slash = name.indexOf('/');
+                    if (slash > 0) {
+                        String moduleId = name.substring(0, slash);
+                        name = name.substring(slash + 1);
+                        module = modules.get(moduleId);
+                    } else {
+                        module = appModule;
+                    }
+
+                    if (module != null) {
+                        String value = (String) entry.getValue();
+                        File dd = new File(value);
+                        if (dd.canRead()) {
+                            module.getAltDDs().put(name, dd.toURL());
+                        } else {
+                            module.getAltDDs().put(name, value);
+                        }
+                    }
+                }
+            }
+
+            AppInfo appInfo = configurationFactory.configureApplication(appModule);
+            assembler.createApplication(appInfo);
+
+            return appInfo;
+        } catch (OpenEJBException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new OpenEJBException(e);
+        }
+    }
+
+    public void undeploy(String moduleId) throws UndeployException, NoSuchApplicationException {
+        assembler.destroyApplication(moduleId);
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Wed Feb  7 21:39:04 2007
@@ -66,6 +66,8 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.TreeMap;
+import java.util.Collections;
+import java.util.Collection;
 
 public class Assembler extends AssemblerTool implements org.apache.openejb.spi.Assembler {
 
@@ -78,6 +80,8 @@
     private TransactionManager transactionManager;
     private SecurityService securityService;
     private OpenEjbConfigurationFactory configFactory;
+    private final Map<String, AppInfo> deployedApplications = new HashMap<String, AppInfo>();
+
 
     public org.apache.openejb.spi.ContainerSystem getContainerSystem() {
         return containerSystem;
@@ -280,6 +284,10 @@
         }
     }
 
+    public Collection<AppInfo> getDeployedApplications() {
+        return new ArrayList<AppInfo>(deployedApplications.values());
+    }
+
     public void createEjbJar(EjbJarInfo ejbJar) throws NamingException, IOException, OpenEJBException {
         AppInfo appInfo = new AppInfo();
         appInfo.jarPath = ejbJar.jarPath;
@@ -314,7 +322,7 @@
 
     public void createApplication(AppInfo appInfo, ClassLoader classLoader) throws OpenEJBException, IOException, NamingException {
 
-        List<String> used = new ArrayList();
+        List<String> used = new ArrayList<String>();
         for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
             for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
                 if (containerSystem.getDeploymentInfo(beanInfo.ejbDeploymentId) != null) {
@@ -344,8 +352,7 @@
             classLoader = new URLClassLoader(new URL []{generatedJar.toURL()}, classLoader);
         }
 
-        AssemblyUnit unit = new AssemblyUnit(appInfo.jarPath);
-        assemblyUnits.put(appInfo.jarPath, unit);
+        deployedApplications.put(appInfo.jarPath, appInfo);
 
         // JPA - Persistence Units MUST be processed first since they will add ClassFileTransformers
         // to the class loader which must be added before any classes are loaded
@@ -369,13 +376,12 @@
         EjbJarBuilder ejbJarBuilder = new EjbJarBuilder(props, classLoader);
         for (EjbJarInfo ejbJar : appInfo.ejbJars) {
             HashMap<String, DeploymentInfo> deployments = ejbJarBuilder.build(ejbJar, allFactories);
-            RoleMapping roleMapping = new RoleMapping(new ArrayList());
+            RoleMapping roleMapping = new RoleMapping(new ArrayList<RoleMappingInfo>());
             for (DeploymentInfo deploymentInfo : deployments.values()) {
                 applyMethodPermissions((CoreDeploymentInfo) deploymentInfo, ejbJar.methodPermissions, roleMapping);
                 applyTransactionAttributes((CoreDeploymentInfo) deploymentInfo, ejbJar.methodTransactions);
                 containerSystem.addDeployment(deploymentInfo);
                 jndiBuilder.bind(deploymentInfo);
-                unit.deployments.add((CoreDeploymentInfo) deploymentInfo);
             }
 
             for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
@@ -386,8 +392,7 @@
 
         // App Client
         for (ClientInfo clientInfo : appInfo.clients) {
-            unit.clientIds.add(clientInfo.moduleId);
-            JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc);
+            JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, clientInfo.moduleId);
             Context context = (Context) jndiEncBuilder.build().lookup("env");
             containerSystem.getJNDIContext().bind("java:openejb/client/" + clientInfo.moduleId + "/comp/env", context);
             if (clientInfo.codebase != null) {
@@ -414,12 +419,84 @@
     }
 
     public void destroyApplication(String filePath) throws UndeployException, NoSuchApplicationException {
-        AssemblyUnit unit = assemblyUnits.get(filePath);
-        if (unit == null) {
+        AppInfo appInfo = deployedApplications.remove(filePath);
+        if (appInfo == null) {
             throw new NoSuchApplicationException(filePath);
         }
-        unit.destroy();
-        assemblyUnits.remove(filePath);
+        destroyApplication(appInfo);
+    }
+
+    private void destroyApplication(AppInfo appInfo) throws UndeployException {
+        Context globalContext = containerSystem.getJNDIContext();
+        UndeployException undeployException = new UndeployException("Failed undeploying application: id=" + appInfo.jarPath);
+
+        // get all of the ejb deployments
+        List<CoreDeploymentInfo> deployments = new ArrayList<CoreDeploymentInfo>();
+        for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
+            for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
+                String deploymentId = beanInfo.ejbDeploymentId;
+                CoreDeploymentInfo deployment = (CoreDeploymentInfo) containerSystem.getDeploymentInfo(deploymentId);
+                if (deployment == null) {
+                    undeployException.getCauses().add(new Exception("deployment not found: " + deploymentId));
+                }
+                deployments.add(deployment);
+            }
+        }
+
+        // get the client ids
+        List<String> clientIds = new ArrayList<String>();
+        for (ClientInfo clientInfo : appInfo.clients) {
+            clientIds.add(clientInfo.moduleId);
+        }
+
+        // Clear out naming for all components first
+        for (CoreDeploymentInfo deployment : deployments) {
+            String deploymentID = deployment.getDeploymentID() + "";
+            try {
+                containerSystem.removeDeploymentInfo(deployment);
+            } catch (Throwable t) {
+                undeployException.getCauses().add(new Exception(deploymentID, t));
+            }
+
+            JndiBuilder.Bindings bindings = deployment.get(JndiBuilder.Bindings.class);
+            for (String name : bindings.getBindings()) {
+                try {
+                    globalContext.lookup("openejb/ejb/" + name);
+                    globalContext.unbind("/openejb/ejb/" + name);
+                    try {
+                        globalContext.lookup("openejb/ejb/" + name);
+                        throw new OpenEJBException("Unbind failed: " + name);
+                    } catch (NamingException goodAndExpected) {
+                    }
+                } catch (Throwable t) {
+                    undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
+                }
+            }
+        }
+        for (CoreDeploymentInfo deployment : deployments) {
+            String deploymentID = deployment.getDeploymentID() + "";
+            try {
+                Container container = deployment.getContainer();
+                container.undeploy(deployment);
+                deployment.setContainer(null);
+            } catch (Throwable t) {
+                undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
+            } finally {
+                deployment.setDestroyed(true);
+            }
+        }
+        deployments.clear();
+
+        for (String clientId : clientIds) {
+            try {
+                globalContext.unbind("/openejb/client/" + clientId);
+            } catch (Throwable t) {
+                undeployException.getCauses().add(new Exception("client: " + clientId + ": " + t.getMessage(), t));
+            }
+        }
+        if (undeployException.getCauses().size() > 0) {
+            throw undeployException;
+        }
     }
 
     public ClassLoader createAppClassLoader(AppInfo appInfo) throws OpenEJBException, IOException {
@@ -650,14 +727,14 @@
         if (transactionManager instanceof TransactionSynchronizationRegistry) {
             synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
         } else {
-            // todo this sould be built
+            // todo this should be built
             synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
         }
         Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
         SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, synchronizationRegistry);
 
         // JtaEntityManagerRegistry
-        // todo this sould be built
+        // todo this should be built
         JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
         Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), jtaEntityManagerRegistry);
         SystemInstance.get().setComponent(JtaEntityManagerRegistry.class, jtaEntityManagerRegistry);
@@ -671,7 +748,6 @@
         }
     }
 
-
     private static class PersistenceClassLoaderHandlerImpl implements PersistenceClassLoaderHandler {
         public void addTransformer(ClassLoader classLoader, ClassFileTransformer classFileTransformer) {
             Instrumentation instrumentation = Agent.getInstrumentation();
@@ -682,71 +758,6 @@
 
         public ClassLoader getNewTempClassLoader(ClassLoader classLoader) {
             return new TemporaryClassLoader(classLoader);
-        }
-    }
-
-    private final Map<String, AssemblyUnit> assemblyUnits = new HashMap<String, AssemblyUnit>();
-
-    private final class AssemblyUnit {
-        private final List<CoreDeploymentInfo> deployments = new ArrayList<CoreDeploymentInfo>();
-        private final List<String> clientIds = new ArrayList<String>();
-        private final String appId;
-
-        public AssemblyUnit(String appId) {
-            this.appId = appId;
-        }
-
-        private void destroy() throws UndeployException {
-            Context globalContext = containerSystem.getJNDIContext();
-            UndeployException undeployException = new UndeployException("Failed undeploying application: id=" + appId);
-            // Clear out naming for all components first
-            for (CoreDeploymentInfo deployment : deployments) {
-                String deploymentID = deployment.getDeploymentID() + "";
-                try {
-                    containerSystem.removeDeploymentInfo(deployment);
-                } catch (Throwable t) {
-                    undeployException.getCauses().add(new Exception(deploymentID, t));
-                }
-
-                JndiBuilder.Bindings bindings = deployment.get(JndiBuilder.Bindings.class);
-                for (String name : bindings.getBindings()) {
-                    try {
-                        globalContext.lookup("openejb/ejb/" + name);
-                        globalContext.unbind("/openejb/ejb/" + name);
-                        try {
-                            globalContext.lookup("openejb/ejb/" + name);
-                            throw new OpenEJBException("Unbind failed: " + name);
-                        } catch (NamingException goodAndExpected) {
-                        }
-                    } catch (Throwable t) {
-                        undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
-                    }
-                }
-            }
-            for (CoreDeploymentInfo deployment : deployments) {
-                String deploymentID = deployment.getDeploymentID() + "";
-                try {
-                    Container container = deployment.getContainer();
-                    container.undeploy(deployment);
-                    deployment.setContainer(null);
-                } catch (Throwable t) {
-                    undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
-                } finally {
-                    deployment.setDestroyed(true);
-                }
-            }
-            deployments.clear();
-
-            for (String clientId : clientIds) {
-                try {
-                    globalContext.unbind("/openejb/client/" + clientId);
-                } catch (Throwable t) {
-                    undeployException.getCauses().add(new Exception("client: " + clientId + ": " + t.getMessage(), t));
-                }
-            }
-            if (undeployException.getCauses().size() > 0) {
-                throw undeployException;
-            }
         }
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java Wed Feb  7 21:39:04 2007
@@ -65,8 +65,8 @@
     private final JndiEncInfo jndiEnc;
 
 
-    public JndiEncBuilder(JndiEncInfo jndiEnc) throws OpenEJBException {
-        this(jndiEnc, null, null, null,null);
+    public JndiEncBuilder(JndiEncInfo jndiEnc, String moduleId) throws OpenEJBException {
+        this(jndiEnc, null, null, null, moduleId);
     }
 
     public JndiEncBuilder(JndiEncInfo jndiEnc, String transactionType, BeanType ejbType, Map<String, Map<String, EntityManagerFactory>> allFactories, String path) throws OpenEJBException {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java Wed Feb  7 21:39:04 2007
@@ -21,6 +21,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
+import java.io.File;
 
 import org.apache.openejb.jee.jpa.EntityMappings;
 
@@ -33,15 +34,22 @@
     private final List<WebModule> webModules = new ArrayList<WebModule>();
     private final List<ClientModule> clientModules = new ArrayList<ClientModule>();
     private final List<EjbModule> ejbModules = new ArrayList<EjbModule>();
-    private final List<PersistenceModule> persistenceModules = new ArrayList<PersistenceModule>();;
+    private final List<PersistenceModule> persistenceModules = new ArrayList<PersistenceModule>();
     private final String jarLocation;
     private final ClassLoader classLoader;
     private EntityMappings cmpMappings;
     private final Map<String,Object> altDDs = new HashMap<String,Object>();
+    private final String moduleId;
 
     public AppModule(ClassLoader classLoader, String jarLocation) {
         this.classLoader = classLoader;
         this.jarLocation = jarLocation;
+        File file = new File(jarLocation);
+        moduleId = file.getName();
+    }
+
+    public String getModuleId() {
+        return moduleId;
     }
 
     public Map<String, Object> getAltDDs() {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java Wed Feb  7 21:39:04 2007
@@ -47,10 +47,6 @@
         this.moduleId = moduleId;
     }
 
-    public ClientModule(ApplicationClient applicationClient, ClassLoader classLoader, String jarLocation, String mainClass) {
-        this(applicationClient, classLoader, jarLocation, mainClass, null);
-    }
-
     public String getModuleId() {
         return moduleId;
     }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java Wed Feb  7 21:39:04 2007
@@ -22,7 +22,8 @@
  * @version $Rev$ $Date$
  */
 public interface DeploymentModule {
-    public ClassLoader getClassLoader();
-    public String getJarLocation();
-    public Map<String,Object> getAltDDs();
+    String getModuleId();
+    ClassLoader getClassLoader();
+    String getJarLocation();
+    Map<String,Object> getAltDDs();
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java Wed Feb  7 21:39:04 2007
@@ -30,7 +30,6 @@
  * @version $Revision$ $Date$
  */
 public class EjbModule implements DeploymentModule {
-
     private ClassLoader classLoader;
     private String jarURI;
     private EjbJar ejbJar;
@@ -38,7 +37,7 @@
     private String moduleId;
     private final Map<String,Object> altDDs = new HashMap<String,Object>();
 
-    public EjbModule(ClassLoader classLoader, String moduleName, String jarURI, EjbJar ejbJar, OpenejbJar openejbJar) {
+    public EjbModule(ClassLoader classLoader, String moduleId, String jarURI, EjbJar ejbJar, OpenejbJar openejbJar) {
         if (classLoader == null) {
             throw new NullPointerException("classLoader is null");
         }
@@ -47,10 +46,11 @@
         this.jarURI = jarURI;
         this.openejbJar = openejbJar;
 
-        if (moduleName == null){
+        if (moduleId == null){
             File file = new File(jarURI);
             moduleId = file.getName();
         }
+        this.moduleId = moduleId;
     }
 
     public EjbModule(ClassLoader classLoader, String jarURI, EjbJar ejbJar, OpenejbJar openejbJar) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java Wed Feb  7 21:39:04 2007
@@ -26,6 +26,8 @@
  * @version $Rev$ $Date$
  */
 public class RemoteServer {
+    private static final boolean DEBUG = System.getProperty("openejb.server.debug","false").equalsIgnoreCase("TRUE");
+
     /**
      * Has the remote server's instance been already running ?
      */
@@ -96,7 +98,7 @@
                 //DMB: If you don't use an array, you get problems with jar paths containing spaces
                 // the command won't parse correctly
                 String[] args;
-                if (System.getProperty("openejb.server.debug","false").equalsIgnoreCase("TRUE")) {
+                if (DEBUG) {
                     args = new String[]{"java",
                             "-Xdebug",
                             "-Xnoagent",
@@ -124,7 +126,11 @@
             } catch (Exception e) {
                 throw (RuntimeException)new RuntimeException("Cannot start the server.  Exception: "+e.getClass().getName()+": "+e.getMessage()).initCause(e);
             }
-            connect(10);
+            if (DEBUG) {
+                connect(Integer.MAX_VALUE);
+            } else {
+                connect(10);
+            }
         } else {
             //System.out.println("[] SERVER STARTED");
         }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ResourceModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ResourceModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ResourceModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ResourceModule.java Wed Feb  7 21:39:04 2007
@@ -22,6 +22,9 @@
  * @version $Rev$ $Date$
  */
 public class ResourceModule implements DeploymentModule {
+    public String getModuleId() {
+        throw new UnsupportedOperationException();
+    }
 
     public Map<String, Object> getAltDDs() {
         throw new UnsupportedOperationException();

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/VmDeploymentManager.java Wed Feb  7 21:39:04 2007
@@ -16,6 +16,26 @@
  */
 package org.apache.openejb.config;
 
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.Arrays;
 import javax.enterprise.deploy.model.DeployableObject;
 import javax.enterprise.deploy.shared.ActionType;
 import javax.enterprise.deploy.shared.CommandType;
@@ -35,75 +55,80 @@
 import javax.enterprise.deploy.spi.status.ProgressEvent;
 import javax.enterprise.deploy.spi.status.ProgressListener;
 import javax.enterprise.deploy.spi.status.ProgressObject;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.io.StringWriter;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
+import javax.naming.InitialContext;
 
-public class VmDeploymentManager implements DeploymentManager {
-    public static final String MODULE_TYPE = "moduleType";
-    public static final String MODULE_ID = "moduleId";
-    public static final String FILENAME = "filename";
+import org.apache.openejb.NoSuchApplicationException;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.ClientInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.InfoObject;
+import org.apache.openejb.assembler.Deployer;
 
-    private static final Target DEFAULT_TARGET = new TargetImpl("DefaultTarget", null);
+public class VmDeploymentManager implements DeploymentManager {
+    private static final Target DEFAULT_TARGET = new TargetImpl("DefaultTarget", "OpenEJB Default Target");
     private static final DConfigBeanVersionType DCONFIG_BEAN_VERSION = DConfigBeanVersionType.V1_4;
     private static final Locale LOCALE = Locale.getDefault();
 
     private boolean connected = true;
-    private final SortedMap<TargetModuleID, Properties> deployed = new TreeMap<TargetModuleID, Properties>();
-    private final SortedSet<TargetModuleID> running = new TreeSet<TargetModuleID>();
-    private final File beansDir;
-    private final File appsDir;
-    private RemoteServer remoteServer;
+    private Deployer deployer;
+    private final String openejbUri;
+    private boolean deployerLocal;
 
     public VmDeploymentManager() {
         String openejbHome = System.getProperty("openejb.home", "target/openejb-3.0-incubating-SNAPSHOT");
         File openejbHomeDir = new File(openejbHome);
-        assertIsDirectory(openejbHomeDir, "beans");
-        beansDir = new File(openejbHomeDir, "beans");
-        assertIsDirectory(beansDir, "beans");
-        appsDir = new File(openejbHomeDir, "apps");
+        if (!openejbHomeDir.exists()) {
+            throw new IllegalArgumentException("OpenEJB home dir does not exist: " + openejbHomeDir);
+        }
+        if (!openejbHomeDir.isDirectory()) {
+            throw new IllegalArgumentException("OpenEJB home dir is not a directory: " + openejbHomeDir);
+        }
+
+        String openejbUri = System.getProperty("openejb.server.uri");
+        if (openejbUri == null) {
+            try {
+                openejbUri = new URI("ejb", null, "localhost", 4201, null, null, null).toString();
+            } catch (URISyntaxException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        this.openejbUri = openejbUri;
 
-        remoteServer = new RemoteServer();
     }
 
-    private static void assertIsDirectory(File beansDir, String variableName) {
-        if (!beansDir.exists()) {
-            throw new IllegalArgumentException(variableName + " dir does not exist: " + beansDir);
+    private Deployer getDeployer() {
+        if (deployer == null) {
+            try {
+                Properties p = new Properties();
+                p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
+                p.put("java.naming.provider.url", openejbUri);
+
+                InitialContext ctx = new InitialContext(p);
+                deployer = (Deployer) ctx.lookup("openejb/DeployerBusinessRemote");
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }
-        if (!beansDir.isDirectory()) {
-            throw new IllegalArgumentException(variableName + " dir is not a directory: " + beansDir);
+        return deployer;
+    }
+
+    private boolean isDeployerLocal() {
+        if (deployer == null) {
+            deployerLocal = new File(getDeployer().getUniqueFile()).exists();            
         }
+        return deployerLocal;
     }
 
     public void release() {
         connected = false;
-        remoteServer.destroy();
-        remoteServer = null;
     }
 
     public Target[] getTargets() {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
-        return new Target[] { DEFAULT_TARGET };
+        return new Target[]{DEFAULT_TARGET};
     }
 
 
@@ -114,57 +139,101 @@
             return null;
         }
 
-        Set<TargetModuleID> modules = new HashSet<TargetModuleID>(deployed.keySet());
-        filterModulesByType(modules, moduleType);
-        return modules.toArray(new TargetModuleID[modules.size()]);
+        Set<TargetModuleID> targetModuleIds = toTargetModuleIds(getDeployer().getDeployedApps(), moduleType);
+        return targetModuleIds.toArray(new TargetModuleID[targetModuleIds.size()]);
     }
 
-    public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] targetList) throws TargetException {
-        if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
+    private static Set<TargetModuleID> toTargetModuleIds(Collection<AppInfo> deployedApps, ModuleType allowedModuleType) {
+        Set<TargetModuleID> targetModuleIds = new HashSet<TargetModuleID>(deployedApps.size());
+        for (AppInfo deployedApp : deployedApps) {
+            TargetModuleID moduleId = toTargetModuleId(deployedApp, allowedModuleType);
+            // moduleID will be null if the module was filtered
+            if (moduleId != null) {
+                targetModuleIds.add(moduleId);
+            }
+        }
+        return targetModuleIds;
+    }
 
-        if (!containsDefaultTarget(targetList)) {
+    private static TargetModuleID toTargetModuleId(AppInfo appInfo, ModuleType allowedModuleType) {
+        List<InfoObject> infos = new ArrayList<InfoObject>();
+        infos.addAll(appInfo.clients);
+        infos.addAll(appInfo.ejbJars);
+
+        // if the module id is the same as the appInfo, then it is a standalone module
+        if (infos.size() == 1) {
+            InfoObject infoObject = infos.get(0);
+            if (infoObject instanceof ClientInfo) {
+                // are client modules allowed
+                if (allowedModuleType != null && !allowedModuleType.equals(ModuleType.CAR)) {
+                    return null;
+                }
+                ClientInfo clientInfo = (ClientInfo) infoObject;
+                if (clientInfo.moduleId == appInfo.jarPath) {
+                    return new TargetModuleIDImpl(DEFAULT_TARGET, clientInfo.moduleId);
+                }
+            }
+            if (infoObject instanceof EjbJarInfo) {
+                // are ejb modules allowed
+                if (allowedModuleType != null && !allowedModuleType.equals(ModuleType.EJB)) {
+                    return null;
+                }
+                EjbJarInfo ejbJarInfo = (EjbJarInfo) infoObject;
+                if (ejbJarInfo.moduleId == appInfo.jarPath) {
+                    return new TargetModuleIDImpl(DEFAULT_TARGET, ejbJarInfo.moduleId);
+                }
+            }
+        }
+
+        // regular ear
+
+        // are ear modules allowed
+        if (allowedModuleType != null && !allowedModuleType.equals(ModuleType.EAR)) {
             return null;
         }
 
-        Set<TargetModuleID> modules = new HashSet<TargetModuleID>(deployed.keySet());
-        modules.removeAll(running);
-        filterModulesByType(modules, moduleType);
-        return modules.toArray(new TargetModuleID[modules.size()]);
+        TargetModuleIDImpl earModuleId = new TargetModuleIDImpl(DEFAULT_TARGET, appInfo.jarPath);
+        for (ClientInfo clientInfo : appInfo.clients) {
+            TargetModuleIDImpl clientModuleId = new TargetModuleIDImpl(DEFAULT_TARGET, clientInfo.moduleId);
+            clientModuleId.setParentTargetModuleID(earModuleId);
+        }
+        for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
+            TargetModuleIDImpl ejbJarModuleId = new TargetModuleIDImpl(DEFAULT_TARGET, ejbJarInfo.moduleId);
+            ejbJarModuleId.setParentTargetModuleID(earModuleId);
+        }
+
+        return earModuleId;
     }
 
-    public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] targetList) throws TargetException {
+    public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] targetList) throws TargetException {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
         if (!containsDefaultTarget(targetList)) {
             return null;
         }
 
-        Set<TargetModuleID> modules = new HashSet<TargetModuleID>(running);
-        filterModulesByType(modules, moduleType);
-        return modules.toArray(new TargetModuleID[modules.size()]);
+        return new TargetModuleIDImpl[0];
     }
 
-    private Set<TargetModuleID> filterModulesByType(Set<TargetModuleID> modules, ModuleType moduleType) {
-        for (Iterator<TargetModuleID> iterator = modules.iterator(); iterator.hasNext();) {
-            TargetModuleID moduleID = iterator.next();
-            if (!isModuleType(moduleID, moduleType)) {
-                iterator.remove();
-            }
-        }
-        return modules;
-    }
+    public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] targetList) throws TargetException {
+        if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
-    private boolean isModuleType(TargetModuleID moduleID, ModuleType moduleType) {
-        if (moduleType == null) return true;
+        if (!containsDefaultTarget(targetList)) {
+            return null;
+        }
 
-        Properties properties = deployed.get(moduleID);
-        String typeString = properties.getProperty(MODULE_TYPE);
-        return moduleType.toString().equalsIgnoreCase(typeString);
+        Set<TargetModuleID> targetModuleIds = toTargetModuleIds(getDeployer().getDeployedApps(), moduleType);
+        return targetModuleIds.toArray(new TargetModuleID[targetModuleIds.size()]);
     }
 
     public ProgressObject distribute(Target[] targetList, File moduleFile, File planFile) {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
+        if (!isDeployerLocal()) {
+            // todo when we input stream is a valid remote type we can implement this
+            throw new UnsupportedOperationException("Deployment from a remote computer is not currently supproted");
+        }
+
         // load properties
         Properties properties = new Properties();
         if (planFile != null) {
@@ -187,10 +256,11 @@
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
         // consume module stream
-        try {
-            byte[] buf = new byte[4096];
-            while (moduleStream.read(buf) >= 0);
-        } catch (IOException ignored) {
+        if (isDeployerLocal()) {
+            close(moduleStream);
+        } else {
+            // todo when we input stream is a valid remote type we can implement this
+            throw new UnsupportedOperationException("Deployment from a remote computer is not currently supproted");
         }
 
         // load properties
@@ -215,25 +285,19 @@
             return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.<TargetModuleID>emptySet());
         }
 
-        File source = new File(properties.getProperty(FILENAME));
-        String moduleId = source.getName().substring(source.getName().lastIndexOf('.'));
-        
-        TargetModuleID moduleID = new TargetModuleIDImpl(DEFAULT_TARGET, moduleId);
-        deployed.put(moduleID, properties);
-
-        File destination = new File(beansDir, source.getName());
         try {
-            copyFile(source, destination);
-        } catch (IOException e) {
+            AppInfo appInfo = getDeployer().deploy(properties);
+            TargetModuleID targetModuleId = toTargetModuleId(appInfo, null);
+
+            return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.singleton(targetModuleId));
+        } catch (OpenEJBException e) {
             return new ProgressObjectImpl(CommandType.DISTRIBUTE, e);
         }
-
-        return new ProgressObjectImpl(CommandType.DISTRIBUTE, Collections.singleton(moduleID));
     }
 
     private boolean containsDefaultTarget(Target[] targetList) {
         for (Target target : targetList) {
-            if  (DEFAULT_TARGET.equals(target)) return true;
+            if (DEFAULT_TARGET.equals(target)) return true;
         }
         return false;
     }
@@ -241,112 +305,44 @@
     public ProgressObject start(TargetModuleID[] moduleIdList) {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
-        Map<TargetModuleID, Properties> toStart = new LinkedHashMap<TargetModuleID, Properties>();
-        for (TargetModuleID moduleID : moduleIdList) {
-            if (!running.contains(moduleID)) {
-                Properties properties = deployed.get(moduleID);
-                if (properties != null) {
-                    toStart.put(moduleID, properties);
-                }
-            }
-        }
-
-        try {
-            start(toStart);
-            Set<TargetModuleID> results = new TreeSet<TargetModuleID>(toStart.keySet());
-            running.addAll(results);
-            return new ProgressObjectImpl(CommandType.START, results);
-        } catch (Exception e) {
-            return new ProgressObjectImpl(CommandType.START, e);
-        }
-    }
+        Set<TargetModuleID> deployedModules = toTargetModuleIds(getDeployer().getDeployedApps(), null);
+        Set<TargetModuleID> targetModuleIds = new HashSet<TargetModuleID>(Arrays.asList(moduleIdList));
+        targetModuleIds.retainAll(deployedModules);
 
-    private void start(Map<TargetModuleID, Properties> moduleIdList) {
-        remoteServer.start();
-//        for (Iterator<Map.Entry<TargetModuleID, Properties>> iterator = moduleIdList.entrySet().iterator(); iterator.hasNext();) {
-//            Map.Entry<TargetModuleID, Properties> entry = iterator.next();
-//            TargetModuleID module = entry.getKey();
-//            Properties properties =  entry.getValue();
-//            File source = new File(properties.getProperty(FILENAME));
-//            File destination = new File(beansDir, source.getName());
-//            copyFile(source, destination);
-//        }
+        return new ProgressObjectImpl(CommandType.START, targetModuleIds);
     }
 
     public ProgressObject stop(TargetModuleID[] moduleIdList) {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
-        Map<TargetModuleID, Properties> toStop = new LinkedHashMap<TargetModuleID, Properties>();
-        for (TargetModuleID moduleID : moduleIdList) {
-            if (running.contains(moduleID)) {
-                Properties properties = deployed.get(moduleID);
-                if (properties != null) {
-                    toStop.put(moduleID, properties);
-                }
-            }
-        }
-
-        try {
-            stop(toStop);
-            Set<TargetModuleID> results = new TreeSet<TargetModuleID>(toStop.keySet());
-            running.removeAll(results);
-            return new ProgressObjectImpl(CommandType.STOP, results);
-        } catch (Exception e) {
-            return new ProgressObjectImpl(CommandType.STOP, e);
-        }
-    }
-
-    private void stop(Map<TargetModuleID, Properties> moduleIdList) {
-        remoteServer.stop();
-        for (Iterator<Map.Entry<TargetModuleID, Properties>> iterator = moduleIdList.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry<TargetModuleID, Properties> entry = iterator.next();
-            TargetModuleID module = entry.getKey();
-            Properties properties =  entry.getValue();
-            String filename = properties.getProperty(FILENAME);
-            System.out.println("STOPPED " + module.getModuleID());
-            System.out.println("        " + filename);
-        }
+        return new ProgressObjectImpl(CommandType.START, Collections.<TargetModuleID>emptySet());
     }
 
     public ProgressObject undeploy(TargetModuleID[] moduleIdList) {
         if (!connected) throw new IllegalStateException("Deployment manager is disconnected");
 
-        Map<TargetModuleID, Properties> toUndeploy = new LinkedHashMap<TargetModuleID, Properties>();
-        for (TargetModuleID moduleID : moduleIdList) {
-            Properties properties = deployed.get(moduleID);
-            if (properties != null) {
-                toUndeploy.put(moduleID, properties);
+        UndeployException undeployException = null;
+        Set<TargetModuleID> results = new TreeSet<TargetModuleID>();
+        for (TargetModuleID targetModuleId : moduleIdList) {
+            try {
+                getDeployer().undeploy(targetModuleId.getModuleID());
+                results.add(targetModuleId);
+            } catch (UndeployException e) {
+                if (undeployException == null) {
+                    undeployException = e;
+                }
+            } catch (NoSuchApplicationException e) {
+                // app was not deployed... this should be ignored by jsr88
             }
         }
 
-
-        try {
-            undeploy(toUndeploy);
-            Set<TargetModuleID> results = new TreeSet<TargetModuleID>(toUndeploy.keySet());
-            running.removeAll(results);
+        if (undeployException == null) {
             return new ProgressObjectImpl(CommandType.UNDEPLOY, results);
-        } catch (Exception e) {
-            return new ProgressObjectImpl(CommandType.UNDEPLOY, e);
+        } else {
+            return new ProgressObjectImpl(CommandType.UNDEPLOY, undeployException);
         }
     }
 
-    private void undeploy(Map<TargetModuleID, Properties> moduleIdList) {
-        if (System.getProperty("openejb.server.debug","false").equalsIgnoreCase("TRUE")) {
-            return;
-        }
-        
-//        for (Iterator<Map.Entry<TargetModuleID, Properties>> iterator = moduleIdList.entrySet().iterator(); iterator.hasNext();) {
-//            Map.Entry<TargetModuleID, Properties> entry = iterator.next();
-//            TargetModuleID module = entry.getKey();
-//            Properties properties =  entry.getValue();
-//            String fileName = new File(properties.getProperty(FILENAME)).getName();
-//            File destination = new File(beansDir, fileName);
-//            destination.delete();
-//            File unpackedDir = new File(appsDir, fileName.substring(0, fileName.lastIndexOf('.')));
-//            recursiveDelete(unpackedDir);
-//        }
-    }
-
     public boolean isRedeploySupported() {
         return false;
     }
@@ -645,60 +641,12 @@
         }
     }
 
-    private static void copyFile(File source, File destination) throws IOException {
-        File destinationDir = destination.getParentFile();
-        if (!destinationDir.exists() && !destinationDir.mkdirs()) {
-            throw new java.io.IOException("Cannot create directory : " + destinationDir);
-        }
-
-        InputStream in = null;
-        OutputStream out = null;
-        try {
-            in = new FileInputStream(source);
-            out = new FileOutputStream(destination);
-            writeAll(in, out);
-        } finally {
-            close(in);
-            close(out);
-        }
-    }
-
-    private static void writeAll(InputStream in, OutputStream out) throws IOException {
-        byte[] buffer = new byte[4096];
-        int count;
-        while ((count = in.read(buffer)) > 0) {
-            out.write(buffer, 0, count);
-        }
-        out.flush();
-    }
-
     private static void close(Closeable thing) {
         if (thing != null) {
             try {
                 thing.close();
-            } catch(Exception ignored) {
-            }
-        }
-    }
-
-    public static boolean recursiveDelete(File root) {
-        if (root == null) {
-            return true;
-        }
-
-        if (root.isDirectory()) {
-            File[] files = root.listFiles();
-            if (files != null) {
-                for (int i = 0; i < files.length; i++) {
-                    File file = files[i];
-                    if (file.isDirectory()) {
-                        recursiveDelete(file);
-                    } else {
-                        file.delete();
-                    }
-                }
+            } catch (Exception ignored) {
             }
         }
-        return root.delete();
     }
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Wed Feb  7 21:39:04 2007
@@ -22,6 +22,9 @@
  * @version $Rev$ $Date$
  */
 public class WebModule implements DeploymentModule {
+    public String getModuleId() {
+        throw new UnsupportedOperationException();
+    }
 
     public Map<String, Object> getAltDDs() {
         throw new UnsupportedOperationException();

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/ejb-jar.xml?view=auto&rev=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/ejb-jar.xml (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/ejb-jar.xml Wed Feb  7 21:39:04 2007
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+
+<!-- $Rev: 502031 $ $Date: 2007-01-31 15:01:07 -0800 (Wed, 31 Jan 2007) $ -->
+
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                  http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+         version="3.0" metadata-complete="true"/>
+

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java?view=diff&rev=504792&r1=504791&r2=504792
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java Wed Feb  7 21:39:04 2007
@@ -58,7 +58,7 @@
         // Nothing may depend on the Assembler except the config code or spring assembler
         String springAssembler = "org.apache.openejb.assembler.spring";
         String dynamicAssembler = "org.apache.openejb.assembler.dynamic";
-        assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.config", springAssembler, "org.apache.openejb.assembler.dynamic");
+        assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.assembler", "org.apache.openejb.config", springAssembler, "org.apache.openejb.assembler.dynamic");
 
         // Nothing may depend on the Spring Assembler
         assertNotDependentOn("org.apache.openejb", springAssembler);
@@ -70,7 +70,7 @@
         assertNotDependentOn("org.apache.openejb", "org.apache.openejb.jee", "org.apache.openejb.config");
 
         // Nothing may depend on the Config code except it's subpackages and the Spring Assembler
-        assertNotDependentOn("org.apache.openejb", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", springAssembler, dynamicAssembler);
+        assertNotDependentOn("org.apache.openejb", "org.apache.openejb.config", "org.apache.openejb.config.rules", "org.apache.openejb.config.sys", "org.apache.openejb.assembler", springAssembler, dynamicAssembler);
 
         // The assembler may not be dependent on the config factory Implementation
         assertNotDependentOn("org.apache.openejb.assembler.classic", "org.apache.openejb.config");



Mime
View raw message