Examples of MultiParentClassLoader


Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

     * ClassLoader.  This should load the parent's copy when
     * contextPriorityClassLoader is set to false and the child's copy when
     * the contextPriorityClassLoader is set to true (as here).
     */
    public void testTrueExistantNonJavaxResource() {
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), true, new String[] {}, NON_OVERRIDABLE);
        URL url = cl.getResource("mx4j/MBeanDescription.class");
        if(url == null) {
            fail("Problem with test; expecting to have mx4j.* on the ClassPath");
        }
        assertEquals("Should be able to override a class that is not in java.*, javax.*, etc.", url.getProtocol(), "file");
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

    private static void dumpIDs(String prefix, ClassLoader loader) {
        if(loader == null) return;
        System.out.println(prefix+"ClassLoader is "+loader);

        if(loader instanceof MultiParentClassLoader) {
            MultiParentClassLoader mp = (MultiParentClassLoader) loader;
            ClassLoader[] parents = mp.getParents();
            for (int i = 0; i < parents.length; i++) {
                dumpIDs(prefix+"  ", parents[i]);
            }
        } else {
            dumpIDs(prefix+"  ", loader.getParent());
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

                URL entry = entries[i];
                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]);
            }
        } else {
            dumpContents(prefix+"    ", loader.getParent());
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

        }
        URL[] urls = (URL[]) path.toArray(new URL[path.size()]);
        if (parentClassLoaders != null) {
            parentClassLoaders.add(parent);
            ClassLoader[] parents = (ClassLoader[]) parentClassLoaders.toArray(new ClassLoader[parentClassLoaders.size()]);
            webLoader = new MultiParentClassLoader(null, urls, parents);
        } else {
            webLoader = new URLClassLoader(urls, parent);
        }
    }
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

/**
* @version $Rev: 527482 $ $Date: 2007-04-11 09:06:45 -0400 (Wed, 11 Apr 2007) $
*/
public class SharedLib {
    public SharedLib(ClassLoader classLoader, String[] classesDirs, String[] libDirs, ServerInfo serverInfo) throws MalformedURLException {
        MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader) classLoader;
        Set currentUrls = new HashSet(Arrays.asList(multiParentClassLoader.getURLs()));

        int size=0;
        if (classesDirs != null) size += classesDirs.length;
        if (libDirs != null) size += libDirs.length;

        LinkedHashSet newUrls = new LinkedHashSet(size);
        if (classesDirs != null) {
            for (int i = 0; i < classesDirs.length; i++) {
                String classesDir = classesDirs[i];
                File dir = serverInfo.resolveServer(classesDir);
                if (!dir.exists()) {
                    if (!dir.mkdirs()) {
                        throw new IllegalArgumentException("Failed to create classes dir: " + dir);
                    }
                }
                if (!dir.isDirectory()) {
                    throw new IllegalArgumentException("Classes dir is not a directory: " + dir);
                }
                URL location = dir.toURL();
                if (!currentUrls.contains(location)) {
                    newUrls.add(location);
                }
            }
        }

        if (libDirs != null) {
            for (int i = 0; i < libDirs.length; i++) {
                String libDir = libDirs[i];
                File dir = serverInfo.resolveServer(libDir);
                if (!dir.exists()) {
                    if (!dir.mkdirs()) {
                        throw new IllegalArgumentException("Failed to create lib dir: " + dir);
                    }
                }
                if (!dir.isDirectory()) {
                    throw new IllegalArgumentException("Lib dir is not a directory: " + dir);
                }

                File[] files = dir.listFiles();
                for (int j = 0; j < files.length; j++) {
                    File file = files[j];
                    if (file.canRead() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) {
                        URL location = file.toURL();
                        if (!currentUrls.contains(location)) {
                            newUrls.add(location);
                        }
                    }
                }
            }
        }

        for (Iterator iterator = newUrls.iterator(); iterator.hasNext();) {
            URL url = (URL) iterator.next();
            multiParentClassLoader.addURL(url);
        }
    }
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

    /**
     * Tries to load a javax.* class that's not available from the
     * parent ClassLoader.  This should work.
     */
    public void testFalseNonexistantJavaxClass() {
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), clRules);
        try {
            cl.loadClass("javax.foo.Foo");
        } catch(ClassNotFoundException e) {
            fail("Should be able to load a javax.* class that is not defined by my parent CL");
        }
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

     * Tries to load a javax.* class that's not available from the
     * parent ClassLoader.  This should work.
     */
    public void testTrueNonexistantJavaxClass() {
        clRules.setInverseClassLoading(true);
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), clRules);
        try {
            cl.loadClass("javax.foo.Foo");
        } catch(ClassNotFoundException e) {
            fail("Should be able to load a javax.* class that is not defined by my parent CL");
        }
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

     * Tries to load a javax.* class that is avialable from the parent ClassLoader,
     * when there's a different definition available from this ClassLoader too.
     * This should always load the parent's copy.
     */
    public void testFalseExistantJavaxClass() {
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), clRules);
        try {
            Class cls = cl.loadClass("javax.servlet.Servlet");
            assertTrue("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",cls.getDeclaredMethods().length > 0);
        } catch(ClassNotFoundException e) {
            fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

     * when there's a different definition available from this ClassLoader too.
     * This should always load the parent's copy.
     */
    public void testTrueExistantJavaxClass() {
        clRules.setInverseClassLoading(true);
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), clRules);
        try {
            Class cls = cl.loadClass("javax.servlet.Servlet");
            assertTrue("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",cls.getDeclaredMethods().length > 0);
        } catch(ClassNotFoundException e) {
            fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
View Full Code Here

Examples of org.apache.geronimo.kernel.config.MultiParentClassLoader

     * ClassLoader.  This should load the parent's copy when
     * contextPriorityClassLoader is set to false (as here) and the child's
     * copy when the contextPriorityClassLoader is set to true.
     */
    public void xtestFalseExistantNonJavaxClass() {
        cl = new MultiParentClassLoader(configId, urls, getClass().getClassLoader(), clRules);
        try {
            Class cls = cl.loadClass("mx4j.MBeanDescription");
            assertTrue("Should not have overriden parent CL definition of class mx4j.MBeanDescription", cls.getDeclaredMethods().length > 0);
        } catch(ClassNotFoundException e) {
            fail("Problem with test; expecting to have mx4j.* on the ClassPath");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.