Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.MethodInterceptor


    @Override
    @SuppressWarnings("unchecked")
    public T createProxy(final Class<T> toProxyClass, final InvocationHandler handler) {

        final MethodInterceptor interceptor = new InvocationHandlerMethodInterceptor(handler);

        // Create the proxy
        final Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(toProxyClass);
        enhancer.setInterfaces(new Class[] { WrapperObject.class });
        enhancer.setCallbackType(interceptor.getClass());

        final Class enhancedClass = enhancer.createClass();

        Enhancer.registerCallbacks(enhancedClass, new Callback[] { interceptor });
View Full Code Here


        new Class<?>[]{optionClass}, handler);
  }

  private Object createCglibHandler(Class<?> optionClass,
                                    final Map<String, String> concreteOptions) {
    MethodInterceptor interceptor = new MethodInterceptor() {
      @Inject
      OptionTypeConverter converter;

      @Override
      public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy)
View Full Code Here

        createCallback();
    }

    @Override
    protected void createCallback() {
        this.callback = new MethodInterceptor() {

            @Override
            public Object intercept(final Object proxied, final Method proxiedMethod, final Object[] args, final MethodProxy proxyMethod) throws Throwable {

                final boolean ignore = proxiedMethod.getDeclaringClass().equals(Object.class);
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public T createProxy(final Class<T> toProxyClass, final InvocationHandler handler) {

        final MethodInterceptor interceptor = new InvocationHandlerMethodInterceptor(handler);

        // Create the proxy
        final Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(toProxyClass);
        enhancer.setInterfaces(new Class[] { WrapperObject.class });
        enhancer.setCallbackType(interceptor.getClass());

        final Class<?> enhancedClass = enhancer.createClass();

        Enhancer.registerCallbacks(enhancedClass, new Callback[] { interceptor });
View Full Code Here

    }

    private Remote createRmiService(final Interface serviceInterface) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(UnicastRemoteObject.class);
        enhancer.setCallback(new MethodInterceptor() {
            public Object intercept(Object arg0, Method method, Object[] args, MethodProxy arg3) throws Throwable {
                try {
                    return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()), args);
                } catch (InvocationTargetException e) {
                    final Throwable cause = e.getCause();
View Full Code Here

        } else {
            enhancer.setSuperclass(cl);
            enhancer.setInterfaces(new Class[] { ManagedObject.class });
        }
        // creates one handler per proxy
        MethodInterceptor handler = new PropertyAccessInvocationHandler(path, this, pathFactory, typeSystem);
        enhancer.setCallback(handler);
        return (A) enhancer.create();
    }
View Full Code Here

    public void testSimpleProxied() throws Exception
    {
        Enhancer enh = new Enhancer();
        enh.setInterfaces(new Class[] { BeanInterface.class });
        enh.setCallback(new MethodInterceptor() {
                public Object intercept(Object obj, Method method,
                                        Object[] args, MethodProxy proxy)
                    throws Throwable
                {
                    if ("getX".equals(method.getName ())) {
View Full Code Here

    public void destroyProxy(Object proxy) {
        if (proxy == null) {
            return;
        }

        MethodInterceptor methodInterceptor = (MethodInterceptor) interceptors.remove(proxy);
        if (methodInterceptor != null) {
            doDestroy(methodInterceptor);
        }
    }
View Full Code Here

    public boolean isProxy(Object proxy) {
        return interceptors.containsKey(proxy);
    }

    public ObjectName getProxyTarget(Object proxy) {
        MethodInterceptor methodInterceptor = (MethodInterceptor) interceptors.get(proxy);
        if (methodInterceptor == null) {
            return null;
        }
        return getObjectName(methodInterceptor);
    }
View Full Code Here

      // 基本类型
      if (obj instanceof String || obj instanceof Number
          || obj instanceof Boolean || obj instanceof Character) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(HashMap.class);
        enhancer.setCallback(new MethodInterceptor() {

          private final String prefix = shardId.getPrefix();
          private final String suffix = shardId.getSuffix();
          private final Object parameter = obj;
View Full Code Here

TOP

Related Classes of net.sf.cglib.proxy.MethodInterceptor

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.