/** * */ public static ClassLoader addFixturesToLoader(ClassLoader loader, URL[] fixtureURL) throws Exception { if (loader == null || fixtureURL == null) { return loader; } if (!(loader instanceof URLClassLoader)) // If it is not an instance of URLClassLoader, we can add url into it. { return loader; } URLClassLoader urlLoader = (URLClassLoader)loader; Method method = URLClassLoader.class.getDeclaredMethod("addURL", clhackParams); method.setAccessible(true); for (URL u : fixtureURL) method.invoke(urlLoader, new Object[]{ u }); return urlLoader; }
public byte[] findFileEntry(String name) { /* retire?? for (LibLoader lib : this.libloaders) { byte[] cd = lib.getEntry(name); if (cd != null) return cd; } */ ClassLoader p = this.getParent(); if (p instanceof Bundle) return ((Bundle)p).findFileEntry(name); return null; }
@Override public void addUrlsTo(WebSitemapGenerator generator) { String baseUrl = configuration.getString("sitemap.baseUrl"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Reflections reflections = new Reflections("controllers", new MethodAnnotationsScanner()); Set<Method> actions = reflections.getMethodsAnnotatedWith(SitemapItem.class); for(Method method : actions) { String actionUrl = actionUrl(classLoader, method); SitemapItem annotation = method.getAnnotation(SitemapItem.class); if(annotation != null) { WebSitemapUrl url = webSitemapUrl(baseUrl, actionUrl, annotation); generator.addUrl(url); } } }
public static void loadClass(String className) { try { ClassLoader classLoader = SystemDispatcher.class.getClassLoader(); Class aClass = Class.forName(className,true,classLoader); // Log.d(TAG,"Class Loaded: " + className); } catch (ClassNotFoundException e) { Log.e(TAG,"Failed to load class: " + className); e.printStackTrace(); } }
static ClassLoader getContextClassLoader() { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (SecurityException ex) { } return cl; } }); }
static ClassLoader getSystemClassLoader() { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader cl = null; try { cl = ClassLoader.getSystemClassLoader(); } catch (SecurityException ex) { } return cl; } }); }
static ClassLoader getParentClassLoader(final ClassLoader cl) { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader parent = null; try { parent = cl.getParent(); } catch (SecurityException ex) { } // eliminate loops in case of the boot // ClassLoader returning itself as a parent return (parent == cl) ? null : parent; } }); }
public static InputStream getResourceAsStream(final ClassLoader cl, final String name) { return (InputStream) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { InputStream ris; if (cl == null) { ris = Object.class.getResourceAsStream("/" + name); } else { ris = cl.getResourceAsStream(name); } return ris; } }); }
/** * Figure out which ClassLoader to use. */ public static ClassLoader findClassLoader() { if (System.getSecurityManager()!=null) { //this will ensure bootclassloader is used return null; } else { return SecuritySupport.class.getClassLoader(); } }
/** * Create a class loader which has <code>old</code> as the basis, and in additional to * a set fixture path from <code>classes</code>. * * @param old * @param classes * @return */ public static ClassLoader createFixtureLoader(boolean autoJarInclude, ClassLoader old, Class<?>...classes) { if (old == null) { return FixtureStore.createFixtureLoader(autoJarInclude, classes); } if (classes == null || classes.length == 0) { return old; } // Create a combined loader for classes first. ClassLoader combinedLoader = FixtureStore.createFixtureLoader(autoJarInclude, classes); if (combinedLoader instanceof URLClassLoader) { URL [] additionClasspath = ((URLClassLoader) combinedLoader).getURLs(); for (URL u : additionClasspath) { clogger.debug("Adding resource path to fixture loader {}", u.toString()); } return new URLClassLoader(additionClasspath, old); } return old; }
/** * * @param src * @param dest * @return * @throws Exception */ public static ClassLoader addFixtureLoaderFrom(ClassLoader src, ClassLoader dest) throws Exception { if (src == null || dest == null) // Null Guard. return null; if (!(src instanceof URLClassLoader) || !(dest instanceof URLClassLoader) ) // Type Guard return null; URLClassLoader usrc = (URLClassLoader) src; URLClassLoader udest = (URLClassLoader) dest; return FixtureStore.addFixturesToLoader(udest, usrc.getURLs()); }
/** * Get a reference to the singleton factory. * @return BagFactory */ public static BagFactory getInstance() { if (gSelf == null) { String factoryName = System.getProperty("pig.data.bag.factory.name"); String factoryJar = System.getProperty("pig.data.bag.factory.jar"); if (factoryName != null && factoryJar != null) { try { URL[] urls = new URL[1]; urls[0] = new URL(factoryJar); ClassLoader loader = new URLClassLoader(urls, BagFactory.class.getClassLoader()); Class c = Class.forName(factoryName, true, loader); Object o = c.newInstance(); if (!(o instanceof BagFactory)) { throw new RuntimeException("Provided factory " + factoryName + " does not extend BagFactory!"); } gSelf = (BagFactory)o; } catch (Exception e) { if (e instanceof RuntimeException) { // We just threw this RuntimeException re = (RuntimeException)e; throw re; } throw new RuntimeException("Unable to instantiate " + "bag factory " + factoryName, e); } } else { gSelf = new DefaultBagFactory(); } } return gSelf; }
public boolean hasFileEntry(String fpath) { /* retire?? for (LibLoader lib : this.libloaders) if (lib.hasEntry(fpath)) return true; */ ClassLoader p = this.getParent(); if (p instanceof Bundle) return ((Bundle)p).hasFileEntry(fpath); return false; }
/** * @ar.org.fitc.spec_ref * */ public static Class<?> loadClass(String codebase, String name, ClassLoader defaultLoader) throws MalformedURLException, ClassNotFoundException { return provider.loadClass(codebase, name, defaultLoader); }
/** * @ar.org.fitc.spec_ref * */ public static Class<?> loadProxyClass(String codebase, String[] interfaces, ClassLoader defaultLoader) throws MalformedURLException, ClassNotFoundException, IllegalArgumentException { return provider.loadProxyClass(codebase, interfaces, defaultLoader); }