geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r752594 - in /geronimo/sandbox/djencks/framework/modules: geronimo-deployment/src/main/java/org/apache/geronimo/deployment/ geronimo-deployment/src/test/java/org/apache/geronimo/deployment/ geronimo-kernel/src/main/java/org/apache/geronimo/...
Date Wed, 11 Mar 2009 19:47:15 GMT
Author: djencks
Date: Wed Mar 11 19:47:15 2009
New Revision: 752594

URL: http://svn.apache.org/viewvc?rev=752594&view=rev
Log:
more generics.  Don't allow adding classes to configurations

Modified:
    geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/InPlaceResourceContext.java
    geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
    geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
    geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/Configuration.java
    geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
    geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ClassLoaderDumper.java
    geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/MultiParentClassLoaderTest.java

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
Wed Mar 11 19:47:15 2009
@@ -28,7 +28,6 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
@@ -317,7 +316,7 @@
             Manifest manifest,
             ConfigurationStore store,
             DeploymentContext context) throws DeploymentException, IOException, Throwable
{
-        List<ConfigurationData> configurations = new ArrayList<ConfigurationData>();
+        List<ConfigurationData> configurationDatas = new ArrayList<ConfigurationData>();
         
         boolean configsCleanupRequired = false;
 
@@ -331,35 +330,34 @@
         thread.setContextClassLoader( context.getConfiguration().getConfigurationClassLoader());
         try {
             try {
-                configurations.add(context.getConfigurationData());
+                configurationDatas.add(context.getConfigurationData());
             } catch (DeploymentException e) {
                 Configuration configuration = context.getConfiguration(); 
                 if (configuration != null) {
                     ConfigurationData dumbConfigurationData = new ConfigurationData(null,
null, null, null,
                             configuration.getEnvironment(), context.getBaseDir(), null, context.getNaming());
-                    configurations.add(dumbConfigurationData);
+                    configurationDatas.add(dumbConfigurationData);
                 }
-                configurations.addAll(context.getAdditionalDeployment());
+                configurationDatas.addAll(context.getAdditionalDeployment());
                 throw e;
             }
             
-            configurations.addAll(context.getAdditionalDeployment());
+            configurationDatas.addAll(context.getAdditionalDeployment());
 
-            if (configurations.isEmpty()) {
+            if (configurationDatas.isEmpty()) {
                 throw new DeploymentException("Deployer did not create any configurations");
             }
 
             if (targetFile != null) {
-                if (configurations.size() > 1) {
+                if (configurationDatas.size() > 1) {
                     throw new DeploymentException("Deployer created more than one configuration");
                 }
-                ConfigurationData configurationData = (ConfigurationData) configurations.get(0);
+                ConfigurationData configurationData = configurationDatas.get(0);
                 ExecutableConfigurationUtil.createExecutableConfiguration(configurationData,
manifest, targetFile);
             }
             if (install) {
-                List deployedURIs = new ArrayList();
-                for (Iterator iterator = configurations.iterator(); iterator.hasNext();)
{
-                    ConfigurationData configurationData = (ConfigurationData) iterator.next();
+                List<String> deployedURIs = new ArrayList<String>();
+                for (ConfigurationData configurationData : configurationDatas) {
                     store.install(configurationData);
                     deployedURIs.add(configurationData.getId().toString());
                 }
@@ -385,12 +383,10 @@
             throw e;
         } finally {
             thread.setContextClassLoader(oldCl);
-            if (context != null) {
-                context.close();
-            }
+            context.close();
             if (configsCleanupRequired) {
                 // We do this after context is closed so the module jar isn't open
-                cleanupConfigurations(configurations);
+                cleanupConfigurations(configurationDatas);
             }
         }
     }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
Wed Mar 11 19:47:15 2009
@@ -17,7 +17,6 @@
 
 package org.apache.geronimo.deployment;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -42,9 +41,6 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.util.DeploymentUtil;
 import org.apache.geronimo.gbean.AbstractName;
@@ -63,6 +59,8 @@
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Rev:385232 $ $Date$
@@ -589,17 +587,17 @@
         }
     }
     
-    public void addClass(URI targetPath, String fqcn, byte[] bytes) throws IOException, URISyntaxException
{
-        if (!targetPath.getPath().endsWith("/"))
-            throw new IllegalStateException("target path must end with a '/' character: "
+ targetPath);
-
-        String classFileName = fqcn.replace('.', '/') + ".class";
-
-        File targetFile = getTargetFile(new URI(targetPath.toString() + classFileName));
-        addFile(targetFile, new ByteArrayInputStream(bytes));
-
-        configuration.addToClassPath(targetPath.toString());
-    }
+//    public void addClass(URI targetPath, String fqcn, byte[] bytes) throws IOException,
URISyntaxException {
+//        if (!targetPath.getPath().endsWith("/"))
+//            throw new IllegalStateException("target path must end with a '/' character:
" + targetPath);
+//
+//        String classFileName = fqcn.replace('.', '/') + ".class";
+//
+//        File targetFile = getTargetFile(new URI(targetPath.toString() + classFileName));
+//        addFile(targetFile, new ByteArrayInputStream(bytes));
+//
+//        configuration.addToClassPath(targetPath.toString());
+//    }
 
     public void addFile(URI targetPath, ZipFile zipFile, ZipEntry zipEntry) throws IOException
{
         resourceContext.addFile(targetPath, zipFile, zipEntry);

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/InPlaceResourceContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/InPlaceResourceContext.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/InPlaceResourceContext.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/InPlaceResourceContext.java
Wed Mar 11 19:47:15 2009
@@ -22,7 +22,6 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
@@ -38,7 +37,7 @@
     
     private final Configuration configuration;
     private final URI inPlaceBaseConfigurationUri;
-    private final Set zipFilesToExpand = new HashSet();
+    private final Set<ZipFile> zipFilesToExpand = new HashSet<ZipFile>();
     
     public InPlaceResourceContext(Configuration configuration, File inPlaceBaseConfigurationDir)
throws DeploymentException {
         this.configuration = configuration;
@@ -102,8 +101,7 @@
     }
     
     public void flush() throws IOException {
-        for (Iterator iter = zipFilesToExpand.iterator(); iter.hasNext();) {
-            ZipFile zipFile = (ZipFile) iter.next();
+        for (ZipFile zipFile : zipFilesToExpand) {
             String name = zipFile.getName();
             zipFile.close();
             File srcFile = new File(name);
@@ -116,14 +114,14 @@
                     throw new AssertionError(e);
                 }
             } else {
-                targetFile = new File(name + PACKED_MODULED_SAVED_SUFFIX);              
 
+                targetFile = new File(name + PACKED_MODULED_SAVED_SUFFIX);
             }
             boolean success = new File(name).renameTo(targetFile);
             if (!success) {
-                throw new IOException("Cannot rename file " + 
+                throw new IOException("Cannot rename file " +
                         name + " to " + targetFile.getAbsolutePath());
             }
-            
+
             DeploymentUtil.unzipToDirectory(new ZipFile(targetFile), srcFile);
         }
     }

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-deployment/src/test/java/org/apache/geronimo/deployment/DeploymentContextTest.java
Wed Mar 11 19:47:15 2009
@@ -53,40 +53,40 @@
 public class DeploymentContextTest extends TestCase {
     private byte[] classBytes;
 
-    public void testAddClass() throws Exception {
-        File basedir = File.createTempFile("car", "tmp");
-        basedir.delete();
-        basedir.mkdirs();
-        try {
-            basedir.deleteOnExit();
-            Environment environment = new Environment();
-            Artifact configId = new Artifact("foo", "artifact", "1", "car");
-            environment.setConfigId(configId);
-            ArtifactManager artifactManager = new DefaultArtifactManager();
-            ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
Collections.EMPTY_SET, null);
-            SimpleConfigurationManager configurationManager = new SimpleConfigurationManager(Collections.EMPTY_SET,
artifactResolver, Collections.EMPTY_SET);
-            DeploymentContext context = new DeploymentContext(basedir, null, environment,
null, ConfigurationModuleType.CAR, new Jsr77Naming(), configurationManager, Collections.EMPTY_SET);
-            Enhancer enhancer = new Enhancer();
-            enhancer.setInterfaces(new Class[]{DataSource.class});
-            enhancer.setCallbackType(MethodInterceptor.class);
-            enhancer.setStrategy(new DefaultGeneratorStrategy() {
-                public byte[] transform(byte[] b) {
-                    classBytes = b;
-                    return b;
-                }
-            });
-            enhancer.setClassLoader(new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
-            Class type = enhancer.createClass();
-            URI location = new URI("cglib/");
-            context.addClass(location, type.getName(), classBytes);
-            ClassLoader cl = context.getClassLoader();
-            Class loadedType = cl.loadClass(type.getName());
-            assertTrue(DataSource.class.isAssignableFrom(loadedType));
-            assertTrue(type != loadedType);
-        } finally {
-            recursiveDelete(basedir);
-        }
-    }
+//    public void testAddClass() throws Exception {
+//        File basedir = File.createTempFile("car", "tmp");
+//        basedir.delete();
+//        basedir.mkdirs();
+//        try {
+//            basedir.deleteOnExit();
+//            Environment environment = new Environment();
+//            Artifact configId = new Artifact("foo", "artifact", "1", "car");
+//            environment.setConfigId(configId);
+//            ArtifactManager artifactManager = new DefaultArtifactManager();
+//            ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager,
Collections.EMPTY_SET, null);
+//            SimpleConfigurationManager configurationManager = new SimpleConfigurationManager(Collections.EMPTY_SET,
artifactResolver, Collections.EMPTY_SET);
+//            DeploymentContext context = new DeploymentContext(basedir, null, environment,
null, ConfigurationModuleType.CAR, new Jsr77Naming(), configurationManager, Collections.EMPTY_SET);
+//            Enhancer enhancer = new Enhancer();
+//            enhancer.setInterfaces(new Class[]{DataSource.class});
+//            enhancer.setCallbackType(MethodInterceptor.class);
+//            enhancer.setStrategy(new DefaultGeneratorStrategy() {
+//                public byte[] transform(byte[] b) {
+//                    classBytes = b;
+//                    return b;
+//                }
+//            });
+//            enhancer.setClassLoader(new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
+//            Class type = enhancer.createClass();
+//            URI location = new URI("cglib/");
+//            context.addClass(location, type.getName(), classBytes);
+//            ClassLoader cl = context.getClassLoader();
+//            Class loadedType = cl.loadClass(type.getName());
+//            assertTrue(DataSource.class.isAssignableFrom(loadedType));
+//            assertTrue(type != loadedType);
+//        } finally {
+//            recursiveDelete(basedir);
+//        }
+//    }
 
     private void recursiveDelete(File file) {
         if (file.isDirectory()) {

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/classloader/JarFileClassLoader.java
Wed Mar 11 19:47:15 2009
@@ -29,6 +29,7 @@
 import java.security.PrivilegedExceptionAction;
 import java.security.cert.Certificate;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 
@@ -90,13 +91,13 @@
      * @param urls the urls from which this class loader will classes and resources
      * @param parents the parents of this class loader
      */
-    public JarFileClassLoader(Artifact id, URL[] urls, ClassLoader[] parents) {
+    public JarFileClassLoader(Artifact id, URL[] urls, List<ClassLoader> parents) {
         super(id, EMPTY_URLS, parents);
         this.acc = AccessController.getContext();
         addURLs(urls);
     }
 
-    public JarFileClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, ClassLoadingRules
classLoadingRules) {
+    public JarFileClassLoader(Artifact id, URL[] urls, List<ClassLoader> parents, ClassLoadingRules
classLoadingRules) {
         super(id, EMPTY_URLS, parents, classLoadingRules);
         this.acc = AccessController.getContext();
         addURLs(urls);

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/Configuration.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/Configuration.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/Configuration.java
Wed Mar 11 19:47:15 2009
@@ -339,17 +339,16 @@
         URL[] urls = buildClassPath(classPath);
 
         // parents
-        ClassLoader[] parentClassLoaders;
+        List<ClassLoader> parentClassLoaders;
         if (parents.size() == 0 && classParents.size() == 0) {
             // no explicit parent set, so use the class loader of this class as
             // the parent... this class should be in the root geronimo classloader,
             // which is normally the system class loader but not always, so be safe
-            parentClassLoaders = new ClassLoader[] {getClass().getClassLoader()};
+            parentClassLoaders = Collections.singletonList(getClass().getClassLoader());
         } else {
-            parentClassLoaders = new ClassLoader[classParents.size()];
-            for (ListIterator iterator = classParents.listIterator(); iterator.hasNext();)
{
-                Configuration configuration = (Configuration) iterator.next();
-                parentClassLoaders[iterator.previousIndex()] = configuration.childrenConfigurationClassLoader;
+            parentClassLoaders = new ArrayList<ClassLoader>(classParents.size());
+            for (Configuration configuration : classParents) {
+                parentClassLoaders.add(configuration.childrenConfigurationClassLoader);
             }
         }
 

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/MultiParentClassLoader.java
Wed Mar 11 19:47:15 2009
@@ -57,7 +57,7 @@
     private static final Logger log = LoggerFactory.getLogger(MultiParentClassLoader.class);
 
     private final Artifact id;
-    private final ClassLoader[] parents;
+    private final List<ClassLoader> parents;
     private final ClassLoadingRules classLoadingRules;
     private boolean destroyed = false;
     private Set<String> resourcesNotFound = new HashSet<String>();
@@ -101,7 +101,7 @@
         super(urls);
         this.id = id;
         
-        parents = new ClassLoader[]{ClassLoader.getSystemClassLoader()};
+        parents = new ArrayList<ClassLoader>(Collections.singleton(ClassLoader.getSystemClassLoader()));
         classLoadingRules = new ClassLoadingRules();
         ClassLoaderRegistry.add(this);
     }
@@ -115,11 +115,11 @@
      * @param parent the parent of this class loader
      */
     public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent) {
-        this(id, urls, new ClassLoader[]{parent});
+        this(id, urls, Collections.singletonList(parent));
     }
 
     public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent, ClassLoadingRules
classLoadingRules) {
-        this(id, urls, new ClassLoader[]{parent}, classLoadingRules);
+        this(id, urls, Collections.singletonList(parent), classLoadingRules);
     }
 
     /**
@@ -132,7 +132,7 @@
      * @param factory the URLStreamHandlerFactory used to access the urls
      */
     public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader parent, URLStreamHandlerFactory
factory) {
-        this(id, urls, new ClassLoader[]{parent}, factory);
+        this(id, urls, Collections.singletonList(parent), factory);
     }
 
     /**
@@ -142,19 +142,19 @@
      * @param urls    the urls from which this class loader will classes and resources
      * @param parents the parents of this class loader
      */
-    public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents) {
+    public MultiParentClassLoader(Artifact id, URL[] urls, List<ClassLoader> parents)
{
         super(urls);
         this.id = id;
-        this.parents = copyParents(parents);
+        this.parents = new ArrayList<ClassLoader>(parents);
 
         classLoadingRules = new ClassLoadingRules();
         ClassLoaderRegistry.add(this);
     }
 
-    public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, ClassLoadingRules
classLoadingRules) {
+    public MultiParentClassLoader(Artifact id, URL[] urls, List<ClassLoader> parents,
ClassLoadingRules classLoadingRules) {
         super(urls);
         this.id = id;
-        this.parents = copyParents(parents);
+        this.parents = new ArrayList<ClassLoader>(parents);
         this.classLoadingRules = classLoadingRules;
         ClassLoaderRegistry.add(this);
     }
@@ -186,38 +186,25 @@
      * @param parents the parents of this class loader
      * @param factory the URLStreamHandlerFactory used to access the urls
      */
-    public MultiParentClassLoader(Artifact id, URL[] urls, ClassLoader[] parents, URLStreamHandlerFactory
factory) {
+    public MultiParentClassLoader(Artifact id, URL[] urls, List<ClassLoader> parents,
URLStreamHandlerFactory factory) {
         super(urls, null, factory);
         this.id = id;
-        this.parents = copyParents(parents);
+        this.parents = new ArrayList<ClassLoader>(parents);
         
         classLoadingRules = new ClassLoadingRules();
         ClassLoaderRegistry.add(this);
     }
 
-    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;
-    }
-
-    private static ClassLoader[] deepCopyParents(ClassLoader[] parents) {
-        ClassLoader[] newParentsArray = new ClassLoader[parents.length];
-        for (int i = 0; i < parents.length; i++) {
-            ClassLoader parent = parents[i];
+    private static List<ClassLoader> deepCopyParents(List<ClassLoader> parents)
{
+        List<ClassLoader> newParentsArray = new ArrayList<ClassLoader>(parents.size());
+        for (ClassLoader parent : parents) {
             if (parent == null) {
-                throw new NullPointerException("parent[" + i + "] is null");
+                throw new NullPointerException("parent is null: " + parents);
             }
             if (parent instanceof MultiParentClassLoader) {
                 parent = ((MultiParentClassLoader) parent).copy();
             }
-            newParentsArray[i] = parent;
+            newParentsArray.add(parent);
         }
         return newParentsArray;
     }
@@ -236,7 +223,7 @@
      *
      * @return the parents of this class loader
      */
-    public ClassLoader[] getParents() {
+    public List<ClassLoader> getParents() {
         return parents;
     }
 

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ClassLoaderDumper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ClassLoaderDumper.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ClassLoaderDumper.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ClassLoaderDumper.java
Wed Mar 11 19:47:15 2009
@@ -16,8 +16,9 @@
  */
 package org.apache.geronimo.kernel.util;
 
-import java.net.URLClassLoader;
 import java.net.URL;
+import java.net.URLClassLoader;
+
 import org.apache.geronimo.kernel.config.MultiParentClassLoader;
 
 /**
@@ -43,9 +44,8 @@
 
         if(loader instanceof MultiParentClassLoader) {
             MultiParentClassLoader mp = (MultiParentClassLoader) loader;
-            ClassLoader[] parents = mp.getParents();
-            for (int i = 0; i < parents.length; i++) {
-                dumpIDs(prefix+"  ", parents[i]);
+            for (ClassLoader parent: mp.getParents()) {
+                dumpIDs(prefix+"  ", parent);
             }
         } else {
             dumpIDs(prefix+"  ", loader.getParent());
@@ -58,16 +58,14 @@
         if(loader instanceof URLClassLoader) {
             URLClassLoader url = (URLClassLoader) loader;
             URL[] entries = url.getURLs();
-            for (int i = 0; i < entries.length; i++) {
-                URL entry = entries[i];
-                System.out.println(prefix+"  "+entry);
+            for (URL entry : entries) {
+                System.out.println(prefix + "  " + entry);
             }
         }
         if(loader instanceof MultiParentClassLoader) {
             MultiParentClassLoader mp = (MultiParentClassLoader) loader;
-            ClassLoader[] parents = mp.getParents();
-            for (int i = 0; i < parents.length; i++) {
-                dumpContents(prefix+"    ", parents[i]);
+            for (ClassLoader parent: mp.getParents()) {
+                dumpContents(prefix+"    ", parent);
             }
         } else {
             dumpContents(prefix+"    ", loader.getParent());

Modified: geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/MultiParentClassLoaderTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/MultiParentClassLoaderTest.java?rev=752594&r1=752593&r2=752594&view=diff
==============================================================================
--- geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/MultiParentClassLoaderTest.java
(original)
+++ geronimo/sandbox/djencks/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/MultiParentClassLoaderTest.java
Wed Mar 11 19:47:15 2009
@@ -28,6 +28,8 @@
 import java.util.jar.JarEntry;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.List;
+import java.util.ArrayList;
 
 import junit.framework.TestCase;
 import net.sf.cglib.proxy.Enhancer;
@@ -49,7 +51,7 @@
     private File[] files;
     private static final String NON_EXISTANT_RESOURCE = "non-existant-resource";
     private static final String NON_EXISTANT_CLASS = "NonExistant.class";
-    private URLClassLoader[] parents;
+    private List<ClassLoader> parents;
     private MultiParentClassLoader classLoader;
     private static final Artifact NAME = new Artifact("test", "fake", "1.0", "car");
 
@@ -101,11 +103,11 @@
      * parents are in the same order.
      */
     public void testGetParents() {
-        ClassLoader[] actualParents = classLoader.getParents();
+        List<ClassLoader> actualParents = classLoader.getParents();
         assertNotSame(parents, actualParents);
-        assertEquals(parents.length, actualParents.length);
-        for (int i = 0; i < actualParents.length; i++) {
-            assertEquals(parents[i], actualParents[i]);
+        assertEquals(parents.size(), actualParents.size());
+        for (int i = 0; i < actualParents.size(); i++) {
+            assertEquals(parents.get(i), actualParents.get(i));
         }
     }
 
@@ -121,8 +123,8 @@
         assertEquals(classLoader, clazz.getClassLoader());
 
         // load class specific to each parent class loader
-        for (int i = 0; i < parents.length; i++) {
-            URLClassLoader parent = parents[i];
+        for (int i = 0; i < parents.size(); i++) {
+            ClassLoader parent = parents.get(i);
             clazz = classLoader.loadClass(CLASS_NAME + i);
             assertNotNull(clazz);
             assertTrue(clazz instanceof Serializable);
@@ -133,7 +135,7 @@
         clazz = classLoader.loadClass(CLASS_NAME);
         assertNotNull(clazz);
         assertTrue(clazz instanceof Serializable);
-        assertEquals(parents[0], clazz.getClassLoader());
+        assertEquals(parents.get(0), clazz.getClassLoader());
     }
 
     public void testInverseClassLoading() throws Exception {
@@ -205,7 +207,7 @@
         assertStreamContains("Should have found value from my file", ENTRY_VALUE + 33 + ENTRY_VALUE,
in);
         in.close();
 
-        for (int i = 0; i < parents.length; i++) {
+        for (int i = 0; i < parents.size(); i++) {
             in = classLoader.getResourceAsStream(ENTRY_NAME + i);
             assertStreamContains("Should have found value from parent " + i, ENTRY_VALUE
+ i + ENTRY_VALUE, in);
             in.close();
@@ -232,7 +234,7 @@
         URL resource = classLoader.getResource(ENTRY_NAME + 33);
         assertURLContains("Should have found value from my file", ENTRY_VALUE + 33 + ENTRY_VALUE,
resource);
 
-        for (int i = 0; i < parents.length; i++) {
+        for (int i = 0; i < parents.size(); i++) {
             resource = classLoader.getResource(ENTRY_NAME + i);
             assertURLContains("Should have found value from parent " + i, ENTRY_VALUE + i
+ ENTRY_VALUE, resource);
         }
@@ -259,7 +261,7 @@
         assertTrue(resources.hasMoreElements());
 
         // there should be one entry for each parent
-        for (int i = 0; i < parents.length; i++) {
+        for (int i = 0; i < parents.size(); i++) {
             URL resource = (URL) resources.nextElement();
             assertURLContains("Should have found value from parent " + i, ENTRY_VALUE + i,
resource);
         }
@@ -316,9 +318,9 @@
             files[i] = createJarFile(i);
         }
 
-        parents = new URLClassLoader[3];
-        for (int i = 0; i < parents.length; i++) {
-            parents[i] = new URLClassLoader(new URL[]{files[i].toURL()});
+        parents = new ArrayList<ClassLoader>(3);
+        for (int i = 0; i < 3; i++) {
+            parents.add(new URLClassLoader(new URL[]{files[i].toURL()}) );
         }
 
         File myFile = createJarFile(33);



Mime
View raw message