Example usage for java.lang ClassLoader getParent

List of usage examples for java.lang ClassLoader getParent

Introduction

In this page you can find the example usage for java.lang ClassLoader getParent.

Prototype

@CallerSensitive
public final ClassLoader getParent() 

Source Link

Document

Returns the parent class loader for delegation.

Usage

From source file:org.carracoo.maven.assist.AssistProcessor.java

private void debugClassLoader(final ClassPool classPool) {
    if (!logger.isLoggable(Level.INFO)) {
        return;//  ww w .j av a2  s .c  o  m
    }

    logger.log(Level.FINE, String.format(" - classPool: %s", classPool.toString()));
    ClassLoader classLoader = classPool.getClassLoader();
    while (classLoader != null) {
        logger.log(Level.INFO,
                String.format(" -- %s : %s", classLoader.getClass().getName(), classLoader.toString()));
        if (classLoader instanceof URLClassLoader) {
            logger.log(Level.INFO, String.format(" --- urls: %s ",
                    Arrays.deepToString(((URLClassLoader) classLoader).getURLs())));
        }
        classLoader = classLoader.getParent();
    }
}

From source file:org.ebayopensource.turmeric.tools.codegen.AbstractServiceGeneratorTestCase.java

private void dumpClassLoader(String indent, ClassLoader cl) {
    if (cl == null) {
        return;//from www . j a va2 s. c o  m
    }
    System.out.printf("%sClassLoader: %s: %s%n", indent, cl.getClass().getName(), cl.toString());
    if (cl instanceof URLClassLoader) {
        URLClassLoader ucl = (URLClassLoader) cl;
        System.out.printf("%s(URLClassLoader)%n", indent);
        URL urls[] = ucl.getURLs();
        for (URL url : urls) {
            System.out.printf("%s* %s%n", indent, url);
        }
    }
    ClassLoader parent = cl.getParent();
    dumpClassLoader(indent + "  ", parent);
}

From source file:org.ebayopensource.turmeric.tools.codegen.util.ClassPathUtil.java

private static void getClassPathFromClassLoader(LinkedList<File> classpath, ClassLoader classLoader) {
    if (classLoader == null) {
        return; // no classloader
    }/*from w  w  w  .  j  a  va 2  s  . c  o m*/

    if (!(classLoader instanceof URLClassLoader)) {
        // unable to get anything from this classloader.
        // Try parent instead.
        getClassPathFromClassLoader(classpath, classLoader.getParent());
        return;
    }

    URLClassLoader ucl = (URLClassLoader) classLoader;

    URL[] urls = null;
    if (ucl instanceof CodeGenClassLoader) {
        CodeGenClassLoader cgcl = (CodeGenClassLoader) ucl;
        urls = cgcl.getAllURLs();
    } else {
        urls = ucl.getURLs();
    }

    // Add the urls
    File file;
    String path;
    for (URL url : urls) {
        // Normalize the path
        try {
            file = new File(url.toURI());
        } catch (URISyntaxException e) {
            LOG.warning("Unable to identify file from invalid URI: " + url.toExternalForm());
            path = url.toExternalForm();
            if (path.startsWith("file:")) {
                path = path.substring("file:".length());
                path = FilenameUtils.normalize(path);
            }
            file = new File(path);
        }
        addFilePath(classpath, file);
    }

    getClassPathFromClassLoader(classpath, classLoader.getParent());
    dumpStats();
}

From source file:org.eclipse.jetty.webapp.WebAppContext.java

@Override
protected void doStart() throws Exception {
    try {//from w w w  .ja va 2s  . c o  m
        // Setup configurations
        loadConfigurations();

        // Setup system classes
        loadSystemClasses();

        // Setup server classes
        loadServerClasses();

        // Configure classloader
        _ownClassLoader = false;
        if (getClassLoader() == null) {
            WebAppClassLoader classLoader = new WebAppClassLoader(this);
            setClassLoader(classLoader);
            _ownClassLoader = true;
        }

        if (Log.isDebugEnabled()) {
            ClassLoader loader = getClassLoader();
            Log.debug("Thread Context class loader is: " + loader);
            loader = loader.getParent();
            while (loader != null) {
                Log.debug("Parent class loader is: " + loader);
                loader = loader.getParent();
            }
        }

        // Prepare for configuration
        for (int i = 0; i < _configurations.length; i++)
            _configurations[i].preConfigure(this);

        super.doStart();

        // Clean up after configuration
        for (int i = 0; i < _configurations.length; i++)
            _configurations[i].postConfigure(this);

        if (isLogUrlOnStart())
            dumpUrl();
    } catch (Exception e) {
        //start up of the webapp context failed, make sure it is not started
        Log.warn("Failed startup of context " + this, e);
        _unavailableException = e;
        setAvailable(false);
    }
}

