Java 类java.lang.ClassLoader 实例源码

项目:hermes    文件:FixtureStore.java   
/**
 * 
 */
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;
}
项目:divconq    文件:Bundle.java   
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;
}
项目:play-sitemap-module.edulify.com    文件:AnnotationUrlProvider.java   
@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);
    }
  }
}
项目:androidnative.pri    文件:SystemDispatcher.java   
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();
        }
   }
项目:OpenJSharp    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OpenJSharp    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:OpenJSharp    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OpenJSharp    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OpenJSharp    文件:SecuritySupport.java   
/**
 * 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();
    }
}
项目:openjdk9    文件:SecuritySupport.java   
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;
        }
    });
}
项目:openjdk9    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:openjdk9    文件:SecuritySupport.java   
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;
        }
    });
}
项目:openjdk9    文件:SecuritySupport.java   
/**
 * 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();
    }
}
项目:hermes    文件:FixtureStore.java   
/**
 * 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;
}
项目:hermes    文件:FixtureStore.java   
/**
 * 
 * @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());
}
项目:lookaside_java-1.8.0-openjdk    文件:SecuritySupport.java   
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;
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:SecuritySupport.java   
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;
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:SecuritySupport.java   
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;
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:SecuritySupport.java   
/**
 * 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();
    }
}
项目:infobip-open-jdk-8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:infobip-open-jdk-8    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:infobip-open-jdk-8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:infobip-open-jdk-8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:infobip-open-jdk-8    文件:SecuritySupport.java   
/**
 * 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();
    }
}
项目:OLD-OpenJDK8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OLD-OpenJDK8    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:OLD-OpenJDK8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OLD-OpenJDK8    文件:SecuritySupport.java   
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;
        }
    });
}
项目:OLD-OpenJDK8    文件:SecuritySupport.java   
/**
 * 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();
    }
}
项目:spork-streaming    文件:BagFactory.java   
/**
 * 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;
}
项目:spork    文件:BagFactory.java   
/**
 * 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;
}
项目:divconq    文件:Bundle.java   
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;
}
项目:freeVM    文件:RMIClassLoader.java   
/**
 * @ar.org.fitc.spec_ref
 * 
 */
public static Class<?> loadClass(String codebase, String name,
        ClassLoader defaultLoader) throws MalformedURLException,
        ClassNotFoundException {

    return provider.loadClass(codebase, name, defaultLoader);
}
项目:freeVM    文件:RMIClassLoader.java   
/**
 * @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);
}
项目:freeVM    文件:RMIClassLoader.java   
/**
 * @ar.org.fitc.spec_ref
 * 
 */
public static Class<?> loadClass(String codebase, String name,
        ClassLoader defaultLoader) throws MalformedURLException,
        ClassNotFoundException {

    return provider.loadClass(codebase, name, defaultLoader);
}
项目:freeVM    文件:RMIClassLoader.java   
/**
 * @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);
}
项目:openjdk-icedtea7    文件:SecuritySupport.java   
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;
        }
    });
}
项目:openjdk-icedtea7    文件:SecuritySupport.java   
static ClassLoader getSystemClassLoader() {
    return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader cl = null;
            try {
                cl = ClassLoader.getSystemClassLoader();
            } catch (SecurityException ex) {
            }
            return cl;
        }
    });
}
项目:openjdk-icedtea7    文件:SecuritySupport.java   
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;
        }
    });
}