/** * @see org.glassfish.internal.api.ClassLoaderHierarchy#getAppLibClassLoader(String, List<URI>) */ public ClassLoader getAppLibClassLoader(String application, List<URI> libURIs) throws MalformedURLException { ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class); DelegatingClassLoader connectorCL = clh.getConnectorClassLoader(application); if (libURIs == null || libURIs.isEmpty()) { // Optimization: when there are no libraries, why create an empty // class loader in the hierarchy? Instead return the parent. return connectorCL; } final ClassLoader commonCL = commonCLS.getCommonClassLoader(); DelegatingClassLoader applibCL = AccessController.doPrivileged( new PrivilegedAction<DelegatingClassLoader>() { public DelegatingClassLoader run() { return new DelegatingClassLoader(commonCL); } }); // order of classfinders is important here : // connector's classfinders should be added before libraries' classfinders // as the delegation hierarchy is appCL->app-libsCL->connectorCL->commonCL->API-CL // since we are merging connector and applib classfinders to be at same level, // connector classfinders need to be be before applib classfinders in the horizontal // search path for (DelegatingClassLoader.ClassFinder cf : connectorCL.getDelegates()) { applibCL.addDelegate(cf); } addDelegates(libURIs, applibCL); return applibCL; }
/** @see org.glassfish.internal.api.ClassLoaderHierarchy#getAppLibClassFinder(List<URI>) */ public DelegatingClassLoader.ClassFinder getAppLibClassFinder(Collection<URI> libURIs) throws MalformedURLException { final ClassLoader commonCL = commonCLS.getCommonClassLoader(); DelegatingClassLoader appLibClassFinder = AccessController.doPrivileged( new PrivilegedAction<DelegatingClassLoader>() { public DelegatingClassLoader run() { return new AppLibClassFinder(commonCL); } }); addDelegates(libURIs, appLibClassFinder); return (DelegatingClassLoader.ClassFinder) appLibClassFinder; }
private void addDelegates(Collection<URI> libURIs, DelegatingClassLoader holder) throws MalformedURLException { ClassLoader commonCL = commonCLS.getCommonClassLoader(); for (URI libURI : libURIs) { synchronized (this) { DelegatingClassLoader.ClassFinder libCF = classFinderRegistry.get(libURI); if (libCF == null) { libCF = new URLClassFinder(new URL[] {libURI.toURL()}, commonCL); classFinderRegistry.put(libURI, libCF); } holder.addDelegate(libCF); } } }