/** * Makes an instance. */ public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository) { return new ScopedClassPool(null, src, repository, true); } }
public void unregisterClassLoader(ClassLoader cl) { synchronized (registeredCLs) { ScopedClassPool pool = (ScopedClassPool)registeredCLs.remove(cl); if (pool != null) pool.close(); } }
/** * Get any local copy of the class * * @param classname * the class name * @return the class * @throws NotFoundException * when the class is not found */ public synchronized CtClass getLocally(String classname) throws NotFoundException { softcache.remove(classname); CtClass clazz = (CtClass)classes.get(classname); if (clazz == null) { clazz = createCtClass(classname, true); if (clazz == null) throw new NotFoundException(classname); super.cacheCtClass(classname, clazz, false); } return clazz; }
/** * Convert a javassist class to a java class * * @param ct * the javassist class * @param loader * the loader * @throws CannotCompileException * for any error */ public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { // We need to pass up the classloader stored in this pool, as the // default implementation uses the Thread context cl. // In the case of JSP's in Tomcat, // org.apache.jasper.servlet.JasperLoader will be stored here, while // it's parent // org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread // context cl. The invocation class needs to // be generated in the JasperLoader classloader since in the case of // method invocations, the package name will be // the same as for the class generated from the jsp, i.e. // org.apache.jsp. For classes belonging to org.apache.jsp, // JasperLoader does NOT delegate to its parent if it cannot find them. lockInCache(ct); return super.toClass(ct, getClassLoader0(), domain); } }
/** * This method will check to see if a register classloader has been * undeployed (as in JBoss) */ public void clearUnregisteredClassLoaders() { ArrayList toUnregister = null; synchronized (registeredCLs) { Iterator it = registeredCLs.values().iterator(); while (it.hasNext()) { ScopedClassPool pool = (ScopedClassPool)it.next(); if (pool.isUnloadedClassLoader()) { it.remove(); ClassLoader cl = pool.getClassLoader(); if (cl != null) { if (toUnregister == null) { toUnregister = new ArrayList(); } toUnregister.add(cl); } } } if (toUnregister != null) { for (int i = 0; i < toUnregister.size(); i++) { unregisterClassLoader((ClassLoader)toUnregister.get(i)); } } } }
CtClass clazz = getCachedLocally(classname); if (clazz == null) { boolean isLocal = false; ClassLoader dcl = getClassLoader0(); if (dcl != null) { final int lastIndex = classname.lastIndexOf('$'); while (it.hasNext()) { ScopedClassPool pool = (ScopedClassPool)it.next(); if (pool.isUnloadedClassLoader()) { repository.unregisterClassLoader(pool .getClassLoader()); continue; clazz = pool.getCachedLocally(classname); if (clazz != null) { return clazz;
/** * Close the class pool */ public void close() { this.removeClassPath(classPath); classes.clear(); softcache.clear(); }
/** * Get the class loader * * @return the class loader */ public ClassLoader getClassLoader() { ClassLoader cl = getClassLoader0(); if (cl == null && !isBootstrapCl) { throw new IllegalStateException( "ClassLoader has been garbage collected"); } return cl; }
/** * Create a new ScopedClassPool. * * @param cl * the classloader * @param src * the original class pool * @param repository * the repository * @param isTemp * Whether this is a temporary pool used to resolve references */ protected ScopedClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, boolean isTemp) { super(src); this.repository = repository; this.classLoader = new WeakReference(cl); if (cl != null) { classPath = new LoaderClassPath(cl); this.insertClassPath(classPath); } childFirstLookup = true; if (!isTemp && cl == null) { isBootstrapCl = true; } }
CtClass clazz = getCachedLocally(classname); if (clazz == null) { boolean isLocal = false; ClassLoader dcl = getClassLoader0(); if (dcl != null) { final int lastIndex = classname.lastIndexOf('$'); synchronized (registeredCLs) { for (ScopedClassPool pool:registeredCLs.values()) { if (pool.isUnloadedClassLoader()) { repository.unregisterClassLoader(pool .getClassLoader()); continue; clazz = pool.getCachedLocally(classname); if (clazz != null) { return clazz;
/** * Convert a javassist class to a java class * * @param ct * the javassist class * @param loader * the loader * @throws CannotCompileException * for any error */ public Class<?> toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { // We need to pass up the classloader stored in this pool, as the // default implementation uses the Thread context cl. // In the case of JSP's in Tomcat, // org.apache.jasper.servlet.JasperLoader will be stored here, while // it's parent // org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread // context cl. The invocation class needs to // be generated in the JasperLoader classloader since in the case of // method invocations, the package name will be // the same as for the class generated from the jsp, i.e. // org.apache.jsp. For classes belonging to org.apache.jsp, // JasperLoader does NOT delegate to its parent if it cannot find them. lockInCache(ct); return super.toClass(ct, getClassLoader0(), domain); } }
/** * This method will check to see if a register classloader has been * undeployed (as in JBoss) */ @Override public void clearUnregisteredClassLoaders() { List<ClassLoader> toUnregister = null; synchronized (registeredCLs) { for (Map.Entry<ClassLoader,ScopedClassPool> reg:registeredCLs.entrySet()) { if (reg.getValue().isUnloadedClassLoader()) { ClassLoader cl = reg.getValue().getClassLoader(); if (cl != null) { if (toUnregister == null) toUnregister = new ArrayList<ClassLoader>(); toUnregister.add(cl); } registeredCLs.remove(reg.getKey()); } } if (toUnregister != null) for (ClassLoader cl:toUnregister) unregisterClassLoader(cl); } }
/** * Close the class pool */ public void close() { this.removeClassPath(classPath); classPath.close(); classes.clear(); softcache.clear(); }
/** * Get the class loader * * @return the class loader */ public ClassLoader getClassLoader() { ClassLoader cl = getClassLoader0(); if (cl == null && !isBootstrapCl) { throw new IllegalStateException( "ClassLoader has been garbage collected"); } return cl; }
/** * Create a new ScopedClassPool. * * @param cl * the classloader * @param src * the original class pool * @param repository * the repository * @param isTemp * Whether this is a temporary pool used to resolve references */ protected ScopedClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, boolean isTemp) { super(src); this.repository = repository; this.classLoader = new WeakReference<ClassLoader>(cl); if (cl != null) { classPath = new LoaderClassPath(cl); this.insertClassPath(classPath); } childFirstLookup = true; if (!isTemp && cl == null) { isBootstrapCl = true; } }
CtClass clazz = getCachedLocally(classname); if (clazz == null) { boolean isLocal = false; ClassLoader dcl = getClassLoader0(); if (dcl != null) { final int lastIndex = classname.lastIndexOf('$'); while (it.hasNext()) { ScopedClassPool pool = (ScopedClassPool)it.next(); if (pool.isUnloadedClassLoader()) { repository.unregisterClassLoader(pool .getClassLoader()); continue; clazz = pool.getCachedLocally(classname); if (clazz != null) { return clazz;
/** * Convert a javassist class to a java class * * @param ct * the javassist class * @param loader * the loader * @throws CannotCompileException * for any error */ public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { // We need to pass up the classloader stored in this pool, as the // default implementation uses the Thread context cl. // In the case of JSP's in Tomcat, // org.apache.jasper.servlet.JasperLoader will be stored here, while // it's parent // org.jboss.web.tomcat.tc5.WebCtxLoader$ENCLoader is used as the Thread // context cl. The invocation class needs to // be generated in the JasperLoader classloader since in the case of // method invocations, the package name will be // the same as for the class generated from the jsp, i.e. // org.apache.jsp. For classes belonging to org.apache.jsp, // JasperLoader does NOT delegate to its parent if it cannot find them. lockInCache(ct); return super.toClass(ct, getClassLoader0(), domain); } }
/** * This method will check to see if a register classloader has been * undeployed (as in JBoss) */ public void clearUnregisteredClassLoaders() { ArrayList toUnregister = null; synchronized (registeredCLs) { Iterator it = registeredCLs.values().iterator(); while (it.hasNext()) { ScopedClassPool pool = (ScopedClassPool)it.next(); if (pool.isUnloadedClassLoader()) { it.remove(); ClassLoader cl = pool.getClassLoader(); if (cl != null) { if (toUnregister == null) { toUnregister = new ArrayList(); } toUnregister.add(cl); } } } if (toUnregister != null) { for (int i = 0; i < toUnregister.size(); i++) { unregisterClassLoader((ClassLoader)toUnregister.get(i)); } } } }
/** * Makes an instance. */ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository) { return new ScopedClassPool(cl, src, repository, false); }
@Override public void unregisterClassLoader(ClassLoader cl) { synchronized (registeredCLs) { ScopedClassPool pool = registeredCLs.remove(cl); if (pool != null) pool.close(); } }