You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ad...@apache.org on 2006/08/28 08:14:50 UTC

svn commit: r437551 [1/2] - in /geronimo/xbean/trunk: ./ xbean-classloader/ xbean-classloader/src/ xbean-classloader/src/main/java/org/apache/xbean/classloader/ xbean-classloader/src/main/java/org/apache/xbean/server/classloader/ xbean-classloader/src/...

Author: adc
Date: Sun Aug 27 23:14:47 2006
New Revision: 437551

URL: http://svn.apache.org/viewvc?rev=437551&view=rev
Log:
XBEAN-45 Move classloaders to their own module

Added:
    geronimo/xbean/trunk/xbean-classloader/
      - copied from r437430, geronimo/xbean/trunk/xbean-server/
    geronimo/xbean/trunk/xbean-classloader/LICENSE.txt
      - copied unchanged from r437542, geronimo/xbean/trunk/xbean-server/LICENSE.txt
    geronimo/xbean/trunk/xbean-classloader/NOTICE.txt
      - copied unchanged from r437542, geronimo/xbean/trunk/xbean-server/NOTICE.txt
    geronimo/xbean/trunk/xbean-classloader/pom.xml
      - copied, changed from r437542, geronimo/xbean/trunk/xbean-server/pom.xml
    geronimo/xbean/trunk/xbean-classloader/src/
      - copied from r437542, geronimo/xbean/trunk/xbean-server/src/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/NamedClassLoader.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ResourceEnumeration.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ResourceFinder.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ResourceHandle.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ResourceLocation.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ThreadContextClassLoaderFactoryBean.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/UnionEnumeration.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/UrlResourceFinder.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/classloader/
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/classloader/JarFileClassLoaderTest.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/classloader/MultiParentClassLoaderTest.java   (with props)
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/classloader/UrlResourceFinderTest.java   (with props)
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/
      - copied from r437542, geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/classloader/
      - copied from r437542, geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/classloader/
Removed:
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/classloader/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/deployer/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/loader/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/main/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/propertyeditor/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/repository/
    geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/server/spring/
    geronimo/xbean/trunk/xbean-classloader/src/main/resources/META-INF/xbean-bootstrap.xml
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/server/classloader/
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/server/deployer/
    geronimo/xbean/trunk/xbean-classloader/src/test/java/org/apache/xbean/server/spring/
    geronimo/xbean/trunk/xbean-classloader/src/test/repository/
    geronimo/xbean/trunk/xbean-classloader/src/test/resources/
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/IoUtil.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/NamedClassLoader.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ResourceEnumeration.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ResourceFinder.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ResourceHandle.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ResourceLocation.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/ThreadContextClassLoaderFactoryBean.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/UnionEnumeration.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/classloader/UrlResourceFinder.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/classloader/
    geronimo/xbean/trunk/xbean-server/src/test-data/
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/classloader/JarFileClassLoaderTest.java
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/classloader/MultiParentClassLoaderTest.java
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/classloader/UrlResourceFinderTest.java
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/classloader/
Modified:
    geronimo/xbean/trunk/pom.xml
    geronimo/xbean/trunk/xbean-server/pom.xml
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/deployer/FileDeployer.java
    geronimo/xbean/trunk/xbean-server/src/main/java/org/apache/xbean/server/spring/configuration/ClassLoaderXmlPreprocessor.java
    geronimo/xbean/trunk/xbean-server/src/test/java/org/apache/xbean/server/spring/loader/SpringLoaderTest.java

Modified: geronimo/xbean/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/pom.xml?rev=437551&r1=437550&r2=437551&view=diff
==============================================================================
--- geronimo/xbean/trunk/pom.xml (original)
+++ geronimo/xbean/trunk/pom.xml Sun Aug 27 23:14:47 2006
@@ -251,6 +251,7 @@
     </build>
     
     <modules>
+        <module>xbean-classloader</module>
         <module>xbean-classpath</module>
         <module>xbean-kernel</module>
         <module>xbean-osgi</module>

Copied: geronimo/xbean/trunk/xbean-classloader/pom.xml (from r437542, geronimo/xbean/trunk/xbean-server/pom.xml)
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/pom.xml?p2=geronimo/xbean/trunk/xbean-classloader/pom.xml&p1=geronimo/xbean/trunk/xbean-server/pom.xml&r1=437542&r2=437551&rev=437551&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-server/pom.xml (original)
+++ geronimo/xbean/trunk/xbean-classloader/pom.xml Sun Aug 27 23:14:47 2006
@@ -20,7 +20,8 @@
 
 <!-- $Rev: 432962 $ $Date: 2006-08-20 03:47:39 -0700 (Sun, 20 Aug 2006) $ -->
 
-<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">
+<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">
 
     <modelVersion>4.0.0</modelVersion>
 
@@ -30,41 +31,9 @@
         <version>2.6-SNAPSHOT</version>
     </parent>
 
