Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.Factory


    }

    @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


        return IndirectionHandlerCGLIB.class;
    }

    public OJBProxy createProxy(Class proxyClass, IndirectionHandler handler) throws Exception {

        Factory factory = (Factory)proxyFactories.get(proxyClass);
        Object result = null;
        if (factory == null) {
            Class[] interfaces;
            if (proxyClass.isInterface()) {
                interfaces = new Class[] { proxyClass, OJBProxy.class };
            } else {
                interfaces = new Class[] { OJBProxy.class };
            }

            result = (Factory)Enhancer.create(proxyClass, interfaces, (Callback)handler);
            proxyFactories.put(proxyClass, result);
        } else {
            result = factory.newInstance((Callback)handler);
        }
        return (OJBProxy)result;
    }
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

            attsToPut.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, ai.getDiscriminatorValue(), true));
        }

        LazyInterceptor interceptor = null;
        if (o instanceof Factory) {
            Factory factory = (Factory) o;
            /*for (Callback callback2 : factory.getCallbacks()) {
                if(logger.isLoggable(Level.FINER)) logger.finer("callback=" + callback2);
                if (callback2 instanceof LazyInterceptor) {
                    interceptor = (LazyInterceptor) callback2;
                }
            }*/
            interceptor = (LazyInterceptor) factory.getCallback(0);
        }

        Collection<Method> getters = ai.getGetters();
        for (Method getter : getters) {
          Object ob;
View Full Code Here

        return lastOpStats;
    }

    public static <T> void replaceEntityManager(T newInstance, EntityManagerSimpleJPA em) {
        if (newInstance instanceof Factory) {
            Factory factory = (Factory) newInstance;
            LazyInterceptor interceptor = (LazyInterceptor) factory.getCallback(0);
            interceptor.setEntityManager(em);
        }
    }
View Full Code Here

            System.out.println("interface=" + aClass);
        }
        for (Method method : bean.getClass().getDeclaredMethods()) {
            System.out.println("method=" + method);
        }
        Factory factory = (Factory) bean;
        for (Callback callback : factory.getCallbacks()) {
            System.out.println("callback=" + callback);
        }
    }
View Full Code Here

        final Class enhancedClass = enhancer.createClass();

        Enhancer.registerCallbacks(enhancedClass, new Callback[] { interceptor });

        Factory factory;
        try {
            factory = (Factory) ClassInstantiatorFactoryCE.getInstantiator().newInstance(enhancedClass);
        } catch (final InstantiationException e) {
            // ///CLOVER:OFF
            throw new RuntimeException("Fail to instantiate mock for " + toProxyClass + " on " + ClassInstantiatorFactoryCE.getJVM() + " JVM");
View Full Code Here

        @Override
        protected void filterConstructors(Class sc, List constructors) { }
    }

    private Object createProxy(Class<?> proxyClass, Callback callback) {
        Factory proxy = (Factory) objenesis.newInstance(proxyClass);
        proxy.setCallbacks(new Callback[] {callback, NoOp.INSTANCE});
        return proxy;
    }
View Full Code Here

    @Override
    @SuppressWarnings("unchecked") @DB(txn=false)
    public <J> GenericSearchBuilder<T, J> createSearchBuilder(Class<J> resultType) {
        final T entity = (T)_searchEnhancer.create();
        final Factory factory = (Factory)entity;
        GenericSearchBuilder<T, J> builder = new GenericSearchBuilder<T, J>(entity, resultType, _allAttributes);
        factory.setCallback(0, builder);
        return builder;
    }
View Full Code Here

        return true;
    }

    @DB(txn=false)
    public static <T> UpdateBuilder getUpdateBuilder(final T entityObject) {
        final Factory factory = (Factory)entityObject;
        assert(factory != null);
        return (UpdateBuilder)factory.getCallback(1);
    }
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.