geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r471382 - in /geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel: classloader/JarFileClassLoader.java config/MultiParentClassLoader.java
Date Sun, 05 Nov 2006 09:01:40 GMT
Author: djencks
Date: Sun Nov  5 01:01:39 2006
New Revision: 471382

URL: http://svn.apache.org/viewvc?view=rev&rev=471382
Log:
GERONIMO-2460  Provide way to copy our classloaders for use as jpa temporary classloaders

Modified:
    geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
    geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java

Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java?view=diff&rev=471382&r1=471381&r2=471382
==============================================================================
--- geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
(original)
+++ geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
Sun Nov  5 01:01:39 2006
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.net.URL;
 import java.net.URI;
+import java.net.URLClassLoader;
 import java.security.AccessControlContext;
 import java.security.AccessController;
 import java.security.CodeSource;
@@ -105,6 +106,28 @@
         super(id, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
         this.acc = AccessController.getContext();
         addURLs(urls);
+    }
+
+    public JarFileClassLoader(JarFileClassLoader source) {
+        super(source);
+        this.acc = AccessController.getContext();
+        addURLs(source.getURLs());
+    }
+
+    public static ClassLoader copy(ClassLoader source) {
+        if (source instanceof JarFileClassLoader) {
+            return new JarFileClassLoader((JarFileClassLoader) source);
+        } else if (source instanceof MultiParentClassLoader) {
+            return new MultiParentClassLoader((MultiParentClassLoader) source);
+        } else if (source instanceof URLClassLoader) {
+            return new URLClassLoader(((URLClassLoader)source).getURLs(), source.getParent());
+        } else {
+            return new URLClassLoader(new URL[0], source);
+        }
+    }
+
+    ClassLoader copy() {
+        return JarFileClassLoader.copy(this);
     }
 
     /**

Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java?view=diff&rev=471382&r1=471381&r2=471382
==============================================================================
--- geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
(original)
+++ geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
Sun Nov  5 01:01:39 2006
@@ -133,6 +133,24 @@
         nonOverridableResources = toResources(nonOverridableClasses);
     }
 
+    public MultiParentClassLoader(MultiParentClassLoader source) {
+        this(source.id, source.getURLs(), deepCopyParents(source.parents), source.inverseClassLoading,
source.hiddenClasses, source.nonOverridableClasses);
+    }
+
+    static ClassLoader copy(ClassLoader source) {
+        if (source instanceof MultiParentClassLoader) {
+            return new MultiParentClassLoader((MultiParentClassLoader) source);
+        } else if (source instanceof URLClassLoader) {
+            return new URLClassLoader(((URLClassLoader)source).getURLs(), source.getParent());
+        } else {
+            return new URLClassLoader(new URL[0], source);
+        }
+    }
+
+    ClassLoader copy() {
+        return MultiParentClassLoader.copy(this);
+    }
+
     private String[] toResources(String[] classes) {
         String[] resources = new String[classes.length];
         for (int i = 0; i < classes.length; i++) {
@@ -168,6 +186,21 @@
             ClassLoader parent = parents[i];
             if (parent == null) {
                 throw new NullPointerException("parent[" + i + "] is null");
+            }
+            newParentsArray[i] = parent;
+        }
+        return newParentsArray;
+    }
+
+    private static ClassLoader[] deepCopyParents(ClassLoader[] parents) {
+        ClassLoader[] newParentsArray = new ClassLoader[parents.length];
+        for (int i = 0; i < parents.length; i++) {
+            ClassLoader parent = parents[i];
+            if (parent == null) {
+                throw new NullPointerException("parent[" + i + "] is null");
+            }
+            if (parent instanceof MultiParentClassLoader) {
+                parent = ((MultiParentClassLoader)parent).copy();
             }
             newParentsArray[i] = parent;
         }



Mime
View raw message