Example #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);
 }
Example #2
0
  BundleClassLoader createBCL(final BundleProtectionDomain pd, final String[] cp) {
    BundleClassLoader bcl = bundle.getBundleData().createClassLoader(BundleLoader.this, pd, cp);
    // attach existing fragments to classloader
    BundleFragment[] fragments = bundle.getFragments();
    if (fragments != null)
      for (int i = 0; i < fragments.length; i++) {
        try {
          bcl.attachFragment(
              fragments[i].getBundleData(),
              fragments[i].getProtectionDomain(),
              fragments[i].getBundleData().getClassPath());
        } catch (BundleException be) {
          bundle.getFramework().publishFrameworkEvent(FrameworkEvent.ERROR, bundle, be);
        }
      }

    // finish the initialization of the classloader.
    bcl.initialize();
    return bcl;
  }
Example #3
0
  private ClassLoader getParentPrivileged(final BundleClassLoader bcl) {
    if (System.getSecurityManager() == null) return bcl.getParent();

    return (ClassLoader)
        AccessController.doPrivileged(
            new PrivilegedAction() {
              public Object run() {
                return bcl.getParent();
              }
            });
  }
Example #4
0
 public synchronized void attachFragment(BundleFragment fragment) throws BundleException {
   ExportPackageDescription[] exports = proxy.getBundleDescription().getSelectedExports();
   if (classloader == null) {
     initializeExports(exports, exportedPackages);
     return;
   }
   String[] classpath = fragment.getBundleData().getClassPath();
   if (classpath != null)
     classloader.attachFragment(
         fragment.getBundleData(), fragment.getProtectionDomain(), classpath);
   initializeExports(exports, exportedPackages);
 }
Example #5
0
 /*
  * Close the the BundleLoader.
  *
  */
 synchronized void close() {
   if ((loaderFlags & FLAG_CLOSED) != 0) return;
   if (classloader != null) classloader.close();
   if (policy != null) policy.close(bundle.getFramework().getSystemBundleContext());
   loaderFlags |= FLAG_CLOSED; /* This indicates the BundleLoader is destroyed */
 }