Package javassist.util.proxy

Examples of javassist.util.proxy.ProxyFactory.createClass()


        TestClass proxy1 = (TestClass)proxyClass1.newInstance();
        ((ProxyObject) proxy1).setHandler(handler);
        proxy1.testMethod();
        assertTrue(proxy1.isTestCalled());

        Class proxyClass2 =  factory.createClass();
        System.out.println("created second class " + proxyClass2.getName());
        TestClass proxy2 = (TestClass)proxyClass2.newInstance();
        ((ProxyObject) proxy2).setHandler(handler);
        proxy2.testMethod();
        assertTrue(proxy2.isTestCalled());
View Full Code Here


            public boolean isHandled(Method m) {
                // ignore finalize()
                return !m.getName().equals("finalize");
            }
        });
        Class c = f.createClass();
        MethodHandler mi = new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed,
                    Object[] args) throws Throwable {
                System.out.println("Name: " + m.getName());
                return proceed.invoke(self, args) + "!"; // execute the original
View Full Code Here

            public boolean isHandled(Method m) {
                // ignore finalize()
                return !m.getName().equals("finalize");
            }
        });
        Class c = f.createClass();
        MethodHandler mi = new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed,
                    Object[] args) throws Throwable {
                System.out.println("Name: " + m.getName());
                return proceed.invoke(self, args) + "!"; // execute the original
View Full Code Here

        f.setFilter(new MethodFilter() {
            public boolean isHandled(Method m) {
                return m.getName().startsWith("f");
            }
        });
        Class c = f.createClass();
        MethodHandler mi = new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed,
                                 Object[] args) throws Throwable {
                testResult += args[0].toString();
                return proceed.invoke(self, args)// execute the original method.
View Full Code Here

                return new javassist.Loader();
            }
        };
        ProxyFactory pf = new ProxyFactory();
        pf.setSuperclass(ReadWriteData.class);
        Object data = pf.createClass().newInstance();
        // Object data = new ReadWriteData();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
        oos.writeObject(data);
        oos.close();
        ProxyFactory.classLoaderProvider = cp;
View Full Code Here

    }

    public void testWriteReplace() throws Exception {
        ProxyFactory pf = new ProxyFactory();
        pf.setSuperclass(WriteReplace.class);
        Object data = pf.createClass().newInstance();
        assertEquals(data, ((WriteReplace)data).writeReplace());

        ProxyFactory pf2 = new ProxyFactory();
        pf2.setSuperclass(WriteReplace2.class);
        Object data2 = pf2.createClass().newInstance();
View Full Code Here

        Object data = pf.createClass().newInstance();
        assertEquals(data, ((WriteReplace)data).writeReplace());

        ProxyFactory pf2 = new ProxyFactory();
        pf2.setSuperclass(WriteReplace2.class);
        Object data2 = pf2.createClass().newInstance();
        Method meth = data2.getClass().getDeclaredMethod("writeReplace", new Class[0]);
        assertEquals("javassist.util.proxy.SerializedProxy",
                    meth.invoke(data2, new Object[0]).getClass().getName());
    }
View Full Code Here

            // ok, now create a factory and a proxy class and proxy from that factory
            factory.setFilter(filter);
            factory.setSuperclass(javaTargetClass);
            // factory.setSuperclass(Object.class);

            Class proxyClass = factory.createClass();
            Object target = proxyClass.newInstance();
            ((ProxyObject)target).setHandler(handler);
        } catch (Exception e) {
            e.printStackTrace();
            fail("cannot create proxy " + e);
View Full Code Here

public class ProxyFactoryTest extends TestCase {
    public void testMethodHandlers() throws Exception {
        ProxyFactory fact = new ProxyFactory();
        fact.setSuperclass(MyCls.class);

        Class proxyClass = fact.createClass();

        MyMethodHandler myHandler = new MyMethodHandler();
        myHandler.setX(4711);

        MyCls myCls = (MyCls) proxyClass.newInstance();
View Full Code Here

    public void testSerialize() throws Exception {
        ProxyFactory fact = new ProxyFactory();
        fact.setSuperclass(MyCls.class);

        Class proxyClass = fact.createClass();

        MyMethodHandler myHandler = new MyMethodHandler();
        myHandler.setX(4711);

        MyCls myCls = (MyCls) proxyClass.newInstance();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.