Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.Factory


    public static ConstructorArgs getCurrentConstructorArgs() {
        return currentConstructorArgs.get();
    }

    public static MockMethodInterceptor getInterceptor(Object mock) {
        Factory factory = (Factory) mock;
        return (MockMethodInterceptor) factory.getCallback(0);
    }
View Full Code Here


    public static ConstructorArgs getCurrentConstructorArgs() {
        return currentConstructorArgs.get();
    }

    public static MockMethodInterceptor getInterceptor(Object mock) {
        Factory factory = (Factory) mock;
        return (MockMethodInterceptor) factory.getCallback(0);
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public <B, R extends ServiceReference<B>> R cast(B target) throws IllegalArgumentException {
        if (isProxyClass(target.getClass())) {
            Factory factory = (Factory)target;
            Callback[] callbacks = factory.getCallbacks();
            if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
                throw new IllegalArgumentException("The object is not a known proxy.");
            }
            CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
            return (R)interceptor.invocationHandler.getCallableReference();
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
        if (isProxyClass(target.getClass())) {
            Factory factory = (Factory)target;
            Callback[] callbacks = factory.getCallbacks();
            if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
                throw new IllegalArgumentException("The object is not a known proxy.");
            }
            CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
            return (R)interceptor.invocationHandler.getCallableReference();
View Full Code Here

            throw new IllegalArgumentException("could not imposterise " + mockedType, e);
        }
    }
   
    private Object createProxy(Class<?> proxyClass, final Invokable mockObject) {
        Factory proxy = (Factory)objenesis.newInstance(proxyClass);
        proxy.setCallbacks(new Callback[] {
            new InvocationHandler() {
                public Object invoke(Object receiver, Method method, Object[] args) throws Throwable {
                    return mockObject.invoke(new Invocation(receiver, method, args));
                }
            },
View Full Code Here

        });
        enhancer.setInterfaces(new Class[]{Runnable.class});
        enhancer.setUseFactory(true);
        final Runnable orig = (Runnable)enhancer.create();
        final String xml = xstream.toXML(orig);
        final Factory deserialized = (Factory)xstream.fromXML(xml);
        assertTrue("Not a Runnable anymore", deserialized instanceof Runnable);
        Callback[] callbacks = deserialized.getCallbacks();
        assertEquals(4, callbacks.length);
        assertTrue(callbacks[0] instanceof DelegatingInterceptor);
        assertTrue(callbacks[1] instanceof DelegatingHandler);
        assertTrue(callbacks[2] instanceof DelegatingDispatcher);
        assertTrue(callbacks[3] instanceof NoOp);
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
        if (isProxyClass(target.getClass())) {
            Factory factory = (Factory)target;
            Callback[] callbacks = factory.getCallbacks();
            if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
                throw new IllegalArgumentException("The object is not a known proxy.");
            }
            CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
            return (R)interceptor.invocationHandler.getCallableReference();
View Full Code Here

  public static <T> Selector<T> using(T selector) {
    if (!isEnhanced(selector)) {
      throw new RuntimeException("The specified object is not a selector.");
    }
    // CGLib applies the Factory interface to all enhanced proxies
    Factory factory = as(selector, Factory.class);
    SelectorMethodInterceptor interceptor = as(factory.getCallback(0), SelectorMethodInterceptor.class);
    interceptor.reset();
    return new Selector<T>(interceptor);
  }
View Full Code Here

    return enhancedInstance;
  }

  protected final static <T> boolean isEnhanced(T selector) {
    Factory factory = as(selector, Factory.class);
    if (factory != null) {
      Callback callback = factory.getCallback(0);
      SelectorMethodInterceptor selectorInterceptor = as(callback, SelectorMethodInterceptor.class);
      return selectorInterceptor != null;
    }
    return false;
  }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
        if (isProxyClass(target.getClass())) {
            Factory factory = (Factory)target;
            Callback[] callbacks = factory.getCallbacks();
            if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
                throw new IllegalArgumentException("The object is not a known proxy.");
            }
            CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
            return (R)interceptor.invocationHandler.getCallableReference();
View Full Code Here

TOP

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

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.