protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class superClass = loader.loadClass(name); int length = readInt(); Class[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } else { return super.readClassDescriptor(); } }
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class<?> superClass = loader.loadClass(name); int length = readInt(); Class<?>[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class<?> proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } return super.readClassDescriptor(); }
@Override public Class<?> load(final Class<?> frameClass) throws Exception { final Class<?> handlerClass = getHandlerClass(frameClass); ProxyFactory proxyFactory = new ProxyFactory() { protected ClassLoader getClassLoader() { return new URLClassLoader(new URL[0], handlerClass.getClassLoader()); } }; proxyFactory.setUseCache(false); proxyFactory.setSuperclass(handlerClass); return proxyFactory.createClass(); } });
@Override public Class<?> load(final Class<?> frameClass) throws Exception { final Class<?> handlerClass = getHandlerClass(frameClass); ProxyFactory proxyFactory = new ProxyFactory() { protected ClassLoader getClassLoader() { return new URLClassLoader(new URL[0], handlerClass.getClassLoader()); } }; proxyFactory.setUseCache(false); proxyFactory.setSuperclass(handlerClass); return proxyFactory.createClass(); } });
private <T> ProxyFactory createProxyFactoryFor(final Class<T> toProxyClass) { final ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setSuperclass(toProxyClass); final Class[] types = ArrayExtensions.combine( toProxyClass.getInterfaces(), new Class<?>[] { JavassistEnhanced.class, WrappingObject.class }); proxyFactory.setInterfaces(types); proxyFactory.setFilter(new MethodFilter() { @Override public boolean isHandled(final Method m) { // ignore finalize() return !m.getName().equals("finalize") || m.isBridge(); } }); // this is the default, I believe // calling it here only because I know that it will throw an exception if the code were // in the future changed such that caching is invalid // (ie fail fast if future change could introduce a bug) proxyFactory.setUseCache(true); return proxyFactory; }
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class superClass = loader.loadClass(name); int length = readInt(); Class[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } else { return super.readClassDescriptor(); } }
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class superClass = loader.loadClass(name); int length = readInt(); Class[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } else { return super.readClassDescriptor(); } }
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class superClass = loader.loadClass(name); int length = readInt(); Class[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } else { return super.readClassDescriptor(); } }
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { boolean isProxy = readBoolean(); if (isProxy) { String name = (String)readObject(); Class superClass = loader.loadClass(name); int length = readInt(); Class[] interfaces = new Class[length]; for (int i = 0; i < length; i++) { name = (String)readObject(); interfaces[i] = loader.loadClass(name); } length = readInt(); byte[] signature = new byte[length]; read(signature); ProxyFactory factory = new ProxyFactory(); // we must always use the cache and never use writeReplace when using // ProxyObjectOutputStream and ProxyObjectInputStream factory.setUseCache(true); factory.setUseWriteReplace(false); factory.setSuperclass(superClass); factory.setInterfaces(interfaces); Class proxyClass = factory.createClass(signature); return ObjectStreamClass.lookup(proxyClass); } else { return super.readClassDescriptor(); } }