Title: [2554] trunk/openejb3/container: Moved the org.openejb.loader package into its own module
Revision
2554
Author
dblevins
Date
2006-03-14 15:49:33 -0500 (Tue, 14 Mar 2006)

Log Message

Moved the org.openejb.loader package into its own module

Modified Paths


Added Paths

Removed Paths

Diff

Modified: trunk/openejb3/container/openejb-core/pom.xml (2553 => 2554)

--- trunk/openejb3/container/openejb-core/pom.xml	2006-03-14 20:34:23 UTC (rev 2553)
+++ trunk/openejb3/container/openejb-core/pom.xml	2006-03-14 20:49:33 UTC (rev 2554)
@@ -65,6 +65,11 @@
   </build>
   <dependencies>
     <dependency>
+      <groupId>org.openejb</groupId>
+      <artifactId>openejb-loader</artifactId>
+      <version>3.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.xbean</groupId>
       <artifactId>xbean-reflect</artifactId>
       <version>2.2-SNAPSHOT</version>

Added: trunk/openejb3/container/openejb-loader/pom.xml (2553 => 2554)

--- trunk/openejb3/container/openejb-loader/pom.xml	2006-03-14 20:34:23 UTC (rev 2553)
+++ trunk/openejb3/container/openejb-loader/pom.xml	2006-03-14 20:49:33 UTC (rev 2554)
@@ -0,0 +1,21 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>container</artifactId>
+    <groupId>org.openejb</groupId>
+    <version>3.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-loader</artifactId>
+  <packaging>jar</packaging>
+  <version>3.0-SNAPSHOT</version>
+  <name>OpenEJB :: Container :: Loader</name>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader (from rev 2552, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/BasicURLClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/BasicURLClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/BasicURLClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,70 +0,0 @@
-package org.openejb.loader;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-public abstract 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();
-            }
-        });
-    }
-
-    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;
-
-        String[] jarNames = dir.list(new java.io.FilenameFilter() {
-            public boolean accept(File dir, String name) {
-
-                return (name.endsWith(".jar") || name.endsWith(".zip"));
-            }
-        });
-
-        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++) {
-
-            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) {
-
-            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;
-    }
-
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/BasicURLClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/BasicURLClassPath.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,13 +0,0 @@
-package org.openejb.loader;
-
-import java.io.File;
-import java.net.URL;
-
-public interface ClassPath {
-
-    ClassLoader getClassLoader();
-
-    void addJarsToPath(File dir) throws Exception;
-
-    void addJarToPath(URL dir) throws Exception;
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ClassPath.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPathFactory.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ClassPathFactory.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPathFactory.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,23 +0,0 @@
-package org.openejb.loader;
-
-public class ClassPathFactory {
-    public static ClassPath createClassPath(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();
-        }
-    }
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ClassPathFactory.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ClassPathFactory.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ContextClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ContextClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ContextClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,32 +0,0 @@
-package org.openejb.loader;
-
-import java.io.File;
-import java.net.URLClassLoader;
-import java.net.URL;
-
-/*-------------------------------------------------------*/
-/* Thread Context ClassLoader Support */
-/*-------------------------------------------------------*/
-
-public class ContextClassPath extends BasicURLClassPath {
-
-    public ClassLoader getClassLoader() {
-        return getContextClassLoader();
-    }
-
-    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);
-        }
-    }
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/ContextClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/ContextClassPath.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Embedder.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/Embedder.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Embedder.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,122 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation
- *
- *  Licensed 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.openejb.loader;
-
-import org.openejb.util.FileUtils;
-
-import java.io.File;
-
-/**
- * @version $Revision$ $Date$
- */
-public class Embedder {
-
-    private final String className;
-
-    public Embedder(String className) {
-        this.className = className;
-    }
-
-    public Class load() throws Exception {
-        ClassPath classPath = SystemInstance.get().getClassPath();
-        ClassLoader classLoader = classPath.getClassLoader();
-        try {
-            return  classLoader.loadClass(className);
-        } catch (Exception e) {
-            return forcefulLoad(classPath, classLoader);
-        }
-    }
-
-    private Class forcefulLoad(ClassPath classPath, ClassLoader classLoader) throws Exception {
-        try {
-            checkOpenEjbHome(SystemInstance.get().getHome().getDirectory());
-            FileUtils home = SystemInstance.get().getHome();
-            classPath.addJarsToPath(home.getDirectory("lib"));
-        } catch (Exception e2) {
-            throw new Exception("Could not load OpenEJB libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
-        }
-        try {
-            return classLoader.loadClass(className);
-        } catch (Exception e2) {
-            throw new Exception("Could not load class '"+className+"' after embedding libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
-        }
-    }
-
-    private String NO_HOME = "The openejb.home is not set.";
-
-    private String BAD_HOME = "Invalid openejb.home: ";
-
-    private String NOT_THERE = "The path specified does not exist.";
-
-    private String NOT_DIRECTORY = "The path specified is not a directory.";
-
-    private String NO_LIBS = "The path specified is not correct, it does not contain any OpenEJB libraries.";
-
-    // TODO: move this part back into the LoaderServlet
-    private String INSTRUCTIONS = "Please edit the web.xml of the openejb_loader webapp and set the openejb.home init-param to the full path where OpenEJB is installed.";
-
-    private void checkOpenEjbHome(File openejbHome) throws Exception {
-        try {
-
-            String homePath = openejbHome.getAbsolutePath();
-
-            // The openejb.home must exist
-            if (!openejbHome.exists())
-                handleError(BAD_HOME + homePath, NOT_THERE, INSTRUCTIONS);
-
-            // The openejb.home must be a directory
-            if (!openejbHome.isDirectory())
-                handleError(BAD_HOME + homePath, NOT_DIRECTORY, INSTRUCTIONS);
-
-            // The openejb.home must contain a 'lib' directory
-            File openejbHomeLibs = new File(openejbHome, "lib");
-            if (!openejbHomeLibs.exists())
-                handleError(BAD_HOME + homePath, NO_LIBS, INSTRUCTIONS);
-
-            // The openejb.home there must be openejb*.jar files in the 'dist'
-            // directory
-            String[] libs = openejbHomeLibs.list();
-            boolean found = false;
-            for (int i = 0; i < libs.length && !found; i++) {
-                found = (libs[i].startsWith("openejb-") && libs[i].endsWith(".jar"));
-            }
-            if (!found)
-                handleError(BAD_HOME + homePath, NO_LIBS, INSTRUCTIONS);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    private void handleError(String m1, String m2, String m3) throws Exception {
-        System.err.println("--[PLEASE FIX]-------------------------------------");
-        System.err.println(m1);
-        System.err.println(m2);
-        System.err.println(m3);
-        System.err.println("---------------------------------------------------");
-        throw new Exception(m1 + " " + m2 + " " + m3);
-    }
-
-    private void handleError(String m1, String m2) throws Exception {
-        System.err.println("--[PLEASE FIX]-------------------------------------");
-        System.err.println(m1);
-        System.err.println(m2);
-        System.err.println("---------------------------------------------------");
-        throw new Exception(m1 + " " + m2);
-    }
-
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Embedder.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/Embedder.java) ( => )

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/FileUtils.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/FileUtils.java)

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Loader.java (2552 => 2554)

--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/Loader.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Loader.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,15 +0,0 @@
-package org.openejb.loader;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-public interface Loader {
-
-    public void init(ServletConfig servletConfig) throws ServletException;
-
-    void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
-}
-

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/Loader.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/Loader.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/LoaderServlet.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/LoaderServlet.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/LoaderServlet.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,160 +0,0 @@
-package org.openejb.loader;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Enumeration;
-import java.util.Properties;
-
-/**
- * @author <a href="" PROTECTED]">David Blevins </a>
- */
-public class LoaderServlet extends HttpServlet {
-
-    private Loader loader;
-
-    public void init(ServletConfig config) throws ServletException {
-        if (loader != null) {
-            return;
-        }
-
-        // Do just enough to get the Tomcat Loader into the classpath
-        // let it do the rest.
-        Properties p = initParamsToProperties(config);
-
-        String embeddingStyle = p.getProperty("openejb.loader");
-
-        // Set the mandatory values for a webapp-only setup
-        if (embeddingStyle.endsWith("tomcat-webapp")) {
-            setPropertyIfNUll(p, "openejb.base", getWebappPath(config));
-//            setPropertyIfNUll(p, "openejb.configuration", "META-INF/openejb.xml");
-//            setPropertyIfNUll(p, "openejb.container.decorators", "org.openejb.tomcat.TomcatJndiSupport");
-//            setPropertyIfNUll(p, "log4j.configuration", "META-INF/log4j.properties");
-        }
-
-        try {
-            SystemInstance.init(p);
-            Embedder embedder = new Embedder("org.openejb.tomcat.TomcatLoader");
-            Class loaderClass = embedder.load();
-            Object instance = loaderClass.newInstance();
-            try {
-                loader = (Loader) instance;
-            } catch (ClassCastException e) {
-                loader = new LoaderWrapper(instance);
-            }
-
-            loader.init(config);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
-    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-        loader.service(request, response);
-    }
-
-    private String getWebappPath(ServletConfig config) {
-        ServletContext ctx = config.getServletContext();
-        File webInf = new File(ctx.getRealPath("WEB-INF"));
-        File webapp = webInf.getParentFile();
-        String webappPath = webapp.getAbsolutePath();
-        return webappPath;
-    }
-
-    private Properties initParamsToProperties(ServletConfig config) {
-        Properties p = new Properties();
-
-        // Set some defaults
-        p.setProperty("openejb.loader", "tomcat");
-
-        // Load in each init-param as a property
-        Enumeration enumeration = config.getInitParameterNames();
-        System.out.println("OpenEJB init-params:");
-        while (enumeration.hasMoreElements()) {
-            String name = (String) enumeration.nextElement();
-            String value = config.getInitParameter(name);
-            p.put(name, value);
-            System.out.println("\tparam-name: " + name + ", param-value: " + value);
-        }
-
-        return p;
-    }
-
-    private Object setPropertyIfNUll(Properties properties, String key, String value) {
-        String currentValue = properties.getProperty(key);
-        if (currentValue == null) {
-            properties.setProperty(key, value);
-        }
-        return currentValue;
-    }
-
-    /**
-     * Ain't classloaders fun?
-     * This class exists to reconcile that loader implementations
-     * may exist in the parent classloader while the loader interface
-     * is also in this classloader.  Use this class in the event that
-     * this is the case.
-     * Think of this as an adapter for adapting the parent's idea of a
-     * Loader to our idea of a Loader.
-     */
-    public static class LoaderWrapper implements Loader {
-        private final Object loader;
-        private final Method init;
-        private final Method service;
-
-        public LoaderWrapper(Object loader) {
-            this.loader = loader;
-            try {
-                Class loaderClass = loader.getClass();
-                this.init = loaderClass.getMethod("init", new Class[]{ServletConfig.class});
-                this.service = loaderClass.getMethod("service", new Class[]{HttpServletRequest.class, HttpServletResponse.class});
-            } catch (NoSuchMethodException e) {
-                throw (IllegalStateException) new IllegalStateException("Signatures for Loader are no longer correct.").initCause(e);
-            }
-        }
-
-        public void init(ServletConfig servletConfig) throws ServletException {
-            try {
-                init.invoke(loader, new Object[]{servletConfig});
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof RuntimeException) {
-                    throw (RuntimeException) cause;
-                } else if (cause instanceof Error) {
-                    throw (Error) cause;
-                } else {
-                    throw (ServletException) cause;
-                }
-            } catch (Exception e) {
-                throw new RuntimeException("Loader.init: " + e.getMessage() + e.getClass().getName() + ": " + e.getMessage(), e);
-            }
-        }
-
-        public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-            try {
-                service.invoke(loader, new Object[]{request, response});
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof RuntimeException) {
-                    throw (RuntimeException) cause;
-                } else if (cause instanceof Error) {
-                    throw (Error) cause;
-                } else if (cause instanceof IOException) {
-                    throw (IOException) cause;
-                } else {
-                    throw (ServletException) cause;
-                }
-            } catch (Exception e) {
-                throw new RuntimeException("Loader.service: " + e.getMessage() + e.getClass().getName() + ": " + e.getMessage(), e);
-            }
-        }
-    }
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/LoaderServlet.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/LoaderServlet.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/OpenEJBInstance.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/OpenEJBInstance.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/OpenEJBInstance.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,125 +0,0 @@
-package org.openejb.loader;
-
-import org.openejb.loader.ClassPath;
-import org.openejb.loader.SystemInstance;
-import org.openejb.util.FileUtils;
-
-import javax.servlet.ServletException;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Properties;
-import java.io.File;
-
-public class OpenEJBInstance {
-    private final Class openejb;
-    private final Method init;
-    private final Method isInitialized;
-
-    public OpenEJBInstance() throws Exception {
-        this.openejb = loadOpenEJBClass();
-        this.init = openejb.getMethod("init", new Class[]{Properties.class});
-        this.isInitialized = openejb.getMethod("isInitialized", new Class[]{});
-    }
-
-    public void init(Properties props) throws Exception {
-        try {
-            init.invoke(null, new Object[]{props});
-        } catch (InvocationTargetException e) {
-            throw (Exception) e.getCause();
-        } catch (Exception e) {
-            throw new RuntimeException("OpenEJB.init: ", e);
-        }
-    }
-
-    public boolean isInitialized() {
-        try {
-            Boolean b = (Boolean) isInitialized.invoke(null, new Object[]{});
-            return b.booleanValue();
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException("OpenEJB.isInitialized: ", e.getCause());
-        } catch (Exception e) {
-            throw new RuntimeException("OpenEJB.isInitialized: ", e);
-        }
-    }
-
-    private Class loadOpenEJBClass() throws Exception {
-        ClassPath classPath = SystemInstance.get().getClassPath();
-        ClassLoader classLoader = classPath.getClassLoader();
-        try {
-            return classLoader.loadClass("org.openejb.OpenEJB");
-        } catch (Exception e) {
-            try {
-                checkOpenEjbHome(SystemInstance.get().getHome().getDirectory());
-                FileUtils home = SystemInstance.get().getHome();
-                classPath.addJarsToPath(home.getDirectory("lib"));
-            } catch (Exception e2) {
-                throw new Exception("Could not load OpenEJB libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
-            }
-            try {
-                return classLoader.loadClass("org.openejb.OpenEJB");
-            } catch (Exception e2) {
-                throw new Exception("Could not load OpenEJB class after embedding libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
-            }
-        }
-    }
-
-    String NO_HOME = "The openejb.home is not set.";
-
-    String BAD_HOME = "Invalid openejb.home: ";
-
-    String NOT_THERE = "The path specified does not exist.";
-
-    String NOT_DIRECTORY = "The path specified is not a directory.";
-
-    String NO_DIST = "The path specified is not correct, it does not contain a 'dist' directory.";
-
-    String NO_LIBS = "The path specified is not correct, it does not contain any OpenEJB libraries.";
-
-    String INSTRUCTIONS = "Please edit the web.xml of the openejb_loader webapp and set the openejb.home init-param to the full path where OpenEJB is installed.";
-
-    private void checkOpenEjbHome(File openejbHome) throws Exception {
-        try {
-
-            String homePath = openejbHome.getAbsolutePath();
-
-            if (!openejbHome.exists())
-                handleError(BAD_HOME + homePath, NOT_THERE, INSTRUCTIONS);
-
-            if (!openejbHome.isDirectory())
-                handleError(BAD_HOME + homePath, NOT_DIRECTORY, INSTRUCTIONS);
-
-            File openejbHomeLibs = new File(openejbHome, "lib");
-            if (!openejbHomeLibs.exists())
-                handleError(BAD_HOME + homePath, NO_DIST, INSTRUCTIONS);
-
-            String[] libs = openejbHomeLibs.list();
-            boolean found = false;
-            for (int i = 0; i < libs.length && !found; i++) {
-                found = (libs[i].startsWith("openejb-") && libs[i].endsWith(".jar"));
-            }
-            if (!found)
-                handleError(BAD_HOME + homePath, NO_LIBS, INSTRUCTIONS);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    private void handleError(String m1, String m2, String m3) throws Exception {
-        System.err.println("--[PLEASE FIX]-------------------------------------");
-        System.err.println(m1);
-        System.err.println(m2);
-        System.err.println(m3);
-        System.err.println("---------------------------------------------------");
-        throw new Exception(m1 + " " + m2 + " " + m3);
-    }
-
-    private void handleError(String m1, String m2) throws Exception {
-        System.err.println("--[PLEASE FIX]-------------------------------------");
-        System.err.println(m1);
-        System.err.println(m2);
-        System.err.println("---------------------------------------------------");
-        throw new Exception(m1 + " " + m2);
-    }
-
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/OpenEJBInstance.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/OpenEJBInstance.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/SystemClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,65 +0,0 @@
-package org.openejb.loader;
-
-import java.net.URLClassLoader;
-import java.net.URL;
-import java.io.File;
-
-/*-------------------------------------------------------*/
-/* 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 {
-
-        this.addJarToPath(jar, getSystemLoader());
-        this.rebuildJavaClassPathVariable();
-    }
-
-    public ClassLoader getClassLoader() {
-        try {
-            return getSystemLoader();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    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();
-
-        if (urls.length < 1)
-            return;
-
-        StringBuffer path = new StringBuffer(urls.length * 32);
-
-        File s = new File(urls[0].getFile());
-        path.append(s.getPath());
-
-        for (int i = 1; i < urls.length; i++) {
-            path.append(File.pathSeparator);
-
-            s = new File(urls[i].getFile());
-
-            path.append(s.getPath());
-        }
-        try {
-            System.setProperty("java.class.path", path.toString());
-        } catch (Exception e) {
-        }
-    }
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/SystemClassPath.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemInstance.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/SystemInstance.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemInstance.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,127 +0,0 @@
-package org.openejb.loader;
-
-import java.util.Properties;
-import java.util.HashMap;
-
-import org.openejb.util.FileUtils;
-
-/**
- * This class aims to be the one and only static in the entire system
- * A static, singleton, instance of this class can be created with the init(props) method
- *
- * It is assumed that only one singleton per classloader is possible in any given VM
- * Thus loading this instance in a classloader will mean there can only be one OpenEJB
- * instance for that classloader and all children classloaders.
- *
- * @version $Revision: 2172 $ $Date: 2005-09-20 16:58:27 -0700 (Tue, 20 Sep 2005) $
- */
-public class SystemInstance {
-
-    private final long startTime = System.currentTimeMillis();
-    private final Properties properties;
-    private final FileUtils home;
-    private final FileUtils base;
-    private final ClassLoader classLoader;
-    private final HashMap components;
-    private final ClassPath classPath;
-
-    private SystemInstance(Properties properties) throws Exception {
-        this.components = new HashMap();
-        this.properties = new Properties();
-        this.properties.putAll(System.getProperties());
-        this.properties.putAll(properties);
-
-        this.home = new FileUtils("openejb.home", "user.dir", this.properties);
-        this.base = new FileUtils("openejb.base", "openejb.home", this.properties);
-        this.classPath = ClassPathFactory.createClassPath(this.properties.getProperty("openejb.loader", "context"));
-        this.classLoader = classPath.getClassLoader();
-
-        this.properties.setProperty("openejb.home", home.getDirectory().getCanonicalPath());
-        this.properties.setProperty("openejb.base", base.getDirectory().getCanonicalPath());
-    }
-
-    public long getStartTime() {
-        return startTime;
-    }
-
-    public Properties getProperties() {
-        return properties;
-    }
-
-    public String getProperty(String key) {
-        return properties.getProperty(key);
-    }
-
-    public String getProperty(String key, String defaultValue) {
-        return properties.getProperty(key, defaultValue);
-    }
-
-    public Object setProperty(String key, String value) {
-        return properties.setProperty(key, value);
-    }
-
-    public FileUtils getHome() {
-        return home;
-    }
-
-    public FileUtils getBase() {
-        return base;
-    }
-
-    public ClassPath getClassPath() {
-        return classPath;
-    }
-
-    public ClassLoader getClassLoader() {
-        return classLoader;
-    }
-
-    /**
-     * I'm not sure how this will play out, but I've used class instances instead of strings
-     * for lookups as class instances are classloader scoped and there is an implicit "namespace"
-     * associated with that.  Theoretically, you can't lookup things that you can't already see
-     * in your classloader.
-     *
-     * @param type
-     * @return the object associated with the class type or null
-     * @throws IllegalStateException of the component isn't found
-     */
-    public Object getComponent(Class type) throws IllegalStateException {
-        Object component = components.get(type);
-        if (component == null){
-            throw new IllegalStateException("No such component exists: "+type.getName() +"(scope: "+type.getClassLoader()+")");
-        }
-        return components.get(type);
-    }
-
-    /**
-     *
-     * @param type the class type of the component required
-     */
-    public Object setComponent(Class type, Object value) {
-        return components.put(type, value);
-    }
-
-    private static SystemInstance system;
-
-    static {
-        try {
-            system = new SystemInstance(System.getProperties());
-        } catch (Exception e) {
-            throw new RuntimeException("Failed to create default instance of SystemInstance", e);
-        }
-    }
-
-    private static boolean initialized;
-
-    public static void init(Properties properties) throws Exception {
-        if (initialized) return;
-        system = new SystemInstance(properties);
-        initialized = true;
-    }
-
-    public static SystemInstance get() {
-        return system;
-    }
-
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/SystemInstance.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/SystemInstance.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/TomcatClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/TomcatClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/TomcatClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,141 +0,0 @@
-package org.openejb.loader;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/*-------------------------------------------------------*/
-/* Tomcat ClassLoader Support */
-/*-------------------------------------------------------*/
-
-public class TomcatClassPath extends BasicURLClassPath {
-
-    private final ClassLoader classLoader;
-
-    private Method addRepositoryMethod;
-    private Method addURLMethod;
-
-    public TomcatClassPath() {
-        this(getCommonLoader(getContextClassLoader()).getParent());
-    }
-
-    public TomcatClassPath(ClassLoader classLoader) {
-        this.classLoader = classLoader;
-        try {
-            addRepositoryMethod = getAddRepositoryMethod();
-        } catch (Exception tomcat4Exception) {
-
-            try {
-                addURLMethod = getAddURLMethod();
-            } catch (Exception tomcat5Exception) {
-                throw new RuntimeException("Failed accessing classloader for Tomcat 4 or 5", tomcat5Exception);
-            }
-        }
-    }
-
-    private static ClassLoader getCommonLoader(ClassLoader loader) {
-        if (loader.getClass().getName().equals("org.apache.catalina.loader.StandardClassLoader")) {
-            return loader;
-        } else {
-            return getCommonLoader(loader.getParent());
-        }
-    }
-
-    public ClassLoader getClassLoader() {
-        return classLoader;
-    }
-
-    public void addJarsToPath(File dir) throws Exception {
-        String[] jarNames = dir.list(new java.io.FilenameFilter() {
-            public boolean accept(File dir, String 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 {
-        this._addJarToPath(jar);
-        rebuild();
-    }
-
-    public void _addJarToPath(URL jar) throws Exception {
-        if (addRepositoryMethod != null) {
-            String path = jar.toExternalForm();
-            addRepositoryMethod.invoke(getClassLoader(), new Object[]{path});
-        } else {
-            addURLMethod.invoke(getClassLoader(), new Object[]{jar});
-        }
-    }
-
-    protected void rebuild() {
-        try {
-            sun.misc.URLClassPath cp = getURLClassPath((URLClassLoader) getClassLoader());
-            URL[] urls = cp.getURLs();
-
-            if (urls.length < 1)
-                return;
-
-            StringBuffer path = new StringBuffer(urls.length * 32);
-
-            File s = new File(urls[0].getFile());
-            path.append(s.getPath());
-
-            for (int i = 1; i < urls.length; i++) {
-                path.append(File.pathSeparator);
-
-                s = new File(urls[i].getFile());
-
-                path.append(s.getPath());
-            }
-            System.setProperty("java.class.path", path.toString());
-        } catch (Exception e) {
-        }
-
-    }
-
-    private java.lang.reflect.Method getAddURLMethod() throws Exception {
-        return (java.lang.reflect.Method) AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                java.lang.reflect.Method method = null;
-                try {
-                    Class clazz = URLClassLoader.class;
-                    method = clazz.getDeclaredMethod("addURL", new Class[]{URL.class});
-                    method.setAccessible(true);
-                    return method;
-                } catch (Exception e2) {
-                    e2.printStackTrace();
-                }
-                return method;
-            }
-        });
-    }
-
-    private Method getAddRepositoryMethod() throws Exception {
-        return (Method) AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                Method method = null;
-                try {
-                    Class clazz = getClassLoader().getClass();
-                    method = clazz.getDeclaredMethod("addRepository", new Class[]{String.class});
-                    method.setAccessible(true);
-                    return method;
-                } catch (Exception e2) {
-                    throw (IllegalStateException) new IllegalStateException("Unable to find or access the addRepository method in StandardClassLoader").initCause(e2);
-                }
-            }
-        });
-    }
-
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/TomcatClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/TomcatClassPath.java) ( => )

Deleted: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/WebAppClassPath.java
===================================================================
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/WebAppClassPath.java	2006-03-14 20:31:37 UTC (rev 2552)
+++ trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/WebAppClassPath.java	2006-03-14 20:49:33 UTC (rev 2554)
@@ -1,15 +0,0 @@
-package org.openejb.loader;
-
-public class WebAppClassPath extends TomcatClassPath {
-
-    public WebAppClassPath() {
-        this(getContextClassLoader());
-    }
-
-    public WebAppClassPath(ClassLoader classLoader) {
-        super(classLoader);
-    }
-
-    protected void rebuild() {
-    }
-}

Copied: trunk/openejb3/container/openejb-loader/src/main/java/org/openejb/loader/WebAppClassPath.java (from rev 2553, trunk/openejb3/container/openejb-core/src/main/java/org/openejb/loader/WebAppClassPath.java) ( => )

Modified: trunk/openejb3/container/pom.xml
===================================================================
--- trunk/openejb3/container/pom.xml	2006-03-14 20:34:23 UTC (rev 2553)
+++ trunk/openejb3/container/pom.xml	2006-03-14 20:49:33 UTC (rev 2554)
@@ -12,5 +12,6 @@
   <name>OpenEJB :: Container POM</name>
   <modules>
     <module>openejb-core</module>
+    <module>openejb-loader</module>
   </modules>
 </project>

Reply via email to