dblevins 2005/07/09 05:28:24
Modified: modules/core/src/java/org/openejb/loader
EmbeddingLoader.java SystemInstance.java
SystemLoader.java TomcatWebappLoader.java
Added: modules/core/src/java/org/openejb/loader
BasicURLClassPath.java ClassPath.java
ClassPathFactory.java ContextClassPath.java
SystemClassPath.java TomcatClassPath.java
WebAppClassPath.java
Log:
Yay! ClasspathUtils is dead.
Revision Changes Path
1.7 +1 -3
openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java
Index: EmbeddingLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/EmbeddingLoader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EmbeddingLoader.java 9 Jul 2005 08:51:00 -0000 1.6
+++ EmbeddingLoader.java 9 Jul 2005 09:28:24 -0000 1.7
@@ -47,8 +47,6 @@
import java.util.Hashtable;
import java.io.File;
-import org.openejb.util.ClasspathUtils;
-
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Blevins</a>
1.3 +5 -6
openejb1/modules/core/src/java/org/openejb/loader/SystemInstance.java
Index: SystemInstance.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/SystemInstance.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SystemInstance.java 9 Jul 2005 09:10:39 -0000 1.2
+++ SystemInstance.java 9 Jul 2005 09:28:24 -0000 1.3
@@ -49,7 +49,6 @@
import java.util.HashMap;
import org.openejb.util.FileUtils;
-import org.openejb.util.ClasspathUtils;
/**
* This class aims to be the one and only static in the entire system
@@ -69,14 +68,14 @@
private final FileUtils base;
private ClassLoader classLoader;
private final HashMap components;
- private final ClasspathUtils.ClassPath classPath;
+ private final ClassPath classPath;
private SystemInstance(Properties properties) throws Exception {
this.properties = properties;
this.home = new FileUtils("openejb.home", "user.dir", properties);
this.base = new FileUtils("openejb.base", "openejb.home",
properties);
this.components = new HashMap();
- classPath =
ClasspathUtils.ClassPathFactory.createLoader(properties.getProperty("openejb.loader",
"context"));
+ classPath =
ClassPathFactory.createLoader(properties.getProperty("openejb.loader",
"context"));
}
@@ -108,7 +107,7 @@
return base;
}
- public ClasspathUtils.ClassPath getLoader() {
+ public ClassPath getLoader() {
return classPath;
}
1.7 +2 -3
openejb1/modules/core/src/java/org/openejb/loader/SystemLoader.java
Index: SystemLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/SystemLoader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SystemLoader.java 9 Jul 2005 09:10:39 -0000 1.6
+++ SystemLoader.java 9 Jul 2005 09:28:24 -0000 1.7
@@ -47,7 +47,6 @@
import java.util.Hashtable;
import java.io.File;
-import org.openejb.util.ClasspathUtils;
import org.openejb.util.FileUtils;
@@ -62,7 +61,7 @@
public class SystemLoader implements Loader {
static boolean loaded = false;
- private final ClasspathUtils.ClassPath classPath;
+ private final ClassPath classPath;
public SystemLoader() {
this.classPath = SystemInstance.get().getLoader();
1.9 +2 -3
openejb1/modules/core/src/java/org/openejb/loader/TomcatWebappLoader.java
Index: TomcatWebappLoader.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/loader/TomcatWebappLoader.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TomcatWebappLoader.java 9 Jul 2005 09:10:39 -0000 1.8
+++ TomcatWebappLoader.java 9 Jul 2005 09:28:24 -0000 1.9
@@ -48,7 +48,6 @@
import java.util.Hashtable;
import java.util.Properties;
-import org.openejb.util.ClasspathUtils;
import org.openejb.util.FileUtils;
/**
@@ -58,7 +57,7 @@
public class TomcatWebappLoader implements Loader {
static boolean loaded = false;
- private final ClasspathUtils.ClassPath classPath;
+ private final ClassPath classPath;
public TomcatWebappLoader() {
this.classPath = SystemInstance.get().getLoader();
1.1
openejb1/modules/core/src/java/org/openejb/loader/BasicURLClassPath.java
Index: BasicURLClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: BasicURLClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
public class BasicURLClassPath implements ClassPath {
public static ClassLoader getContextClassLoader() {
return (ClassLoader) java.security.AccessController.doPrivileged(new
java.security.PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
}
public void addJarsToPath(File dir) throws Exception {
}
public void addJarToPath(URL jar) throws Exception {
}
private java.lang.reflect.Field ucpField;
protected void addJarToPath(final URL jar, final URLClassLoader loader)
throws Exception {
this.getURLClassPath(loader).addURL(jar);
}
protected void addJarsToPath(final File dir, final URLClassLoader loader)
throws Exception {
if (dir == null || !dir.exists()) return;
//System.out.println("DIR "+dir);
// Get the list of jars and zips
String[] jarNames = dir.list(new java.io.FilenameFilter() {
public boolean accept(File dir, String name) {
//System.out.println("FILE "+name);
return (name.endsWith(".jar") || name.endsWith(".zip"));
}
});
// Create URLs from them
final URL[] jars = new URL[jarNames.length];
for (int j = 0; j < jarNames.length; j++) {
jars[j] = new File(dir, jarNames[j]).toURL();
}
sun.misc.URLClassPath path = getURLClassPath(loader);
for (int i = 0; i < jars.length; i++) {
//System.out.println("URL "+jars[i]);
path.addURL(jars[i]);
}
}
protected sun.misc.URLClassPath getURLClassPath(URLClassLoader loader)
throws Exception {
return (sun.misc.URLClassPath) getUcpField().get(loader);
}
private java.lang.reflect.Field getUcpField() throws Exception {
if (ucpField == null) {
// Add them to the URLClassLoader's classpath
ucpField = (java.lang.reflect.Field)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
java.lang.reflect.Field ucp = null;
try {
ucp = URLClassLoader.class.getDeclaredField("ucp");
ucp.setAccessible(true);
} catch (Exception e2) {
e2.printStackTrace();
}
return ucp;
}
});
}
return ucpField;
}
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/ClassPath.java
Index: ClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: ClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
import java.io.File;
import java.net.URL;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
public interface ClassPath {
public void addJarsToPath(File dir) throws Exception;
public void addJarToPath(URL dir) throws Exception;
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/ClassPathFactory.java
Index: ClassPathFactory.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: ClassPathFactory.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
public class ClassPathFactory {
public static ClassPath createLoader(String name){
if (name.equalsIgnoreCase("tomcat")) {
return new TomcatClassPath();
} else if (name.equalsIgnoreCase("tomcat-common")) {
return new TomcatClassPath();
} else if (name.equalsIgnoreCase("tomcat-webapp")) {
return new WebAppClassPath();
} else if (name.equalsIgnoreCase("bootstrap")) {
return new SystemClassPath();
} else if (name.equalsIgnoreCase("system")) {
return new SystemClassPath();
} else if (name.equalsIgnoreCase("thread")) {
return new ContextClassPath();
} else if (name.equalsIgnoreCase("context")) {
return new ContextClassPath();
} else {
return new ContextClassPath();
}
}
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/ContextClassPath.java
Index: ContextClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: ContextClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
import java.io.File;
import java.net.URLClassLoader;
import java.net.URL;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
/*-------------------------------------------------------*/
/* Thread Context ClassLoader Support */
/*-------------------------------------------------------*/
public class ContextClassPath extends BasicURLClassPath {
public void addJarsToPath(File dir) throws Exception {
ClassLoader contextClassLoader = getContextClassLoader();
if (contextClassLoader instanceof URLClassLoader) {
URLClassLoader loader = (URLClassLoader) contextClassLoader;
this.addJarsToPath(dir, loader);
}
}
public void addJarToPath(URL jar) throws Exception {
ClassLoader contextClassLoader = getContextClassLoader();
if (contextClassLoader instanceof URLClassLoader) {
URLClassLoader loader = (URLClassLoader) contextClassLoader;
this.addJarToPath(jar, loader);
}
}
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/SystemClassPath.java
Index: SystemClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: SystemClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
import java.net.URLClassLoader;
import java.net.URL;
import java.io.File;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
/*-------------------------------------------------------*/
/* System ClassLoader Support */
/*-------------------------------------------------------*/
public class SystemClassPath extends BasicURLClassPath {
private URLClassLoader sysLoader;
public void addJarsToPath(File dir) throws Exception {
this.addJarsToPath(dir, getSystemLoader());
this.rebuildJavaClassPathVariable();
}
public void addJarToPath(URL jar) throws Exception {
//System.out.println("[|] SYSTEM "+jar.toExternalForm());
this.addJarToPath(jar, getSystemLoader());
this.rebuildJavaClassPathVariable();
}
private URLClassLoader getSystemLoader() throws Exception {
if (sysLoader == null) {
sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
}
return sysLoader;
}
private void rebuildJavaClassPathVariable() throws Exception {
sun.misc.URLClassPath cp = getURLClassPath(getSystemLoader());
URL[] urls = cp.getURLs();
//for (int i=0; i < urls.length; i++){
// System.out.println(urls[i].toExternalForm());
//}
if (urls.length < 1)
return;
StringBuffer path = new StringBuffer(urls.length * 32);
File s = new File(urls[0].getFile());
path.append(s.getPath());
//System.out.println(s.getPath());
for (int i = 1; i < urls.length; i++) {
path.append(File.pathSeparator);
s = new File(urls[i].getFile());
//System.out.println(s.getPath());
path.append(s.getPath());
}
try {
System.setProperty("java.class.path", path.toString());
} catch (Exception e) {
}
}
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/TomcatClassPath.java
Index: TomcatClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: TomcatClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
/*-------------------------------------------------------*/
/* Tomcat ClassLoader Support */
/*-------------------------------------------------------*/
public class TomcatClassPath extends BasicURLClassPath {
/**
* The Tomcat Common ClassLoader
*/
private ClassLoader tomcatLoader;
/**
* The addRepository(String jar) method of the Tomcat Common ClassLoader
*/
private java.lang.reflect.Method addRepositoryMethod;
public void addJarsToPath(File dir) throws Exception {
String[] jarNames = dir.list(new java.io.FilenameFilter() {
public boolean accept(File dir, String name) {
//System.out.println("FILE "+name);
return (name.endsWith(".jar") || name.endsWith(".zip"));
}
});
if (jarNames == null) {
return;
}
for (int j = 0; j < jarNames.length; j++) {
this.addJarToPath(new File(dir, jarNames[j]).toURL());
}
rebuild();
}
public void addJarToPath(URL jar) throws Exception {
//System.out.println("[|] TOMCAT "+jar.toExternalForm());
this._addJarToPath(jar);
rebuild();
}
public void _addJarToPath(URL jar) throws Exception {
String path = jar.toExternalForm();
//System.out.println("[] PATH "+path);
//if (path.startsWith("file:/C")) {
// path = path.substring("file:/C".length());
// path = "file:C"+path;
//}
this.addRepository(path);
//ClassLoader cl = ClasspathUtils.getContextClassLoader();
//cl = getCommonLoader(cl);
//System.out.println("[] "+cl.getClass().getName());
//System.out.println("[] "+cl);
//
////Reloader loader = (Reloader)cl.getParent();
//cl = cl.getParent();
//java.lang.reflect.Method m = getAddRepositoryMethod(
// cl.getClass());
//m.invoke( cl, new Object[]{jar.toExternalForm()});
////loader.addRepository( jar.toExternalForm() );
}
public void addRepository(String path) throws Exception {
// Add this repository to our underlying class loader
this.getAddRepositoryMethod().invoke(getCommonLoader(), new Object[]
{ new URL(path) });
}
private void rebuild() {
try {
sun.misc.URLClassPath cp = getURLClassPath((URLClassLoader)
getCommonLoader());
URL[] urls = cp.getURLs();
//for (int i=0; i < urls.length; i++){
// System.out.println(urls[i].toExternalForm());
//}
if (urls.length < 1)
return;
StringBuffer path = new StringBuffer(urls.length * 32);
File s = new File(urls[0].getFile());
path.append(s.getPath());
//System.out.println(s.getPath());
for (int i = 1; i < urls.length; i++) {
path.append(File.pathSeparator);
s = new File(urls[i].getFile());
//System.out.println(s.getPath());
path.append(s.getPath());
}
System.setProperty("java.class.path", path.toString());
} catch (Exception e) {
}
}
protected ClassLoader getCommonLoader() {
if (tomcatLoader == null) {
tomcatLoader =
this.getCommonLoader(getContextClassLoader()).getParent();
}
return tomcatLoader;
}
private ClassLoader getCommonLoader(ClassLoader loader) {
if
(loader.getClass().getName().equals("org.apache.catalina.loader.StandardClassLoader"))
{
return loader;
} else {
return this.getCommonLoader(loader.getParent());
}
}
/**
* This method gets the Tomcat StandardClassLoader.addRepository method
* via reflection. This allows us to call the addRepository method for
* Tomcat integration, but doesn't require us to include or ship any
* Tomcat libraries.
*
* @return URLClassLoader.addURL method instance
*/
private java.lang.reflect.Method getAddRepositoryMethod() throws
Exception {
if (addRepositoryMethod == null) {
final Class clazz = URLClassLoader.class;
this.addRepositoryMethod = (java.lang.reflect.Method)
AccessController
.doPrivileged(new PrivilegedAction() {
public Object run() {
java.lang.reflect.Method method = null;
try {
method = clazz.getDeclaredMethod("addURL",
new Class[] { URL.class });
method.setAccessible(true);
} catch (Exception e2) {
e2.printStackTrace();
}
return method;
}
});
}
return addRepositoryMethod;
}
}
1.1
openejb1/modules/core/src/java/org/openejb/loader/WebAppClassPath.java
Index: WebAppClassPath.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: WebAppClassPath.java,v 1.1 2005/07/09 09:28:24 dblevins Exp $
*/
package org.openejb.loader;
/**
* @version $Revision: 1.1 $ $Date: 2005/07/09 09:28:24 $
*/
public class WebAppClassPath extends TomcatClassPath {
ClassLoader webappLoader;
protected ClassLoader getCommonLoader() {
if (webappLoader == null) {
webappLoader = getContextClassLoader();
}
return webappLoader;
}
}