-    <artifactId>xbean-server</artifactId>
-    <name>XBean :: Server</name>
-
-    <dependencies>
-    
-        <dependency>
-            <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-spring</artifactId>
-            <version>${pom.version}</version>
-        </dependency>
-        
-        <dependency>
-            <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-kernel</artifactId>
-            <version>${pom.version}</version>
-        </dependency>
-        
-        <dependency>
-            <groupId>mx4j</groupId>
-            <artifactId>mx4j</artifactId>
-            <optional>true</optional>
-        </dependency>
-        
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-        </dependency>
-        
-        <dependency>
-            <groupId>cglib</groupId>
-            <artifactId>cglib-nodep</artifactId>
-            <scope>test</scope>
-        </dependency>
-        
-    </dependencies>
+    <artifactId>xbean-classloader</artifactId>
+    <name>XBean :: Classloader</name>
+    <version>2.6-SNAPSHOT</version>
 
     <build>
         <plugins>
@@ -87,10 +56,21 @@
                     </execution>
                 </executions>
                 <configuration>
-                    <namespace>http://xbean.apache.org/schemas/server</namespace>
+                    <namespace>http://xbean.apache.org/schemas/classloader</namespace>
                 </configuration>
             </plugin>
         </plugins>
     </build>
 
+    <dependencies>
+        <dependency>
+            <groupId>cglib</groupId>
+            <artifactId>cglib-nodep</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+        </dependency>
+    </dependencies>
 </project>

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractResourceHandle implements ResourceHandle {
+    public byte[] getBytes() throws IOException {
+        InputStream in = getInputStream();
+        try {
+            byte[] bytes = IoUtil.getBytes(in);
+            return bytes;
+        } finally {
+            IoUtil.close(in);
+        }
+    }
+
+    public Manifest getManifest() throws IOException {
+        return null;
+    }
+
+    public Certificate[] getCertificates() {
+        return null;
+    }
+
+    public Attributes getAttributes() throws IOException {
+        Manifest m = getManifest();
+        if (m == null) {
+            return null;
+        }
+
+        String entry = getUrl().getFile();
+        return m.getAttributes(entry);
+    }
+
+    public void close() {
+    }
+
+    public String toString() {
+        return "[" + getName() + ": " + getUrl() + "; code source: " + getCodeSourceUrl() + "]";
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractResourceHandle.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractUrlResourceLocation implements ResourceLocation {
+    private final URL codeSource;
+
+    public AbstractUrlResourceLocation(URL codeSource) {
+        this.codeSource = codeSource;
+    }
+
+    public final URL getCodeSource() {
+        return codeSource;
+    }
+
+    public void close() {
+    }
+
+    public final boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        AbstractUrlResourceLocation that = (AbstractUrlResourceLocation) o;
+        return codeSource.equals(that.codeSource);
+    }
+
+    public final int hashCode() {
+        return codeSource.hashCode();
+    }
+
+    public final String toString() {
+        return "[" + getClass().getName() + ": " + codeSource + "]";
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/AbstractUrlResourceLocation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.util.Map;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.beans.Introspector;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+
+/**
+ * Utility methods for class loader manipulation in a server environment.
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.0
+ */
+public final class ClassLoaderUtil {
+    private ClassLoaderUtil() {
+    }
+
+    /**
+     * Cleans well known class loader leaks in VMs and libraries.  There is a lot of bad code out there and this method
+     * will clear up the know problems.  This method should only be called when the class loader will no longer be used.
+     * It this method is called two often it can have a serious impact on preformance.
+     * @param classLoader the class loader to destroy
+     */
+    public static void destroy(ClassLoader classLoader) {
+        releaseCommonsLoggingCache(classLoader);
+        clearSunSoftCache(ObjectInputStream.class, "subclassAudits");
+        clearSunSoftCache(ObjectOutputStream.class, "subclassAudits");
+        clearSunSoftCache(ObjectStreamClass.class, "localDescs");
+        clearSunSoftCache(ObjectStreamClass.class, "reflectors");
+        Introspector.flushCaches();
+    }
+
+    /**
+     * Clears the caches maintained by the SunVM object stream implementation.  This method uses reflection and
+     * setAccessable to obtain access to the Sun cache.  The cache is locked with a synchronize monitor and cleared.
+     * This method completely clears the class loader cache which will impact preformance of object serialization.
+     * @param clazz the name of the class containing the cache field
+     * @param fieldName the name of the cache field
+     */
+    public static void clearSunSoftCache(Class clazz, String fieldName) {
+        Map cache = null;
+        try {
+            Field field = clazz.getDeclaredField(fieldName);
+            field.setAccessible(true);
+            cache = (Map) field.get(null);
+        } catch (Throwable ignored) {
+            // there is nothing a user could do about this anyway
+        }
+
+        if (cache != null) {
+            synchronized (cache) {
+                cache.clear();
+            }
+        }
+    }
+
+    /**
+     * Releases the specified classloader from the Apache Jakarta Commons Logging class loader cache using reflection.
+     * @param classLoader the class loader to release
+     */
+    public static void releaseCommonsLoggingCache(ClassLoader classLoader) {
+        try {
+            Class logFactory = classLoader.loadClass("org.apache.commons.logging.LogFactory");
+            Method release = logFactory.getMethod("release", new Class[] {ClassLoader.class});
+            release.invoke(null, new Object[] {classLoader});
+        } catch (Throwable ignored) {
+            // there is nothing a user could do about this anyway
+        }
+    }
+
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/ClassLoaderUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+/**
+ * DestroyableClassLoader is a mixin interface for a ClassLoader that add a destroy method to propertly cleanup a
+ * classloader then dereferenced by the server.
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.0
+ */
+public interface DestroyableClassLoader {
+    /**
+     * Destroys the clasloader releasing all resources.  After this mehtod is called, the class loader will no longer
+     * load any classes or resources.
+     */
+    void destroy();
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DestroyableClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DirectoryResourceHandle extends AbstractResourceHandle {
+    private final String name;
+    private final File file;
+    private final Manifest manifest;
+    private final URL url;
+    private final URL codeSource;
+
+    public DirectoryResourceHandle(String name, File file, File codeSource, Manifest manifest) throws MalformedURLException {
+        this.name = name;
+        this.file = file;
+        this.codeSource = codeSource.toURL();
+        this.manifest = manifest;
+        url = file.toURL();
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public URL getCodeSourceUrl() {
+        return codeSource;
+    }
+
+    public boolean isDirectory() {
+        return file.isDirectory();
+    }
+
+    public InputStream getInputStream() throws IOException {
+        if (file.isDirectory()) {
+            return new IoUtil.EmptyInputStream();
+        }
+        return new FileInputStream(file);
+    }
+
+    public int getContentLength() {
+        if (file.isDirectory() || file.length() > Integer.MAX_VALUE) {
+            return -1;
+        } else {
+            return (int) file.length();
+        }
+    }
+
+    public Manifest getManifest() throws IOException {
+        return manifest;
+    }
+
+    public Attributes getAttributes() throws IOException {
+        if (manifest == null) {
+            return null;
+        }
+        return manifest.getAttributes(getName());
+    }
+
+    /**
+     * Always return null.  This could be implementd by verifing the signatures
+     * in the manifest file against the actual file, but we don't need this right now.
+     * @return null
+     */
+    public Certificate[] getCertificates() {
+        return null;
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceHandle.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DirectoryResourceLocation extends AbstractUrlResourceLocation {
+    private final File baseDir;
+    private boolean manifestLoaded = false;
+    private Manifest manifest;
+
+    public DirectoryResourceLocation(File baseDir) throws MalformedURLException {
+        super(baseDir.toURL());
+        this.baseDir = baseDir;
+    }
+
+    public ResourceHandle getResourceHandle(String resourceName) {
+        File file = new File(baseDir, resourceName);
+        if (!file.exists()) {
+            return null;
+        }
+
+        try {
+            ResourceHandle resourceHandle = new DirectoryResourceHandle(resourceName, file, baseDir, getManifestSafe());
+            return resourceHandle;
+        } catch (MalformedURLException e) {
+            return null;
+        }
+    }
+
+    public Manifest getManifest() throws IOException {
+        if (!manifestLoaded) {
+            File manifestFile = new File(baseDir, "META-INF/MANIFEST.MF");
+
+            if (manifestFile.isFile() && manifestFile.canRead()) {
+                FileInputStream in = null;
+                try {
+                    in = new FileInputStream(manifestFile);
+                    manifest = new Manifest(in);
+                } finally {
+                    IoUtil.close(in);
+                }
+            }
+            manifestLoaded = true;
+        }
+        return manifest;
+    }
+
+    private Manifest getManifestSafe() {
+        Manifest manifest = null;
+        try {
+            manifest = getManifest();
+        } catch (IOException e) {
+            // ignore
+        }
+        return manifest;
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/DirectoryResourceLocation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,145 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.jar.JarFile;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class IoUtil {
+    private IoUtil() {
+    }
+
+    public static byte[] getBytes(InputStream inputStream) throws IOException {
+        try {
+            byte[] buffer = new byte[4096];
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
+                out.write(buffer, 0, count);
+            }
+            byte[] bytes = out.toByteArray();
+            return bytes;
+        } finally {
+            close(inputStream);
+        }
+    }
+
+    public static void flush(OutputStream thing) {
+        if (thing != null) {
+            try {
+                thing.flush();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void flush(Writer thing) {
+        if (thing != null) {
+            try {
+                thing.flush();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void close(JarFile thing) {
+        if (thing != null) {
+            try {
+                thing.close();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void close(InputStream thing) {
+        if (thing != null) {
+            try {
+                thing.close();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void close(OutputStream thing) {
+        if (thing != null) {
+            try {
+                thing.close();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void close(Reader thing) {
+        if (thing != null) {
+            try {
+                thing.close();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static void close(Writer thing) {
+        if (thing != null) {
+            try {
+                thing.close();
+            } catch(Exception ignored) {
+            }
+        }
+    }
+
+    public static final class EmptyInputStream extends InputStream {
+        public int read() {
+            return -1;
+        }
+
+        public int read(byte b[])  {
+            return -1;
+        }
+
+        public int read(byte b[], int off, int len) {
+            return -1;
+        }
+
+        public long skip(long n) {
+            return 0;
+        }
+
+        public int available() {
+            return 0;
+        }
+
+        public void close() {
+        }
+
+        public synchronized void mark(int readlimit) {
+        }
+
+        public synchronized void reset() {
+        }
+
+        public boolean markSupported() {
+            return false;
+        }
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/IoUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,344 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.IOException;
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.CodeSource;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+import java.security.cert.Certificate;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * The JarFileClassLoader that loads classes and resources from a list of JarFiles.  This method is simmilar to URLClassLoader
+ * except it properly closes JarFiles when the classloader is destroyed so that the file read lock will be released, and
+ * the jar file can be modified and deleted.
+ * <p>
+ * Note: This implementation currently does not work reliably on windows, since the jar URL handler included with the Sun JavaVM
+ * holds a read lock on the JarFile, and this lock is not released when the jar url is dereferenced.  To fix this a
+ * replacement for the jar url handler must be written.
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.0
+ */
+public class JarFileClassLoader extends MultiParentClassLoader {
+    private static final URL[] EMPTY_URLS = new URL[0];
+
+    private final UrlResourceFinder resourceFinder = new UrlResourceFinder();
+    private final AccessControlContext acc;
+
+    /**
+     * Creates a JarFileClassLoader that is a child of the system class loader.
+     * @param name the name of this class loader
+     * @param urls a list of URLs from which classes and resources should be loaded
+     */
+    public JarFileClassLoader(String name, URL[] urls) {
+        super(name, EMPTY_URLS);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    /**
+     * Creates a JarFileClassLoader that is a child of the specified class loader.
+     * @param name the name of this class loader
+     * @param urls a list of URLs from which classes and resources should be loaded
+     * @param parent the parent of this class loader
+     */
+    public JarFileClassLoader(String name, URL[] urls, ClassLoader parent) {
+        super(name, EMPTY_URLS, parent);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(name, EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parents.
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parents the parents of this class loader
+     */
+    public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents) {
+        super(name, EMPTY_URLS, parents);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
+        super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+        this.acc = AccessController.getContext();
+        addURLs(urls);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URL[] getURLs() {
+        return resourceFinder.getUrls();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addURL(final URL url) {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                resourceFinder.addUrl(url);
+                return null;
+            }
+        }, acc);
+    }
+
+    /**
+     * Adds an array of urls to the end of this class loader.
+     * @param urls the URLs to add
+     */
+    protected void addURLs(final URL[] urls) {
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                resourceFinder.addUrls(urls);
+                return null;
+            }
+        }, acc);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void destroy() {
+        resourceFinder.destroy();
+        super.destroy();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URL findResource(final String resourceName) {
+        return (URL) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return resourceFinder.findResource(resourceName);
+            }
+        }, acc);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Enumeration findResources(final String resourceName) throws IOException {
+        // todo this is not right
+        // first get the resources from the parent classloaders
+        Enumeration parentResources = super.findResources(resourceName);
+
+        // get the classes from my urls
+        Enumeration myResources = (Enumeration) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return resourceFinder.findResources(resourceName);
+            }
+        }, acc);
+
+        // join the two together
+        Enumeration resources = new UnionEnumeration(parentResources, myResources);
+        return resources;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected String findLibrary(String libraryName) {
+        // if the libraryName is actually a directory it is invalid
+        int pathEnd = libraryName.lastIndexOf('/');
+        if (pathEnd == libraryName.length() - 1) {
+            throw new IllegalArgumentException("libraryName ends with a '/' character: " + libraryName);
+        }
+
+        // get the name if the library file
+        final String resourceName;
+        if (pathEnd < 0) {
+            resourceName = System.mapLibraryName(libraryName);
+        } else {
+            String path = libraryName.substring(0, pathEnd + 1);
+            String file = libraryName.substring(pathEnd + 1);
+            resourceName = path + System.mapLibraryName(file);
+        }
+
+        // get a resource handle to the library
+        ResourceHandle resourceHandle = (ResourceHandle) AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return resourceFinder.getResource(resourceName);
+            }
+        }, acc);
+
+        if (resourceHandle == null) {
+            return null;
+        }
+
+        // the library must be accessable on the file system
+        URL url = resourceHandle.getUrl();
+        if (!"file".equals(url.getProtocol())) {
+            return null;
+        }
+
+        String path = new File(URI.create(url.toString())).getPath();
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Class findClass(final String className) throws ClassNotFoundException {
+        try {
+            return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() throws ClassNotFoundException {
+                    // first think check if we are allowed to define the package
+                    SecurityManager securityManager = System.getSecurityManager();
+                    if (securityManager != null) {
+                        String packageName;
+                        int packageEnd = className.lastIndexOf('.');
+                        if (packageEnd >= 0) {
+                            packageName = className.substring(0, packageEnd);
+                            securityManager.checkPackageDefinition(packageName);
+                        }
+                    }
+
+
+                    // convert the class name to a file name
+                    String resourceName = className.replace('.', '/') + ".class";
+
+                    // find the class file resource
+                    ResourceHandle resourceHandle = resourceFinder.getResource(resourceName);
+                    if (resourceHandle == null) {
+                        throw new ClassNotFoundException(className);
+                    }
+
+                    byte[] bytes;
+                    Manifest manifest;
+                    try {
+                        // get the bytes from the class file
+                        bytes = resourceHandle.getBytes();
+
+                        // get the manifest for defining the packages
+                        manifest = resourceHandle.getManifest();
+                    } catch (IOException e) {
+                        throw new ClassNotFoundException(className, e);
+                    }
+
+                    // get the certificates for the code source
+                    Certificate[] certificates = resourceHandle.getCertificates();
+
+                    // the code source url is used to define the package and as the security context for the class
+                    URL codeSourceUrl = resourceHandle.getCodeSourceUrl();
+
+                    // define the package (required for security)
+                    definePackage(className, codeSourceUrl, manifest);
+
+                    // this is the security context of the class
+                    CodeSource codeSource = new CodeSource(codeSourceUrl, certificates);
+
+                    // load the class into the vm
+                    Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource);
+                    return clazz;
+                }
+            }, acc);
+        } catch (PrivilegedActionException e) {
+            throw (ClassNotFoundException) e.getException();
+        }
+    }
+
+    private void definePackage(String className, URL jarUrl, Manifest manifest) {
+        int packageEnd = className.lastIndexOf('.');
+        if (packageEnd < 0) {
+            return;
+        }
+
+        String packageName = className.substring(0, packageEnd);
+        String packagePath = packageName.replace('.', '/') + "/";
+
+        Attributes packageAttributes = null;
+        Attributes mainAttributes = null;
+        if (manifest != null) {
+            packageAttributes = manifest.getAttributes(packagePath);
+            mainAttributes = manifest.getMainAttributes();
+        }
+        Package pkg = getPackage(packageName);
+        if (pkg != null) {
+            if (pkg.isSealed()) {
+                if (!pkg.isSealed(jarUrl)) {
+                    throw new SecurityException("Package was already sealed with another URL: package=" + packageName + ", url=" + jarUrl);
+                }
+            } else {
+                if (isSealed(packageAttributes, mainAttributes)) {
+                    throw new SecurityException("Package was already been loaded and not sealed: package=" + packageName + ", url=" + jarUrl);
+                }
+            }
+        } else {
+            String specTitle = getAttribute(Attributes.Name.SPECIFICATION_TITLE, packageAttributes, mainAttributes);
+            String specVendor = getAttribute(Attributes.Name.SPECIFICATION_VENDOR, packageAttributes, mainAttributes);
+            String specVersion = getAttribute(Attributes.Name.SPECIFICATION_VERSION, packageAttributes, mainAttributes);
+            String implTitle = getAttribute(Attributes.Name.IMPLEMENTATION_TITLE, packageAttributes, mainAttributes);
+            String implVendor = getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR, packageAttributes, mainAttributes);
+            String implVersion = getAttribute(Attributes.Name.IMPLEMENTATION_VERSION, packageAttributes, mainAttributes);
+
+            URL sealBase = null;
+            if (isSealed(packageAttributes, mainAttributes)) {
+                sealBase = jarUrl;
+            }
+
+            definePackage(packageName, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
+        }
+    }
+
+    private String getAttribute(Attributes.Name name, Attributes packageAttributes, Attributes mainAttributes) {
+        if (packageAttributes != null) {
+            String value = packageAttributes.getValue(name);
+            if (value != null) {
+                return value;
+            }
+        }
+        if (mainAttributes != null) {
+            return mainAttributes.getValue(name);
+        }
+        return null;
+    }
+
+    private boolean isSealed(Attributes packageAttributes, Attributes mainAttributes) {
+        String sealed = getAttribute(Attributes.Name.SEALED, packageAttributes, mainAttributes);
+        if (sealed == null) {
+            return false;
+        }
+        return "true".equalsIgnoreCase(sealed);
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.Permission;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JarFileUrlConnection extends JarURLConnection {
+    public static final URL DUMMY_JAR_URL;
+    static {
+        try {
+            DUMMY_JAR_URL = new URL("jar", "", -1, "file:dummy!/", new URLStreamHandler() {
+                protected URLConnection openConnection(URL u) {
+                    throw new UnsupportedOperationException();
+                }
+            });
+        } catch (Exception e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private final URL url;
+    private final JarFile jarFile;
+    private final JarEntry jarEntry;
+    private final URL jarFileUrl;
+
+    public JarFileUrlConnection(URL url, JarFile jarFile, JarEntry jarEntry) throws MalformedURLException {
+        super(DUMMY_JAR_URL);
+
+        if (url == null) throw new NullPointerException("url is null");
+        if (jarFile == null) throw new NullPointerException("jarFile is null");
+        if (jarEntry == null) throw new NullPointerException("jarEntry is null");
+
+        this.url = url;
+        this.jarFile = jarFile;
+        this.jarEntry = jarEntry;
+        jarFileUrl = new File(jarFile.getName()).toURL();
+    }
+
+    public JarFile getJarFile() throws IOException {
+        return jarFile;
+    }
+
+    public synchronized void connect() {
+    }
+
+    public URL getJarFileURL() {
+        return jarFileUrl;
+    }
+
+    public String getEntryName() {
+        return getJarEntry().getName();
+    }
+
+    public Manifest getManifest() throws IOException {
+        return jarFile.getManifest();
+    }
+
+    public JarEntry getJarEntry() {
+        return jarEntry;
+    }
+
+    public Attributes getAttributes() throws IOException {
+        return getJarEntry().getAttributes();
+    }
+
+    public Attributes getMainAttributes() throws IOException {
+        return getManifest().getMainAttributes();
+    }
+
+    public Certificate[] getCertificates() throws IOException {
+        return getJarEntry().getCertificates();
+    }
+
+    public URL getURL() {
+        return url;
+    }
+
+    public int getContentLength() {
+        long size = getJarEntry().getSize();
+        if (size > Integer.MAX_VALUE) {
+            return -1;
+        }
+        return (int) size;
+    }
+
+    public long getLastModified() {
+        return getJarEntry().getTime();
+    }
+
+    public synchronized InputStream getInputStream() throws IOException {
+        return jarFile.getInputStream(jarEntry);
+    }
+
+    public Permission getPermission() throws IOException {
+        URL jarFileUrl = new File(jarFile.getName()).toURL();
+        return jarFileUrl.openConnection().getPermission();
+    }
+
+    public String toString() {
+        return JarFileUrlConnection.class.getName() + ":" + url;
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlConnection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JarFileUrlStreamHandler extends URLStreamHandler {
+    public static URL createUrl(JarFile jarFile, JarEntry jarEntry) throws MalformedURLException {
+        return createUrl(jarFile, jarEntry, new File(jarFile.getName()).toURL());
+    }
+
+    public static URL createUrl(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException {
+        JarFileUrlStreamHandler handler = new JarFileUrlStreamHandler(jarFile, jarEntry);
+        URL url = new URL("jar", "", -1, codeSource + "!/" + jarEntry.getName(), handler);
+        handler.setExpectedUrl(url);
+        return url;
+    }
+
+    private URL expectedUrl;
+    private final JarFile jarFile;
+    private final JarEntry jarEntry;
+
+    public JarFileUrlStreamHandler(JarFile jarFile, JarEntry jarEntry) {
+        if (jarFile == null) throw new NullPointerException("jarFile is null");
+        if (jarEntry == null) throw new NullPointerException("jarEntry is null");
+
+        this.jarFile = jarFile;
+        this.jarEntry = jarEntry;
+    }
+
+    public void setExpectedUrl(URL expectedUrl) {
+        if (expectedUrl == null) throw new NullPointerException("expectedUrl is null");
+        this.expectedUrl = expectedUrl;
+    }
+
+    public URLConnection openConnection(URL url) throws IOException {
+        if (expectedUrl == null) throw new IllegalStateException("expectedUrl was not set");
+
+        // the caller copied the URL reusing a stream handler from a previous call
+        if (!expectedUrl.equals(url)) {
+            // the new url is supposed to be within our context, so it must have a jar protocol
+            if (!url.getProtocol().equals("jar")) {
+                throw new IllegalArgumentException("Unsupported protocol " + url.getProtocol());
+            }
+
+            // split the path at "!/" into the file part and entry part
+            String path = url.getPath();
+            String[] chunks = path.split("!/", 2);
+
+            // if we only got only one chunk, it didn't contain the required "!/" delimiter
+            if (chunks.length == 1) {
+                throw new MalformedURLException("Url does not contain a '!' character: " + url);
+            }
+
+            String file = chunks[0];
+            String entryPath = chunks[1];
+
+            // this handler only supports jars on the local file system
+            if (!file.startsWith("file:")) {
+                // let the system handler deal with this
+                return new URL(url.toExternalForm()).openConnection();
+            }
+            file = file.substring("file:".length());
+
+            // again the new url is supposed to be within our context so it must reference the same jar file
+            if (!jarFile.getName().equals(file)) {
+                // let the system handler deal with this
+                return new URL(url.toExternalForm()).openConnection();
+            }
+
+            // get the entry
+            JarEntry newEntry = jarFile.getJarEntry(entryPath);
+            if (newEntry == null) {
+                throw new FileNotFoundException("Entry not found: " + url);
+            }
+            return new JarFileUrlConnection(url, jarFile, newEntry);
+        }
+
+        return new JarFileUrlConnection(url, jarFile, jarEntry);
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileUrlStreamHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.security.cert.Certificate;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JarResourceHandle extends AbstractResourceHandle {
+    private final JarFile jarFile;
+    private final JarEntry jarEntry;
+    private final URL url;
+    private final URL codeSource;
+
+    public JarResourceHandle(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException {
+        this.jarFile = jarFile;
+        this.jarEntry = jarEntry;
+        this.url = JarFileUrlStreamHandler.createUrl(jarFile, jarEntry, codeSource);
+        this.codeSource = codeSource;
+    }
+
+    public String getName() {
+        return jarEntry.getName();
+    }
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public URL getCodeSourceUrl() {
+        return codeSource;
+    }
+
+    public boolean isDirectory() {
+        return jarEntry.isDirectory();
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return jarFile.getInputStream(jarEntry);
+    }
+
+    public int getContentLength() {
+        return (int) jarEntry.getSize();
+    }
+
+    public Manifest getManifest() throws IOException {
+        return jarFile.getManifest();
+    }
+
+    public Attributes getAttributes() throws IOException {
+        return jarEntry.getAttributes();
+    }
+
+    public Certificate[] getCertificates() {
+        return jarEntry.getCertificates();
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceHandle.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.util.jar.Manifest;
+import java.util.jar.JarFile;
+import java.util.jar.JarEntry;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.IOException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JarResourceLocation extends AbstractUrlResourceLocation  {
+    private final JarFile jarFile;
+
+    public JarResourceLocation(URL codeSource, JarFile jarFile) {
+        super(codeSource);
+        this.jarFile = jarFile;
+    }
+
+    public ResourceHandle getResourceHandle(String resourceName) {
+        JarEntry jarEntry = jarFile.getJarEntry(resourceName);
+        if (jarEntry != null) {
+            try {
+                URL url = new URL(getCodeSource(), resourceName);
+                return new JarResourceHandle(jarFile, jarEntry, getCodeSource());
+            } catch (MalformedURLException e) {
+            }
+        }
+        return null;
+    }
+
+    public Manifest getManifest() throws IOException {
+        return jarFile.getManifest();
+    }
+
+    public void close() {
+        IoUtil.close(jarFile);
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarResourceLocation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java?rev=437551&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java (added)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java Sun Aug 27 23:14:47 2006
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.xbean.classloader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLStreamHandlerFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * A MultiParentClassLoader is a simple extension of the URLClassLoader that simply changes the single parent class
+ * loader model to support a list of parent class loaders.  Each operation that accesses a parent, has been replaced
+ * with a operation that checks each parent in order.  This getParent method of this class will always return null,
+ * which may be interperated by the calling code to mean that this class loader is a direct child of the system class
+ * loader.
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.0
+ */
+public class MultiParentClassLoader extends NamedClassLoader {
+    private final ClassLoader[] parents;
+    private final boolean inverseClassLoading;
+    private final String[] hiddenClasses;
+    private final String[] nonOverridableClasses;
+    private final String[] hiddenResources;
+    private final String[] nonOverridableResources;
+
+    /**
+     * Creates a named class loader with no parents.
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     */
+    public MultiParentClassLoader(String name, URL[] urls) {
+        this(name, urls, ClassLoader.getSystemClassLoader());
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parent.
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parent the parent of this class loader
+     */
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader parent) {
+        this(name, urls, new ClassLoader[] {parent});
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parent and using the specified URLStreamHandlerFactory
+     * for accessing the urls..
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parent the parent of this class loader
+     * @param factory the URLStreamHandlerFactory used to access the urls
+     */
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
+        this(name, urls, new ClassLoader[] {parent}, factory);
+    }
+
+    /**
+     * Creates a named class loader as a child of the specified parents.
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parents the parents of this class loader
+     */
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents) {
+        this(name, urls, parents, false, new String[0], new String[0]);
+    }
+
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        this(name, urls, new ClassLoader[]{parent}, inverseClassLoading, hiddenClasses, nonOverridableClasses);
+    }
+    
+    /**
+     * Creates a named class loader as a child of the specified parents and using the specified URLStreamHandlerFactory
+     * for accessing the urls..
+     * @param name the name of this class loader
+     * @param urls the urls from which this class loader will classes and resources
+     * @param parents the parents of this class loader
+     * @param factory the URLStreamHandlerFactory used to access the urls
+     */
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, URLStreamHandlerFactory factory) {
+        super(name, urls, null, factory);
+        this.parents = copyParents(parents);
+        this.inverseClassLoading = false;
+        this.hiddenClasses = new String[0];
+        this.nonOverridableClasses = new String[0];
+        this.hiddenResources = new String[0];
+        this.nonOverridableResources = new String[0];
+    }
+
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
+        this(name, urls, parents, inverseClassLoading, (String[]) hiddenClasses.toArray(new String[hiddenClasses.size()]), (String[]) nonOverridableClasses.toArray(new String[nonOverridableClasses.size()]));
+    }
+
+    public MultiParentClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
+        super(name, urls);
+        this.parents = copyParents(parents);
+        this.inverseClassLoading = inverseClassLoading;
+        this.hiddenClasses = hiddenClasses;
+        this.nonOverridableClasses = nonOverridableClasses;
+        hiddenResources = toResources(hiddenClasses);
+        nonOverridableResources = toResources(nonOverridableClasses);
+    }
+
+    private static String[] toResources(String[] classes) {
+        String[] resources = new String[classes.length];
+        for (int i = 0; i < classes.length; i++) {
+            String className = classes[i];
+            resources[i] = className.replace('.', '/');
+        }
+        return resources;
+    }
+    
+    private static ClassLoader[] copyParents(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");
+            }
+            newParentsArray[i] = parent;
+        }
+        return newParentsArray;
+    }
+
+    /**
+     * Gets the parents of this class loader.
+     * @return the parents of this class loader
+     */
+    public ClassLoader[] getParents() {
+        return parents;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
+        //
+        // Check if class is in the loaded classes cache
+        //
+        Class cachedClass = findLoadedClass(name);
+        if (cachedClass != null) {
+            return resolveClass(cachedClass, resolve);
+        }
+        
+        //
+        // if we are using inverse class loading, check local urls first
+        //
+        if (inverseClassLoading && !isDestroyed() && !isNonOverridableClass(name)) {
+            try {
+                Class clazz = findClass(name);
+                return resolveClass(clazz, resolve);
+            } catch (ClassNotFoundException ignored) {
+            }
+        }
+
+        //
+        // Check parent class loaders
+        //
+        if (!isHiddenClass(name)) {
+            for (int i = 0; i < parents.length; i++) {
+                ClassLoader parent = parents[i];
+                try {
+                    Class clazz = parent.loadClass(name);
+                    return resolveClass(clazz, resolve);
+                } catch (ClassNotFoundException ignored) {
+                    // this parent didn't have the class; try the next one
+                }
+            }
+        }
+
+        //
+        // if we are not using inverse class loading, check local urls now
+        //
+        // don't worry about excluding non-overridable classes here... we
+        // have alredy checked he parent and the parent didn't have the
+        // class, so we can override now
+        if (!isDestroyed()) {
+            try {
+                Class clazz = findClass(name);
+                return resolveClass(clazz, resolve);
+            } catch (ClassNotFoundException ignored) {
+            }
+        }
+
+        throw new ClassNotFoundException(name + " in classloader " + name);
+    }
+
+    private boolean isNonOverridableClass(String name) {
+        for (int i = 0; i < nonOverridableClasses.length; i++) {
+            if (name.startsWith(nonOverridableClasses[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isHiddenClass(String name) {
+        for (int i = 0; i < hiddenClasses.length; i++) {
+            if (name.startsWith(hiddenClasses[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private Class resolveClass(Class clazz, boolean resolve) {
+        if (resolve) {
+            resolveClass(clazz);
+        }
+        return clazz;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public URL getResource(String name) {
+        if (isDestroyed()) {
+            return null;
+        }
+
+        //
+        // if we are using inverse class loading, check local urls first
+        //
+        if (inverseClassLoading && !isDestroyed() && !isNonOverridableResource(name)) {
+            URL url = findResource(name);
+            if (url != null) {
+                return url;
+            }
+        }
+
+        //
+        // Check parent class loaders
+        //
+        if (!isHiddenResource(name)) {
+            for (int i = 0; i < parents.length; i++) {
+                ClassLoader parent = parents[i];
+                URL url = parent.getResource(name);
+                if (url != null) {
+                    return url;
+                }
+            }
+        }
+
+        //
+        // if we are not using inverse class loading, check local urls now
+        //
+        // don't worry about excluding non-overridable resources here... we
+        // have alredy checked he parent and the parent didn't have the
+        // resource, so we can override now
+        if (!isDestroyed()) {
+            // parents didn't have the resource; attempt to load it from my urls
+            return findResource(name);
+        }
+
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Enumeration findResources(String name) throws IOException {
+        if (isDestroyed()) {
+            return Collections.enumeration(Collections.EMPTY_SET);
+        }
+
+        List resources = new ArrayList();
+
+        //
+        // if we are using inverse class loading, add the resources from local urls first
+        //
+        if (inverseClassLoading && !isDestroyed()) {
+            List myResources = Collections.list(super.findResources(name));
+            resources.addAll(myResources);
+        }
+
+        //
+        // Add parent resources
+        //
+        for (int i = 0; i < parents.length; i++) {
+            ClassLoader parent = parents[i];
+            List parentResources = Collections.list(parent.getResources(name));
+            resources.addAll(parentResources);
+        }
+
+        //
+        // if we are not using inverse class loading, add the resources from local urls now
+        //
+        if (!inverseClassLoading && !isDestroyed()) {
+            List myResources = Collections.list(super.findResources(name));
+            resources.addAll(myResources);
+        }
+
+        return Collections.enumeration(resources);
+    }
+
+    private boolean isNonOverridableResource(String name) {
+        for (int i = 0; i < nonOverridableResources.length; i++) {
+            if (name.startsWith(nonOverridableResources[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean isHiddenResource(String name) {
+        for (int i = 0; i < hiddenResources.length; i++) {
+            if (name.startsWith(hiddenResources[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "[" + getClass().getName() + ":" +
+                " name=" + getName() +
+                " urls=" + Arrays.asList(getURLs()) +
+                " parents=" + Arrays.asList(parents) +
+                "]";
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/MultiParentClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain