dblevins    2005/08/16 00:18:56

  Modified:    modules/core/src/java/org/openejb/util SafeToolkit.java
  Log:

  Killed the temp codebase functionality from SafeToolkit.  Added new class
  TempCodebase which is not static.  Refactored nearly all code using the
  SafeToolkit.loadTempClass to use just a classloader instead.  Code for 
creating
  "temp" jars for validation and other deployment related classloading is now in
  one spot (instead of everywhere a class is loaded) and can now be safely 
avoided
  for unpacked ejb jars--we don't want to copy entire directories when we 
validate
  an unpacked ejb jar.
  
  Revision  Changes    Path
  1.7       +0 -109    
openejb1/modules/core/src/java/org/openejb/util/SafeToolkit.java
  
  Index: SafeToolkit.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/util/SafeToolkit.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SafeToolkit.java  16 Aug 2005 01:05:03 -0000      1.6
  +++ SafeToolkit.java  16 Aug 2005 04:18:56 -0000      1.7
  @@ -55,7 +55,6 @@
       private String systemLocation;
       public static final Messages messages = new 
Messages("org.openejb.util.resources");
       public static final HashMap codebases = new HashMap();
  -    protected static final HashMap _tempcodebases = new HashMap();
   
       /**
        * Creates a new SafeToolkit dedicated to the specified system location.
  @@ -298,112 +297,4 @@
       }
   
   
  -    /**
  -     * Loads the class using the class loader for the specific
  -     * codebase.  If the codebase is null, the bootstrap classloader
  -     * is used.
  -     *
  -     * @param className
  -     * @param codebase
  -     * @return Class
  -     * @throws OpenEJBException
  -     */
  -    public static Class loadTempClass(String className, String codebase) 
throws OpenEJBException {
  -        return loadTempClass(className, codebase, true);
  -    }
  -
  -    public static Class loadTempClass(String className, String codebase, 
boolean cache) throws OpenEJBException {
  -
  -        ClassLoader cl = (cache) ? getCodebaseTempClassLoader(codebase) : 
getTempClassLoader(codebase);
  -        Class clazz = null;
  -        try {
  -            clazz = cl.loadClass(className);
  -        } catch (ClassNotFoundException cnfe) {
  -            throw new OpenEJBException(messages.format("cl0007", className, 
codebase));
  -        }
  -        return clazz;
  -    }
  -
  -    public static void unloadTempCodebase(String codebase) {
  -        //TODO Delete temp jar
  -        _tempcodebases.remove(codebase);
  -    }
  -
  -    /**
  -     * Ensures that a class loader for each code base used in the
  -     * system is created at most one time.  The default bootsrap
  -     * classloader is used if codebase is null.
  -     *
  -     * @param codebase
  -     * @return ClassLoader
  -     * @throws OpenEJBException
  -     */
  -    protected static ClassLoader getCodebaseTempClassLoader(String codebase) 
throws OpenEJBException {
  -        if (codebase == null) codebase = "CLASSPATH";
  -
  -        ClassLoader cl = (ClassLoader) _tempcodebases.get(codebase);
  -        if (cl == null) {
  -            synchronized (codebases) {
  -                cl = (ClassLoader) codebases.get(codebase);
  -                if (cl == null) {
  -                    try {
  -                        java.net.URL[] urlCodebase = new java.net.URL[1];
  -                        urlCodebase[0] = createTempCopy(codebase).toURL();
  -
  -// make sure everything works if we were not loaded by the system class 
loader
  -                        cl = new java.net.URLClassLoader(urlCodebase, 
SafeToolkit.class.getClassLoader());
  -
  -                        _tempcodebases.put(codebase, cl);
  -                    } catch (java.net.MalformedURLException mue) {
  -                        throw new OpenEJBException(messages.format("cl0001", 
codebase, mue.getMessage()));
  -                    } catch (SecurityException se) {
  -                        throw new OpenEJBException(messages.format("cl0002", 
codebase, se.getMessage()));
  -                    }
  -                }
  -            }
  -        }
  -        return cl;
  -    }
  -
  -    /**
  -     * Ensures that a class loader for each code base used in the
  -     * system is created at most one time.  The default bootsrap
  -     * classloader is used if codebase is null.
  -     *
  -     * @param codebase
  -     * @return ClassLoader
  -     * @throws OpenEJBException
  -     */
  -    protected static ClassLoader getTempClassLoader(String codebase) throws 
OpenEJBException {
  -        ClassLoader cl = null;
  -        try {
  -            java.net.URL[] urlCodebase = new java.net.URL[1];
  -            urlCodebase[0] = createTempCopy(codebase).toURL();
  -
  -            // make sure everything works if we were not loaded by the 
system class loader
  -            cl = new java.net.URLClassLoader(urlCodebase, 
SafeToolkit.class.getClassLoader());
  -        } catch (java.net.MalformedURLException mue) {
  -            throw new OpenEJBException(messages.format("cl0001", codebase, 
mue.getMessage()));
  -        } catch (SecurityException se) {
  -            throw new OpenEJBException(messages.format("cl0002", codebase, 
se.getMessage()));
  -        }
  -        return cl;
  -    }
  -
  -    protected static File createTempCopy(String codebase) throws 
OpenEJBException {
  -        File file = null;
  -
  -        try {
  -            File codebaseFile = new File(codebase);
  -//            if (codebaseFile.isDirectory()) return codebaseFile;
  -
  -            file = File.createTempFile("openejb_validate", ".jar", null);
  -            file.deleteOnExit();
  -
  -            FileUtils.copyFile(file, codebaseFile);
  -        } catch (Exception e) {
  -            throw new OpenEJBException(messages.format("cl0002", codebase, 
e.getMessage()));
  -        }
  -        return file;
  -    }
   }
  
  
  

Reply via email to