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); }
/** * {@inheritDoc} */ public void destroy() { resourceFinder.destroy(); super.destroy(); }
Class cachedClass = findLoadedClass(name); if (cachedClass != null) { return resolveClass(cachedClass, resolve); if (inverseClassLoading && !isDestroyed() && !isNonOverridableClass(name)) { try { Class clazz = findClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { 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) { if (!isDestroyed()) { try { Class clazz = findClass(name); return resolveClass(clazz, resolve); } catch (ClassNotFoundException ignored) { throw new ClassNotFoundException(name + " in classloader " + getName());
if (isDestroyed()) { return null; if (inverseClassLoading && !isDestroyed() && !isNonOverridableResource(name)) { URL url = findResource(name); if (url != null) { return url; if (!isHiddenResource(name)) { for (int i = 0; i < parents.length; i++) { ClassLoader parent = parents[i]; if (!isDestroyed()) { return findResource(name);
return new MultiParentClassLoader( name, urls.toArray(new URL[urls.size()]),
/** * 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]; }
/** * {@inheritDoc} */ protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class result = null; // // check if the class is already in the local cache // SoftReference<Class> reference = cache.get(name); if (reference != null) { result = reference.get(); } if (result == null) { result = doLoadClass(name, resolve); cache.put(name, new SoftReference<Class>(result)); } return result; }
/** * {@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 = resourceFinder.findResources(resourceName); // join the two together Enumeration resources = new UnionEnumeration(parentResources, myResources); return resources; }
protected ClassLoader createClassLoader() { SharedLibraryDesc library = descriptor.getSharedLibrary(); // Make the current ClassLoader the parent ClassLoader parent = new BundleDelegatingClassLoader(bundle, getClass().getClassLoader()); boolean parentFirst = library.isParentFirstClassLoaderDelegation(); ClassPath cp = library.getSharedLibraryClassPath(); String[] classPathNames = cp.getPathElements(); List<URL> urls = new ArrayList<URL>(); for (String classPathName : classPathNames) { File f = new File(installRoot, classPathName); if (!f.exists()) { logger.warn("Shared library classpath entry not found: '" + classPathName + "'"); } try { urls.add(f.getCanonicalFile().toURL()); } catch (IOException e) { throw new IllegalArgumentException("Shared library classpath entry not found: '" + classPathName + "'"); } } return new MultiParentClassLoader( library.getIdentification().getName(), urls.toArray(new URL[urls.size()]), parent, !parentFirst, new String[0], new String[]{"java.", "javax."}); } }
public ServerInfo createBroker(String uri, Properties properties) throws Exception { CONFIG_PROPERTIES.set(properties); try { ClassLoader classLoader = new MultiParentClassLoader("xbean", new URL[0], new ClassLoader[] { this.getClass().getClassLoader(), BrokerService.class.getClassLoader()
public ServerInfo createBroker(String uri, Properties properties) throws Exception { CONFIG_PROPERTIES.set(properties); try { ClassLoader classLoader = new MultiParentClassLoader("xbean", new URL[0], new ClassLoader[] { this.getClass().getClassLoader(), BrokerService.class.getClassLoader()