FileDocCategorySizeDatePackage
JBossClassPool.javaAPI DocJBoss 4.2.14334Fri Jul 13 21:02:24 BST 2007org.jboss.aop.deployment

JBossClassPool

public class JBossClassPool extends org.jboss.aop.classpool.AOPClassPool
Comment
author
Bill Burke
version
$Revision: 60560 $

Fields Summary
protected File
tempdir
Used for dynamically created classes (see loadClass(String, byte[]), ClassLoader)
protected URL
tempURL
protected final Object
tmplock
Constructors Summary
protected JBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)

   
             
   
      super(cl, src, repository);
      tempdir = tmp;
      tempURL = tmpURL;
   
protected JBossClassPool(ClassPool src, ScopedClassPoolRepository repository)

      super(src, repository);
   
Methods Summary
protected booleanisLocalResource(java.lang.String resourceName)

      if (super.isLocalResource(resourceName))
      {
         return true;
      }
      
      File file = new File(tempdir, resourceName);
      if (file.exists())
      {
         return true;
      }
      
      return false;
   
public booleanisUnloadedClassLoader()

      if (getClassLoader() instanceof RepositoryClassLoader)
      {
         RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
         return rcl.getLoaderRepository() == null;
      }
      return false;
   
public java.lang.ClasstoClass(javassist.CtClass cc, java.lang.ClassLoader loader, java.security.ProtectionDomain domain)

      lockInCache(cc);
      if (getClassLoader() == null || tempdir == null)
      {
         return super.toClass(cc, loader, domain);
      }
      Class dynClass = null;
      try
      {
         File classFile = null;
         String classFileName = getResourceName(cc.getName());
         // Write the clas file to the tmpdir
         synchronized (tmplock)
         {
            classFile = new File(tempdir, classFileName);
            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) getClassLoader();
         rcl.clearClassBlackList();
         rcl.clearResourceBlackList();

         // Now load the class through the cl
         dynClass = getClassLoader().loadClass(cc.getName());
      }
      catch (Exception ex)
      {
         ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName() + " with " + getClassLoader());
         cfe.initCause(ex);
         throw cfe;
      }

      return dynClass;