From source file:org.fusesource.cloudmix.agent.mop.MopProcess.java

void dumpClassLoader(ClassLoader cl) {
    if (LOG.isDebugEnabled()) {
        if (cl instanceof URLClassLoader) {
            URLClassLoader urlClassLoader = (URLClassLoader) cl;
            URL[] urls = urlClassLoader.getURLs();
            for (URL url : urls) {
                LOG.debug("ClassLoader URL: " + url);
            }//  w  ww. j av a  2  s.  c  o  m
        }
        ClassLoader parent = cl.getParent();
        if (parent != null) {
            LOG.debug("Parent Class Loader: " + parent);
            dumpClassLoader(parent);
        }
    }
}

From source file:org.fusesource.meshkeeper.classloader.basic.BasicClassLoaderServer.java

private static void addExportedFiles(ClassLoader classLoader, int maxExportDepth,
        ArrayList<ExportedFile> elements) throws IOException {
    if (maxExportDepth > 0) {
        if (classLoader.getParent() != null) {
            //TODO wonder if it is appropriate to include the extension classloader ...
            //perhaps jdk specific extensions should be excluded?
            addExportedFiles(classLoader.getParent(), maxExportDepth - 1, elements);
        }//www. j  a v  a 2  s . c o  m
    }
    addExportedFiles(classLoader, elements);
}

From source file:org.hopen.framework.rewrite.CachedIntrospectionResults.java

/**
 * Check whether the given ClassLoader is underneath the given parent,
 * that is, whether the parent is within the candidate's hierarchy.
 * @param candidate the candidate ClassLoader to check
 * @param parent the parent ClassLoader to check for
 *///from ww  w.  java  2  s.  c  om
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
    if (candidate == null) {
        return false;
    }
    if (candidate == parent) {
        return true;
    }
    ClassLoader classLoaderToCheck = candidate;
    while (classLoaderToCheck != null) {
        classLoaderToCheck = classLoaderToCheck.getParent();
        if (classLoaderToCheck == parent) {
            return true;
        }
    }
    return false;
}

From source file:org.hyperic.hq.plugin.websphere.WebsphereProductPlugin.java

private void setExtDirs(String installDir) throws Exception {
    ClassLoader parent = getClass().getClassLoader().getParent();
    URLClassLoader loader = null;

    //rewind to top most parent, which should (must) be ExtClassLoader
    while (parent != null) {
        if (parent instanceof URLClassLoader) {
            loader = (URLClassLoader) parent;
        }//w w w . jav a  2 s  . c  om
        parent = parent.getParent();
    }

    log.debug("Using java.ext.dirs loader=" + loader);

    //bypass protected access.
    Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });

    addURL.setAccessible(true);

    String[] dirs = { "lib", "plugins", "runtimes" };

    for (int i = 0; i < dirs.length; i++) {
        File dir = new File(installDir, dirs[i]);
        String[] jars = dir.list();
        if (jars != null) {
            for (int j = 0; j < jars.length; j++) {
                File jar = new File(dir, jars[j]);
                if (isValidJar(jar)) {
                    log.debug("classpath += " + jar);
                    if (jar.getName().startsWith("com.ibm.ws.runtime_")) {
                        jar = runtimeJarHack(jar);
                    }
                    URL url = sun.net.www.ParseUtil.fileToEncodedURL(jar);
                    addURL.invoke(loader, new Object[] { url });
                } else {
                    log.debug("jar '" + jars[j] + "' skipped");
                    continue;
                }
            }
        }
    }
}

From source file:org.impalaframework.classloader.graph.GraphClassLoader.java

/**
 * Returns true if classes loaded by the specified class loader are visible to the current class loader.
 *///from   ww w . j a v  a  2s . co m
public boolean hasVisibilityOf(ClassLoader classLoader) {
    if (classLoader == this) {
        return true;
    }
    boolean hasVisibilityOf = delegateClassLoader.hasVisibilityOf(classLoader);

    if (hasVisibilityOf)
        return hasVisibilityOf;

    ClassLoader child = this;
    ClassLoader parent = null;

    while ((parent = child.getParent()) != null) {
        if (parent == classLoader) {
            return true;
        }
        child = parent;
    }

    return false;
}

From source file:org.jboss.web.tomcat.tc5.WebCtxLoader.java

/**
 * Create a WebCtxLoader given the ENC scoping class loader.
 *
 * @param encLoader//from   www. ja  v  a2s . c  om
 */
WebCtxLoader(ClassLoader encLoader) {
    this.encLoader = encLoader;
    this.ctxLoader = new ENCLoader(encLoader);
    ClassLoader parent = encLoader;
    while ((parent instanceof RepositoryClassLoader) == false && parent != null)
        parent = parent.getParent();
    this.delegate = (RepositoryClassLoader) parent;
}