1 22 package org.jboss.aop.deployment; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.URL ; 27 28 import org.jboss.aop.AspectManager; 29 import org.jboss.aop.classpool.AOPClassPool; 30 import org.jboss.mx.loading.RepositoryClassLoader; 31 import javassist.ClassPool; 32 import javassist.scopedpool.ScopedClassPool; 33 import javassist.scopedpool.ScopedClassPoolFactory; 34 import javassist.scopedpool.ScopedClassPoolRepository; 35 36 43 public class JBossClassPoolFactory implements ScopedClassPoolFactory 44 { 45 protected File tmpClassesDir; 46 47 public JBossClassPoolFactory(File tmpClassesDir) throws IOException 48 { 49 this.tmpClassesDir = tmpClassesDir; 50 51 } 52 public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository) 53 { 54 try 55 { 56 if (cl instanceof RepositoryClassLoader) 57 { 58 File tempdir = createTempDir(cl); 59 URL tmpCP = createURLAndAddToLoader(cl, tempdir); 60 if (AspectManager.scopedCLHelper.ifScopedDeploymentGetScopedParentUclForCL(cl) != null) 61 { 62 return new ScopedJBossClassPool(cl, src, repository, tempdir, tmpCP); 64 } 65 return new JBossClassPool(cl, src, repository, tempdir, tmpCP); 66 } 67 return new AOPClassPool(cl, src, repository); 68 } 69 catch (IOException e) 70 { 71 throw new RuntimeException (e); 72 } 73 } 74 75 public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository) 76 { 77 return new TempJBossClassPool(src, repository); 78 } 79 80 public File createTempDir(ClassLoader cl) throws IOException 81 { 82 File tempdir = File.createTempFile("ucl", "", tmpClassesDir); 83 tempdir.delete(); 84 tempdir.mkdir(); 85 tempdir.deleteOnExit(); 86 87 return tempdir; 88 } 89 90 private URL createURLAndAddToLoader(ClassLoader cl, File tempdir) throws IOException 91 { 92 URL tmpURL = tempdir.toURL(); 93 URL tmpCP = new URL (tmpURL, "?dynamic=true"); 94 95 RepositoryClassLoader ucl = (RepositoryClassLoader) cl; 96 97 if (ucl.getLoaderRepository() != null) 99 { 100 ucl.addURL(tmpCP); 101 } 102 103 return tmpCP; 104 } 105 } 106 | Popular Tags |