@Override protected IClass findIClass(String descriptor) throws ClassNotFoundException { Class clazz; try { // // See also [ 931385 ] Janino 2.0 throwing exception on arrays of java.io.File: // // "ClassLoader.loadClass()" and "Class.forName()" should be identical, // but "ClassLoader.loadClass("[Ljava.lang.Object;")" throws a // ClassNotFoundException under JDK 1.5.0 beta. // Unclear whether this a beta version bug and SUN will fix this in the final // release, but "Class.forName()" seems to work fine in all cases, so we // use that. // // clazz = this.classLoader.loadClass(Descriptor.toClassName(descriptor)); clazz = Class.forName(Descriptor.toClassName(descriptor), false, this.classLoader); } catch (ClassNotFoundException e) { if (e.getException() == null) { return null; } else { throw e; } } if (ClassLoaderIClassLoader.DEBUG) System.out.println("clazz = " + clazz); IClass result = new ReflectionIClass(clazz, this); this.defineIClass(result); return result; }
protected void manipulate(String classname, CtClass toManipulate, int extRefCount) throws NotFoundException, CannotCompileException { // LOG.info(extRefCount+" Starting bytecode instrumentation... "); // replace all usages of constructors of the external classes found by a factory method of its // proxy class (that may return a proxy instance instead). extRefCount = 0; Iterator extRefs = class2cop.entrySet().iterator(); while (extRefs.hasNext()) { java.util.Map.Entry entry = (java.util.Map.Entry) extRefs.next(); UpgradeableComponentResource extCop = (UpgradeableComponentResource) entry.getValue(); String extRef = (String) entry.getKey(); LOG.info( extRefCount + " ... hiding " + extRef + " in " + extCop.getCodeBase() + " from " + classname); String proxyName = null; try { ClassPool externalPool = getPool(extCop); // create and load a Proxy for external class extRefClass Class extRefClass = extCop.getClassLoader().loadClass(extRef); ProxyLoader proxyLoader = extCop.getProxyLoader(); /// ProxyFactory.setNamingConventionOfWrapper(ProxyFactory.proxyJarPrefix, true); Class proxyClass = TransparentProxyFactory.getProxyClass( proxyLoader, extRefClass); // creates the proxy class for the external class proxyName = proxyClass.getName(); // LOG.info(extRefCount+" Created proxy class "+proxyName+" for externally referenced class // "+extRef); instrument(toManipulate, extRef, externalPool, proxyName, proxyLoader); } catch (ClassNotFoundException e) { LOG.error(extRefCount + " onWrite: Caught ClassNotFoundException " + e.getException()); } catch (WrappingException w) { LOG.error(extRef, w); } finally { extRefCount++; } } }