Esempio n. 1
0
 /**
  * This method loads a class from the bundle. The class is searched for in the same manner as it
  * would if it was being loaded from a bundle (i.e. all hosts, fragments, import, required bundles
  * and local resources are searched.
  *
  * @param name the name of the desired Class.
  * @return the resulting Class
  * @exception java.lang.ClassNotFoundException if the class definition was not found.
  */
 public final Class loadClass(String name) throws ClassNotFoundException {
   BundleClassLoader bcl = createClassLoader();
   // The instanceof check here is just to be safe.  The javadoc contract stated in
   // BundleClassLoader
   // mandate that BundleClassLoaders be an instance of ClassLoader.
   if (name.length() > 0 && name.charAt(0) == '[' && bcl instanceof ClassLoader)
     return Class.forName(name, false, (ClassLoader) bcl);
   return bcl.loadClass(name);
 }
Esempio n. 2
0
 private static ClassLoader getClassLoader(final Class clazz) {
   if (System.getSecurityManager() == null) return clazz.getClassLoader();
   return (ClassLoader)
       AccessController.doPrivileged(
           new PrivilegedAction() {
             public Object run() {
               return clazz.getClassLoader();
             }
           });
 }