You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2011/07/25 13:29:00 UTC

svn commit: r1150632 - in /openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config: AppInfoBuilder.java ClientModule.java DeploymentModule.java

Author: jlmonteiro
Date: Mon Jul 25 11:29:00 2011
New Revision: 1150632

URL: http://svn.apache.org/viewvc?rev=1150632&view=rev
Log:
Reverting David's commit regarding NameAlreadyBoundException. Looks like we only need to replace moduleId by uniqueId like we did for Validation stuff

Modified:
    openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java
    openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java

Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=1150632&r1=1150631&r2=1150632&view=diff
==============================================================================
--- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java (original)
+++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java Mon Jul 25 11:29:00 2011
@@ -254,7 +254,7 @@ class AppInfoBuilder {
             clientInfo.localClients.addAll(clientModule.getLocalClients());
             clientInfo.remoteClients.addAll(clientModule.getRemoteClients());
             clientInfo.callbackHandler = applicationClient.getCallbackHandler();
-            clientInfo.moduleId = clientModule.getModuleId();
+            clientInfo.moduleId = getClientModuleId(clientModule);
             clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
             clientInfo.validationInfo = ValidatorBuilder.getInfo(clientModule.getValidationConfig());
             clientInfo.uniqueId = clientModule.getUniqueId();
@@ -599,6 +599,16 @@ class AppInfoBuilder {
         }
     }
 
+    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>();

Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java?rev=1150632&r1=1150631&r2=1150632&view=diff
==============================================================================
--- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java (original)
+++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java Mon Jul 25 11:29:00 2011
@@ -16,14 +16,16 @@
  */
 package org.apache.openejb.config;
 
-import java.io.File;
-import java.util.HashSet;
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.xbean.finder.ClassFinder;
+
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.HashSet;
 import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.openejb.jee.ApplicationClient;
-import org.apache.xbean.finder.ClassFinder;
+import java.io.File;
 
 /**
  * @version $Rev$ $Date$
@@ -31,23 +33,32 @@ import org.apache.xbean.finder.ClassFind
 public class ClientModule extends Module implements DeploymentModule {
     private final ValidationContext validation;
     private ApplicationClient applicationClient;
+    private String jarLocation;
     private ClassLoader classLoader;
     private String mainClass;
     private boolean ejbModuleGenerated;
     private AtomicReference<ClassFinder> finder;
     private final Set<String> localClients = new HashSet<String>();
     private final Set<String> remoteClients = new HashSet<String>();
-    private ID id;
+    private final String moduleId;
     private final Set<String> watchedResources = new TreeSet<String>();
 
     public ClientModule(ApplicationClient applicationClient, ClassLoader classLoader, String jarLocation, String mainClass, String moduleId) {
         this.applicationClient = applicationClient;
         this.classLoader = classLoader;
+        this.jarLocation = jarLocation;
         this.mainClass = mainClass;
 
-        File file = (jarLocation == null) ? null : new File(jarLocation);
-        this.id = new ID(//null, applicationClient,
-            moduleId, file, null, this);
+        if (moduleId == null){
+            if (applicationClient != null && applicationClient.getId() != null){
+                moduleId = applicationClient.getId();
+            } else {
+                File file = new File(jarLocation);
+                moduleId = file.getName();
+            }
+        }
+
+        this.moduleId = moduleId;
         validation = new ValidationContext(ClientModule.class, jarLocation);
     }
 
@@ -76,7 +87,7 @@ public class ClientModule extends Module
     }
 
     public String getModuleId() {
-        return id.getName();
+        return moduleId;
     }
 
     public ApplicationClient getApplicationClient() {
@@ -104,12 +115,11 @@ public class ClientModule extends Module
     }
 
     public String getJarLocation() {
-        return (id.getLocation() != null) ? id.getLocation().getAbsolutePath() : null;
+        return jarLocation;
     }
 
     public void setJarLocation(String jarLocation) {
-        this.id = new ID(//null, applicationClient,
-            id.getName(), new File(jarLocation), id.getUri(), this);
+        this.jarLocation = jarLocation;
     }
 
     public String getMainClass() {

Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java?rev=1150632&r1=1150631&r2=1150632&view=diff
==============================================================================
--- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java (original)
+++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentModule.java Mon Jul 25 11:29:00 2011
@@ -16,10 +16,6 @@
  */
 package org.apache.openejb.config;
 
-import java.io.File;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -38,81 +34,4 @@ public interface DeploymentModule {
     ValidationContext getValidation();
 
     Set<String> getWatchedResources();
-
-    class ID {
-        private final String name;
-        private final File location;
-        private final URI uri;
-
-        public ID(//NamedModule vendorDd, NamedModule specDd,
-            String name, File location, URI uri, DeploymentModule module) {
-            this.name = name(//vendorDd, specDd,
-                uri, location, name, module);
-            this.location = location(location, uri);
-            this.uri = uri(uri, location, this.name);
-        }
-
-        private URI uri(URI uri, File location, String name) {
-            if (uri != null) return uri;
-            if (location != null) return location.toURI();
-            return URI.create(name);
-        }
-
-        private File location(File location, URI uri) {
-            if (location != null) return location;
-            if (uri != null && uri.isAbsolute()) return new File(uri);
-            return null;
-        }
-
-        private String name(//NamedModule vendor, NamedModule spec,
-                URI uri, File location, String name, DeploymentModule module) {
-            if (name != null && !name.startsWith("@")) return name;
-//            if (vendor != null && vendor.getModuleName() != null) return vendor.getModuleName().trim();
-//            if (vendor != null && vendor.getId() != null) return vendor.getId().trim();
-//            if (spec != null && spec.getModuleName() != null) return spec.getModuleName().trim();
-//            if (spec != null && spec.getId() != null) return spec.getId().trim();
-            if (uri != null) return stripExtension(uri.getPath());
-            if (location != null) return moduleName(location);
-            if (name != null) return name;
-            return "@" + module.getClass().getSimpleName() + module.hashCode();
-        }
-
-        private String moduleName(File location) {
-            List<String> invalid = new ArrayList<String>();
-            invalid.add("classes");
-            invalid.add("test-classes");
-            invalid.add("target");
-            invalid.add("build");
-            invalid.add("dist");
-            invalid.add("bin");
-
-            while (invalid.contains(location.getName())) {
-                location = location.getParentFile();
-            }
-            return stripExtension(location.getName());
-        }
-
-        private String stripExtension(String name) {
-            String[] exts = {".jar", ".zip", ".ear", ".war", ".rar", ".unpacked"};
-            for (String ext : exts) {
-                if (name.endsWith(ext)) {
-                    return name.substring(0, name.length() - ext.length());
-                }
-            }
-            return name;
-        }
-
-        public String getName() {
-            if (name.startsWith("@")) return name.substring(1);
-            return name;
-        }
-
-        public File getLocation() {
-            return location;
-        }
-
-        public URI getUri() {
-            return uri;
-        }
-    }
 }