示例#1
0
 public boolean isUnloadedClassLoader() {
   if (getClassLoader() instanceof RepositoryClassLoader) {
     RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
     return rcl.getLoaderRepository() == null;
   }
   return false;
 }
示例#2
0
  public Class<?> toClass(
      ToClassInvokerPoolReference pool,
      CtClass cc,
      String classFileName,
      ClassLoader loader,
      ProtectionDomain domain)
      throws CannotCompileException {
    boolean trace = logger.isTraceEnabled();
    pool.lockInCache(cc);
    final ClassLoader myloader = pool.getClassLoader();
    if (myloader == null || tmpDir == null) {
      if (trace)
        logger.trace(
            this
                + " "
                + pool
                + ".toClass() myloader:"
                + myloader
                + " tmpDir:"
                + tmpDir
                + " default to superPool.toClass for "
                + cc.getName());
      Class<?> clazz = pool.superPoolToClass(cc, loader, domain);
      if (trace)
        logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + clazz);
      return clazz;
    }
    Class<?> dynClass = null;
    try {
      File classFile = null;
      // Write the clas file to the tmpdir
      synchronized (tmplock) {
        classFile = new File(tmpDir, classFileName);
        if (trace)
          logger.trace(
              this
                  + " "
                  + pool
                  + ".toClass() myloader:"
                  + myloader
                  + " writing bytes to "
                  + classFile);
        File pkgDirs = classFile.getParentFile();
        pkgDirs.mkdirs();
        FileOutputStream stream = new FileOutputStream(classFile);
        stream.write(cc.toBytecode());
        stream.flush();
        stream.close();
        classFile.deleteOnExit();
      }
      // We have to clear Blacklist caches or the class will never
      // be found
      // ((UnifiedClassLoader)dcl).clearBlacklists();
      // To be backward compatible
      RepositoryClassLoader rcl = (RepositoryClassLoader) myloader;
      rcl.clearClassBlackList();
      rcl.clearResourceBlackList();

      // Now load the class through the cl
      dynClass = myloader.loadClass(cc.getName());
      if (trace)
        logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + dynClass);
      return dynClass;
    } catch (Exception ex) {
      ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
      cfe.initCause(ex);
      throw cfe;
    }
  }