Example usage for java.net URLClassLoader getClass

List of usage examples for java.net URLClassLoader getClass

Introduction

In this page you can find the example usage for java.net URLClassLoader getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java

/**
 * Get the list of classpath components//from w ww .  java 2  s  . c o  m
 *
 * @param ucl url classloader
 * @return List of classpath components
 */
private static List getUrlClassLoaderClasspathComponents(URLClassLoader ucl) {
    List components = new ArrayList();

    URL[] urls = new URL[0];

    // Workaround for running on JBoss with UnifiedClassLoader3 usage
    // We need to invoke getClasspath() method instead of getURLs()
    if (ucl.getClass().getName().equals("org.jboss.mx.loading.UnifiedClassLoader3")) {
        try {
            Method classPathMethod = ucl.getClass().getMethod("getClasspath", new Class[] {});
            urls = (URL[]) classPathMethod.invoke(ucl, new Object[0]);
        } catch (Exception e) {
            LogFactory.getLog(ClasspathUtils.class)
                    .debug("Error invoking getClasspath on UnifiedClassLoader3: ", e);
        }
    } else {
        // Use regular ClassLoader method to get classpath
        urls = ucl.getURLs();
    }

    for (int i = 0; i < urls.length; i++) {
        URL url = urls[i];
        components.add(getCanonicalPath(url.getPath()));
    }

    return components;
}

From source file:org.pentaho.marketplace.domain.services.BaPluginService.java

@Override
protected void unloadPlugin(IPlugin plugin) {
    String pluginId = plugin.getId();
    IPluginManager pluginManager = this.getPluginManager(this.getCurrentSession());
    ClassLoader cl = pluginManager.getClassLoader(pluginId);
    if (cl != null && cl instanceof URLClassLoader) {
        try {/* ww w. j  av a  2s  . c  o  m*/
            URLClassLoader cl1 = (URLClassLoader) cl;
            Util.closeURLClassLoader(cl1);
            Method closeMethod = cl1.getClass().getMethod(BaPluginService.CLOSE_METHOD_NAME);
            closeMethod.invoke(cl1);
        } catch (Throwable e) {
            if (e instanceof NoSuchMethodException) {
                logger.debug("Probably running in java 6 so close method on URLClassLoader is not available");
            } else if (e instanceof IOException) {
                logger.error("Unable to close class loader for plugin. Will try uninstalling plugin anyway", e);
            } else {
                logger.error("Error while closing class loader", e);
            }
        }
    }
}

From source file:org.pentaho.marketplace.domain.services.PluginService.java

private void closeClassLoader(String pluginId) {
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession());
    ClassLoader cl = pluginManager.getClassLoader(pluginId);
    if (cl != null && cl instanceof URLClassLoader) {
        try {//from  ww  w.  ja va  2 s .c om
            URLClassLoader cl1 = (URLClassLoader) cl;
            Util.closeURLClassLoader(cl1);
            Method closeMethod = cl1.getClass().getMethod(PluginService.CLOSE_METHOD_NAME);
            closeMethod.invoke(cl1);
        } catch (Throwable e) {
            if (e instanceof NoSuchMethodException) {
                logger.debug("Probably running in java 6 so close method on URLClassLoader is not available");
            } else if (e instanceof IOException) {
                logger.error("Unable to close class loader for plugin. Will try uninstalling plugin anyway", e);
            } else {
                logger.error("Error while closing class loader", e);
            }
        }
    }
}