Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.Factory


        assertThat(actual).hasSize(2);

        CompleteBean found1 = actual.get(0);
        CompleteBean found2 = actual.get(1);

        Factory factory1 = (Factory) found1;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor1 = (ProxyInterceptor<CompleteBean>) factory1.getCallback(0);

        CompleteBean target1 = (CompleteBean) interceptor1.getTarget();

        assertThat(target1.getAge()).isNull();
        assertThat(target1.getFollowers()).isNull();
        assertThat(target1.getLabel()).isNull();
        assertThat(target1.getPreferences()).isNull();
        assertThat(target1.getWelcomeTweet()).isNull();

        Factory factory2 = (Factory) found1;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor2 = (ProxyInterceptor<CompleteBean>) factory2.getCallback(0);

        CompleteBean target2 = (CompleteBean) interceptor2.getTarget();

        assertThat(target2.getAge()).isNull();
        assertThat(target2.getFollowers()).isNull();
View Full Code Here


        Object proxy = proxifier.buildProxyWithAllFieldsLoadedExceptCounters(entity, context);

        assertThat(proxy).isNotNull();
        assertThat(proxy).isInstanceOf(Factory.class);
        Factory factory = (Factory) proxy;

        assertThat(factory.getCallbacks()).hasSize(1);
        assertThat(factory.getCallback(0)).isInstanceOf(ProxyInterceptor.class);

        verify(pm.forValues()).getValueFromField(entity);
        verify(pm.forValues()).setValueToField(realProxy, value);
        verify(counterMeta.forValues()).setValueToField(entity,null);
    }
View Full Code Here

    @Test
    public void should_unproxy_entity() throws Exception {
        when(interceptor.getTarget()).thenReturn(realProxy);

        Factory actual = proxifier.removeProxy(realProxy);

        assertThat(actual).isSameAs(realProxy);
    }
View Full Code Here

        assertThat(list1).hasSize(1);

        CompleteBean foundPaul = list1.get(0);

        Factory factory1 = (Factory) foundPaul;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor1 = (ProxyInterceptor<CompleteBean>) factory1.getCallback(0);

        CompleteBean realPaul = (CompleteBean) interceptor1.getTarget();

        assertThat(realPaul.getLabel()).isNull();
        assertThat(realPaul.getWelcomeTweet()).isNull();

        assertThat(realPaul.getName()).isEqualTo(paul.getName());
        assertThat(realPaul.getAge()).isEqualTo(paul.getAge());
        assertThat(realPaul.getFriends()).containsAll(paul.getFriends());
        assertThat(realPaul.getFollowers()).containsAll(paul.getFollowers());
        assertThat(realPaul.getPreferences().get(1)).isEqualTo("FR");
        assertThat(realPaul.getPreferences().get(2)).isEqualTo("Paris");
        assertThat(realPaul.getPreferences().get(3)).isEqualTo("75014");

        Factory factory2 = (Factory) foundJohn;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor2 = (ProxyInterceptor<CompleteBean>) factory2.getCallback(0);

        CompleteBean realJohn = (CompleteBean) interceptor2.getTarget();

        assertThat(realJohn.getLabel()).isNull();
        assertThat(realJohn.getWelcomeTweet()).isNull();
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

            }
        }


        if (factories.containsKey(configClass)) {
            Factory f = factories.get(configClass);
            return configClass.cast(f.newInstance(callbacks.toArray(new Callback[callbacks.size()])));
        }
        else {
            Enhancer e = new Enhancer();
            e.setSuperclass(configClass);
            e.setCallbackFilter(new ConfigMagicCallbackFilter(slots));
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

                targetInstance = fieldInstance;
            }
            proxiedObject = getJDKProxy(interceptorClass, timeInMillies, fieldType, targetInstance);
        } else {
            if (fieldInstance instanceof Factory) {
                Factory cglibFactory = (Factory) fieldInstance;
                InternalInterceptor internalInterceptor = (InternalInterceptor) cglibFactory.getCallback(0);
                targetInstance = internalInterceptor.getTargetInstance();
            } else {
                targetInstance = fieldInstance;
            }
            proxiedObject = getCGLIBProxy(interceptorClass, timeInMillies, fieldType, targetInstance);
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.