1 22 package org.jboss.aop.deployment; 23 24 import java.io.File ; 25 import java.io.FileOutputStream ; 26 import java.net.URL ; 27 import java.security.ProtectionDomain ; 28 29 import org.jboss.aop.classpool.AOPClassPool; 30 import org.jboss.mx.loading.RepositoryClassLoader; 31 import javassist.CannotCompileException; 32 import javassist.ClassPool; 33 import javassist.CtClass; 34 import javassist.scopedpool.ScopedClassPoolRepository; 35 36 42 public class JBossClassPool extends AOPClassPool 43 { 44 47 protected File tempdir = null; 48 protected URL tempURL = null; 49 protected final Object tmplock = new Object (); 51 52 protected JBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL) 53 { 54 super(cl, src, repository); 55 tempdir = tmp; 56 tempURL = tmpURL; 57 } 58 59 protected JBossClassPool(ClassPool src, ScopedClassPoolRepository repository) 60 { 61 super(src, repository); 62 } 63 64 public boolean isUnloadedClassLoader() 65 { 66 if (getClassLoader() instanceof RepositoryClassLoader) 67 { 68 RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader(); 69 return rcl.getLoaderRepository() == null; 70 } 71 return false; 72 } 73 74 public Class toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) 75 throws CannotCompileException 76 { 77 lockInCache(cc); 78 if (getClassLoader() == null || tempdir == null) 79 { 80 return super.toClass(cc, loader, domain); 81 } 82 Class dynClass = null; 83 try 84 { 85 File classFile = null; 86 String classFileName = getResourceName(cc.getName()); 87 synchronized (tmplock) 89 { 90 classFile = new File (tempdir, classFileName); 91 File pkgDirs = classFile.getParentFile(); 92 pkgDirs.mkdirs(); 93 FileOutputStream stream = new FileOutputStream (classFile); 94 stream.write(cc.toBytecode()); 95 stream.flush(); 96 stream.close(); 97 classFile.deleteOnExit(); 98 } 99 RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader(); 104 rcl.clearClassBlackList(); 105 rcl.clearResourceBlackList(); 106 107 dynClass = getClassLoader().loadClass(cc.getName()); 109 } 110 catch (Exception ex) 111 { 112 ClassFormatError cfe = new ClassFormatError ("Failed to load dyn class: " + cc.getName()); 113 cfe.initCause(ex); 114 throw cfe; 115 } 116 117 return dynClass; 118 } 119 120 protected boolean isLocalResource(String resourceName) 121 { 122 if (super.isLocalResource(resourceName)) 123 { 124 return true; 125 } 126 127 File file = new File (tempdir, resourceName); 128 if (file.exists()) 129 { 130 return true; 131 } 132 133 return false; 134 } 135 } 136 | Popular Tags |