Package javassist.util.proxy

Examples of javassist.util.proxy.MethodHandler


        f.setHandler(interceptor);
        f.setFilter(finalizeRemover);
        Class c = f.createClass();
        Object obj = (Object)c.newInstance();
        System.out.println("setter1: " + obj.toString());
        ((ProxyObject)obj).setHandler(new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed,
                    Object[] args) throws Exception {
                System.out.print("intercept: " + m);
                return "OK";
            }
View Full Code Here


    public static boolean testInitFlag;

    public void testInit() throws Exception {
        ProxyFactory f = new ProxyFactory();
        f.setSuperclass(TargetInit.class);
        MethodHandler handler = new MethodHandler() {
            public Object invoke(Object self, Method m,
                    Method proceed, Object[] args) throws Exception {
                System.out.println("testInit " + testInitFlag);
                return proceed.invoke(self, args);
            }
View Full Code Here

    public void testJIRA127() throws Exception {
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.writeDirectory = ".";
        proxyFactory.setInterfaces(new Class[]{ Target127.Sub.class });
        Target127.Sub proxy = (Target127.Sub)proxyFactory.create(new Class[0], new Object[0], new MethodHandler() {
            public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
                return null;
            }
        });
        ((Target127.Super)proxy).item();    // proxyFactory must generate a bridge method.
View Full Code Here

            public boolean isHandled(Method m) {
                return !m.getName().equals("finalize");
            }
        };

        handler = new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed,
                                 Object[] args) throws Throwable {
                System.out.println("calling: " + m.getName());
                return proceed.invoke(self, args)// execute the original method.
            }
View Full Code Here

                // 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
                // method.
View Full Code Here

                // 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
                // method.
View Full Code Here

            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

            ProxyFactory factory = new ProxyFactory();
            Class javaTargetClass = classPool.toClass(ctTargetClass);
            Class javaHandlerClass = classPool.toClass(ctHandlerClass);
            Class javaFilterClass = classPool.toClass(ctFilterClass);

            MethodHandler handler= (MethodHandler)javaHandlerClass.newInstance();
            MethodFilter filter = (MethodFilter)javaFilterClass.newInstance();

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

        myHandler.setX(4711);

        MyCls myCls = (MyCls) proxyClass.newInstance();
        ((ProxyObject) myCls).setHandler(myHandler);

        MethodHandler h2 = ((ProxyObject) myCls).getHandler();
        assertNotNull(h2);
        assertTrue(h2 instanceof MyMethodHandler);
    }
View Full Code Here

        ByteArrayInputStream bais = new ByteArrayInputStream(ba);
        ObjectInputStream ois = new ObjectInputStream(bais);
        MyCls myCls2 =  (MyCls) ois.readObject();

        MethodHandler h2 = ((ProxyObject) myCls2).getHandler();
        assertNotNull(h2);
        assertTrue(h2 instanceof MyMethodHandler);
    }
View Full Code Here

TOP

Related Classes of javassist.util.proxy.MethodHandler

Copyright © 2018 www.massapicom. 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.