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 2011/07/21 02:43:51 UTC
svn commit: r1148991 - in
/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config:
AppInfoBuilder.java ClientModule.java DeploymentModule.java
Author: dblevins
Date: Thu Jul 21 00:43:50 2011
New Revision: 1148991
URL: http://svn.apache.org/viewvc?rev=1148991&view=rev
Log:
Patch from Marius Kruger, OPENEJB-1366: NameAlreadyBoundException: ParsedName{path=openejb/client/test-classes/comp/env
Thank you so much, Marius!
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=1148991&r1=1148990&r2=1148991&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 Thu Jul 21 00:43:50 2011
@@ -254,7 +254,7 @@ class AppInfoBuilder {
clientInfo.localClients.addAll(clientModule.getLocalClients());
clientInfo.remoteClients.addAll(clientModule.getRemoteClients());
clientInfo.callbackHandler = applicationClient.getCallbackHandler();
- clientInfo.moduleId = getClientModuleId(clientModule);
+ clientInfo.moduleId = clientModule.getModuleId();
clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
clientInfo.validationInfo = ValidatorBuilder.getInfo(clientModule.getValidationConfig());
clientInfo.uniqueId = clientModule.getUniqueId();
@@ -599,16 +599,6 @@ 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=1148991&r1=1148990&r2=1148991&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 Thu Jul 21 00:43:50 2011
@@ -16,16 +16,14 @@
*/
package org.apache.openejb.config;
-import org.apache.openejb.jee.ApplicationClient;
-import org.apache.xbean.finder.ClassFinder;
-
-import java.util.Map;
-import java.util.HashMap;
+import java.io.File;
+import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
-import java.util.HashSet;
import java.util.concurrent.atomic.AtomicReference;
-import java.io.File;
+
+import org.apache.openejb.jee.ApplicationClient;
+import org.apache.xbean.finder.ClassFinder;
/**
* @version $Rev$ $Date$
@@ -33,32 +31,23 @@ import java.io.File;
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 final String moduleId;
+ private ID id;
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;
- if (moduleId == null){
- if (applicationClient != null && applicationClient.getId() != null){
- moduleId = applicationClient.getId();
- } else {
- File file = new File(jarLocation);
- moduleId = file.getName();
- }
- }
-
- this.moduleId = moduleId;
+ File file = (jarLocation == null) ? null : new File(jarLocation);
+ this.id = new ID(//null, applicationClient,
+ moduleId, file, null, this);
validation = new ValidationContext(ClientModule.class, jarLocation);
}
@@ -87,7 +76,7 @@ public class ClientModule extends Module
}
public String getModuleId() {
- return moduleId;
+ return id.getName();
}
public ApplicationClient getApplicationClient() {
@@ -115,11 +104,12 @@ public class ClientModule extends Module
}
public String getJarLocation() {
- return jarLocation;
+ return (id.getLocation() != null) ? id.getLocation().getAbsolutePath() : null;
}
public void setJarLocation(String jarLocation) {
- this.jarLocation = jarLocation;
+ this.id = new ID(//null, applicationClient,
+ id.getName(), new File(jarLocation), id.getUri(), this);
}
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=1148991&r1=1148990&r2=1148991&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 Thu Jul 21 00:43:50 2011
@@ -16,6 +16,10 @@
*/
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;
@@ -34,4 +38,81 @@ 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;
+ }
+ }
}