Package javassist.util.proxy

Examples of javassist.util.proxy.MethodHandler


      public boolean isHandled(Method m) {
        String name = m.getName();
        return "getConfiguration".equals(name) || "getCounter".equals(name) || "progress".equals(name);
      }
    });
    MethodHandler handler = new MethodHandler() {
      @Override
      public Object invoke(Object arg0, Method m, Method arg2, Object[] args) throws Throwable {
        String name = m.getName();
        if ("getConfiguration".equals(name)) {
          return conf;
View Full Code Here



   public <T> T createSubclassingProxy(ClassMetadata<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments)
   {
      T instance = createAdvisedSubclassInstance(proxifiedClass, constructorTypes, constructorArguments);
      MethodHandler interceptorMethodHandler = createSubclassingMethodHandler(instance, proxifiedClass);
      ((ProxyObject)instance).setHandler(new CompositeHandler(Arrays.asList(new MethodHandler[]{interceptorMethodHandler})));
      return instance;
   }
View Full Code Here

      ProxyFactory factory = new ProxyFactory();

      factory.setInterfaces(new Class[] { c });

      MethodHandler handler = handler(c, lambda, environment);

      Class<?> interfaceClass = factory.createClass();

      Object object = interfaceClass.newInstance();
View Full Code Here

      ProxyFactory factory = new ProxyFactory();

      factory.setSuperclass(c);

      MethodHandler handler = handler(c, lambda, environment);

      Class<?> interfaceClass = factory.createClass();

      Object object = interfaceClass.newInstance();
View Full Code Here

    }
  }

  private static MethodHandler handler(final Class<?> c, final LLambda lambda, final Environment environment) {

    return new MethodHandler() {

      @Override
      public Object invoke(Object arg0, Method method, Method arg2, Object[] args) throws Throwable {

        String name = method.getName();
View Full Code Here

   }


   public <T> T createProxyFromInstance(final Object target, Class<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments, InterceptorMetadata interceptorClassMetadata)
   {
      MethodHandler interceptorMethodHandler = createMethodHandler(target, proxifiedClass, interceptorClassMetadata);
      return createProxyInstance(InterceptionUtils.createProxyClassWithHandler(proxifiedClass, interceptorMethodHandler), interceptorMethodHandler);
   }
View Full Code Here

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(interfacesToProxy);

    Object instance;
    try {
      instance = proxyFactory.create(new Class[0], new Object[0], new MethodHandler() {
        @Override
        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
          return proceed.invoke(self, args);
        }
      });
View Full Code Here

    }
   
    private <T> void setHandler(Object proxyInstance, final MethodInvocation<? super T> handler) {
        ProxyObject proxyObject = (ProxyObject) proxyInstance;

        proxyObject.setHandler(new MethodHandler() {
            public Object invoke(final Object self, final Method thisMethod, final Method proceed, Object[] args)
                throws Throwable {

                return handler.intercept((T) self, thisMethod, args, new SuperMethod() {
                    public Object invoke(Object proxy, Object[] args) {
View Full Code Here

            public boolean isHandled(Method m) {
                return isLazyAccessor(m);
            }
        });
        proxyClass = proxyFactory.createClass();
        proxyMethodHandler = new MethodHandler() {
            public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
                log.debug("lazy loading: " + m.getName());
                persistenceFactory.loadLazyPropertyIfNecessary(ClassMetadata.this, self, proceed, m, args);
                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

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.