1 22 package org.jboss.aop.deployment; 23 24 import java.io.File ; 25 import java.io.FileOutputStream ; 26 import java.security.ProtectionDomain ; 27 28 import org.jboss.aop.classpool.AOPClassPool; 29 import org.jboss.mx.loading.UnifiedClassLoader; 30 import javassist.CannotCompileException; 31 import javassist.ClassPool; 32 import javassist.CtClass; 33 import javassist.scopedpool.ScopedClassPoolRepository; 34 35 41 public class JBossClassPool32 extends AOPClassPool 42 { 43 46 protected File tempdir = null; 47 protected final Object tmplock = new Object (); 49 50 protected JBossClassPool32(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp) 51 { 52 super(cl, src, repository); 53 tempdir = tmp; 54 } 55 56 protected JBossClassPool32(ClassPool src, ScopedClassPoolRepository repository) 57 { 58 super(src, repository); 59 } 60 61 public boolean isUnloadedClassLoader() 62 { 63 if (getClassLoader() instanceof UnifiedClassLoader) 64 { 65 UnifiedClassLoader rcl = (UnifiedClassLoader) getClassLoader(); 66 return rcl.getLoaderRepository() == null; 67 } 68 return false; 69 } 70 71 public Class toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) 72 throws CannotCompileException 73 { 74 lockInCache(cc); 75 if (getClassLoader() == null || tempdir == null) 76 { 77 return super.toClass(cc, loader, domain); 78 } 79 Class dynClass = null; 80 try 81 { 82 File classFile = null; 83 String classFileName = cc.getName().replace('.', '/') + ".class"; 84 synchronized (tmplock) 86 { 87 classFile = new File (tempdir, classFileName); 88 File pkgDirs = classFile.getParentFile(); 89 pkgDirs.mkdirs(); 90 FileOutputStream stream = new FileOutputStream (classFile); 91 stream.write(cc.toBytecode()); 92 stream.flush(); 93 stream.close(); 94 classFile.deleteOnExit(); 95 } 96 UnifiedClassLoader rcl = (UnifiedClassLoader) getClassLoader(); 101 rcl.clearBlacklists(); 102 103 dynClass = getClassLoader().loadClass(cc.getName()); 105 } 106 catch (Exception ex) 107 { 108 ClassFormatError cfe = new ClassFormatError ("Failed to load dyn class: " + cc.getName()); 109 cfe.initCause(ex); 110 throw cfe; 111 } 112 113 return dynClass; 114 } 115 116 } 117 | Popular Tags |