Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.MethodInterceptor


            final long pos = buffer.getBitPos();
            ClassLoader loader = this.getClass().getClassLoader();
            Enhancer enhancer = new Enhancer();
            enhancer.setClassLoader(loader);
            enhancer.setSuperclass(type);
            enhancer.setCallback(new MethodInterceptor() {

                private Object actual;

                public Object intercept(Object target, Method method,
                                        Object[] args, MethodProxy proxy) throws Throwable {
View Full Code Here


      enhancer.setCallbackTypes(new Class[] {MethodInterceptor.class, NoOp.class});
      return enhancer;
  }

  protected MethodInterceptor cglibMethodInterceptor(final MethodInvocation handler) {
    return new MethodInterceptor() {
          public Object intercept(Object proxy, Method method, Object[] args, final MethodProxy methodProxy) {
              return handler.intercept(proxy, method, args, new SuperMethod() {
                  public Object invoke(Object proxy, Object[] args) {
                      try {
                          return methodProxy.invokeSuper(proxy, args);
View Full Code Here

   * @param type
   *            the type to call
   */
  @SuppressWarnings("unchecked")
  public static <T> T build(final Class<T> type) {
    final MethodInterceptor interceptor = new ClassMethodCallInterceptor<T>();
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(type);
    enhancer.setCallback(interceptor);
    final T proxy = (T) enhancer.create();
    return proxy;
View Full Code Here

   * @param instance
   *            the instance to call
   */
  @SuppressWarnings("unchecked")
  public static <T> T build(final T instance) {
    final MethodInterceptor interceptor = new ObjectMethodCallInterceptor<T>(instance);
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(instance.getClass());
    enhancer.setCallback(interceptor);
    final T proxy = (T) enhancer.create();
    return proxy;
View Full Code Here

     * @param type the type of the generated proxy
     * @param interceptor the interceptor for intercepting methods executed on generated proxy
     * @return proxy for executing methods which shoyld be intercepted by given interceptor
     */
    public <T> T interceptInvocation(Class<T> type, final Interceptor interceptor) {
        return (T) ClassImposterizer.INSTANCE.imposterise(new MethodInterceptor() {
            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                registerMethodInterceptor(method, interceptor);
                return null;
            }
View Full Code Here

    private static boolean isAboutToDelegateToWebElement(Class<?> clazz) {
        return Arrays.asList(clazz.getInterfaces()).contains(WebElement.class);
    }

    private static <T> T createProxyDelegatingToRoot(final WebElement root, Class<T> clazz) {
        return ClassImposterizer.INSTANCE.imposterise(new MethodInterceptor() {

            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                List<Method> webElementMethods = Arrays.asList(WebElement.class.getMethods());
                if (webElementMethods.contains(method)) {
View Full Code Here

      enhancer.setCallbackTypes(new Class[] {MethodInterceptor.class, NoOp.class});
      return enhancer;
  }

  protected MethodInterceptor cglibMethodInterceptor(final MethodInvocation handler) {
    return new MethodInterceptor() {
          public Object intercept(Object proxy, Method method, Object[] args, final MethodProxy methodProxy) {
              return handler.intercept(proxy, method, args, new SuperMethod() {
                  public Object invoke(Object proxy, Object[] args) {
                      try {
                          return methodProxy.invokeSuper(proxy, args);
View Full Code Here

    }

    public static <T> T recordDefaults(Class<T> type)
    {
        final T instance = newDefaultInstance(type);
        @SuppressWarnings("unchecked") T proxy = (T) Enhancer.create(type, new Class[]{$$RecordingConfigProxy.class}, new MethodInterceptor()
        {
            private final ConcurrentMap<Method, Object> invokedMethods = new MapMaker().makeMap();

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

            }
        });

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(test.getClass());
        enhancer.setCallback(new MethodInterceptor() {

            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                return null;
            }
        });
View Full Code Here

            generator.setSuperclass(Object.class);
            generator.setInterfaces(new Class<?>[] { intfs });

            generator.setCallbacks(new Callback[] {
                    // default callback
                    new MethodInterceptor() {
                        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
                                throws Throwable {
                            return proxy.invokeSuper(obj, args);
                        }
                    },

                    // toString callback
                    new MethodInterceptor() {
                        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
                                throws Throwable {
                            MapBuilder mb = new MapBuilder().setPrintCount(true).setSortKeys(true);

                            for (Map.Entry<Method, FastMethod> entry : methodMappings.entrySet()) {
                                mb.append(
                                        entry.getKey().getName(),
                                        getSimpleMethodSignature(entry.getValue().getJavaMethod(), false, true, true, false));
                            }

                            return new ToStringBuilder().append(intfs.getName()).append(mb).toString();
                        }
                    },

                    // proxied callback
                    new MethodInterceptor() {
                        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
                                throws Throwable {
                            FastMethod realMethod = assertNotNull(methodMappings.get(method), "unknown method: %s", method);
                            return realMethod.invoke(null, args);
                        }
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.