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

JBossClassPoolFactory

public class JBossClassPoolFactory extends Object implements ScopedClassPoolFactory
Comment
author
Bill Burke
version
$Revision: 60381 $

Fields Summary
protected File
tmpClassesDir
Constructors Summary
public JBossClassPoolFactory(File tmpClassesDir)

      this.tmpClassesDir = tmpClassesDir;

   
Methods Summary
public javassist.scopedpool.ScopedClassPoolcreate(java.lang.ClassLoader cl, javassist.ClassPool src, javassist.scopedpool.ScopedClassPoolRepository repository)

      try
      {
         if (cl instanceof RepositoryClassLoader)
         {
            File tempdir = getTempDirectory(cl);
            URL tmpCP = createURLAndAddToLoader(cl, tempdir);
            if (AspectManager.scopedCLHelper.ifScopedDeploymentGetScopedParentUclForCL(cl) != null)
            {
               //It is scoped
               return new ScopedJBossClassPool(cl, src, repository, tempdir, tmpCP);
            }
            return new JBossClassPool(cl, src, repository, tempdir, tmpCP);
         }
         return new AOPClassPool(cl, src, repository);
      }
      catch (IOException e)
      {
         throw new RuntimeException(e);
      }
   
public javassist.scopedpool.ScopedClassPoolcreate(javassist.ClassPool src, javassist.scopedpool.ScopedClassPoolRepository repository)

      return new JBossClassPool(src, repository);
   
public java.io.FilecreateTempDir(java.lang.ClassLoader cl)

      File tempdir = File.createTempFile("ucl", "", tmpClassesDir);
      tempdir.delete();
      tempdir.mkdir();
      tempdir.deleteOnExit();

      return tempdir;
   
private java.net.URLcreateURLAndAddToLoader(java.lang.ClassLoader cl, java.io.File tempdir)

      URL tmpURL = tempdir.toURL();
      URL tmpCP = new URL(tmpURL, "?dynamic=true");

      RepositoryClassLoader ucl = (RepositoryClassLoader) cl;

      // We may be undeploying.
      if (ucl.getLoaderRepository() != null)
      {
         ucl.addURL(tmpCP);
      }
      
      return tmpCP;
   
private java.io.FilegetTempDirectory(java.lang.ClassLoader cl)

      File tempdir = null;
      int attempts = 0;
      IOException ex = null;
      while (tempdir == null && attempts < 5)
      {
         //Workaround for JBAOP-254, retry a few times
         try
         {
            tempdir = createTempDir(cl);
         }
         catch (IOException e)
         {
            ex = e;
         }
      }
      
      if (tempdir == null)
      {
         throw new RuntimeException("", ex);
      }
      
      return tempdir;