1 15 package org.apache.hivemind.service.impl; 16 17 import java.util.HashSet ; 18 import java.util.Set ; 19 20 import javassist.CannotCompileException; 21 import javassist.ClassPath; 22 import javassist.ClassPool; 23 import javassist.CtClass; 24 import javassist.LoaderClassPath; 25 26 33 public class HiveMindClassPool extends ClassPool 34 { 35 private ClassFactoryClassLoader _loader = new ClassFactoryClassLoader(HiveMindClassPool.class.getClassLoader()); 36 37 40 private Set _loaders = new HashSet (); 41 42 public HiveMindClassPool() 43 { 44 super(null); 45 46 appendClassLoader(Thread.currentThread().getContextClassLoader()); 47 } 48 49 52 public synchronized void appendClassLoader(ClassLoader loader) 53 { 54 if (loader == null || loader == _loader || _loaders.contains(loader)) 55 return; 56 57 _loader.addDelegateLoader(loader); 58 59 ClassPath path = new LoaderClassPath(loader); 60 61 appendClassPath(path); 62 63 _loaders.add(loader); 64 } 65 66 73 public Class toClass(CtClass ctClass) throws CannotCompileException 74 { 75 return ctClass.toClass(_loader, this.getClass().getProtectionDomain()); 76 } 77 } | Popular Tags |