Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.Factory


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


    }

    @Override @DB(txn=false)
    public <K> SearchCriteria2 createSearchCriteria2(Class<K> resultType) {
        final T entity = (T)_searchEnhancer.create();
        final Factory factory = (Factory)entity;
        SearchCriteria2 sc = new SearchCriteria2(entity, resultType, _allAttributes, this);
        factory.setCallback(0, sc);
        return sc;
    }
View Full Code Here

    }

    @Override @DB(txn=false)
    public SearchCriteria2 createSearchCriteria2() {
        final T entity = (T)_searchEnhancer.create();
        final Factory factory = (Factory)entity;
        SearchCriteria2 sc = new SearchCriteria2(entity, entity.getClass(), _allAttributes, this);
        factory.setCallback(0, sc);
        return sc;
    }
View Full Code Here

     * Marks the SearchBuilder as completed in building the search conditions.
     */
    @Override
    protected synchronized void finalize() {
        if (_entity != null) {
            final Factory factory = (Factory)_entity;
            factory.setCallback(0, null);
            _entity = null;
        }

        if (_joins != null) {
            for (final JoinBuilder<SearchBase<?, ?, ?>> join : _joins.values()) {
View Full Code Here

            }
        }

        try {
            T t = (T)en.create();
            Factory factory = (Factory)t;
            factory.setCallback(0, new MethodInterceptor() {
                @Override
                public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
                    if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize")) {
                        return null;
                    } else {
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 "
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

    /**
     * Marks the SearchBuilder as completed in building the search conditions.
     */
    public synchronized void done() {
        if (_entity != null) {
            Factory factory = (Factory)_entity;
            factory.setCallback(0, null);
            _entity = null;
        }
       
        if (_joins != null) {
          for (JoinBuilder<GenericSearchBuilder<?, ?>> join : _joins.values()) {
View Full Code Here

            }
        }
    }

    private static Object createInstance(Class<?> clazz, boolean inject, boolean singleton, Object... args) {
        Factory factory = null;
        Singleton entity = null;
        synchronized(s_factories) {
            if (singleton) {
                entity = s_singletons.get(clazz);
                if (entity != null) {
                    s_logger.debug("Found singleton instantiation for " + clazz.toString());
                    return entity.singleton;
                }
            }
            InjectInfo info = s_factories.get(clazz);
            if (info == null) {
                Enhancer enhancer = new Enhancer();
                enhancer.setSuperclass(clazz);
                enhancer.setCallbackFilter(s_callbackFilter);
                enhancer.setCallbacks(s_callbacks);
                factory = (Factory)enhancer.create();
                info = new InjectInfo(enhancer, factory);
                s_factories.put(clazz, info);
            } else {
                factory = info.factory;
            }
        }


        Class<?>[] argTypes = null;
        if (args != null && args.length > 0) {
            Constructor<?>[] constructors = clazz.getConstructors();
            for (Constructor<?> constructor : constructors) {
                Class<?>[] paramTypes = constructor.getParameterTypes();
                if (paramTypes.length == args.length) {
                    boolean found = true;
                    for (int i = 0; i < paramTypes.length; i++) {
                        if (!paramTypes[i].isAssignableFrom(args[i].getClass()) && !paramTypes[i].isPrimitive()) {
                            found = false;
                            break;
                        }
                    }
                    if (found) {
                        argTypes = paramTypes;
                        break;
                    }
                }
            }

            if (argTypes == null) {
                throw new CloudRuntimeException("Unable to find constructor to match parameters given: " + clazz.getName());
            }

            entity = new Singleton(factory.newInstance(argTypes, args, s_callbacks));
        } else {
            entity = new Singleton(factory.newInstance(s_callbacks));
        }

        if (inject) {
            inject(clazz, entity.singleton);
            entity.state = Singleton.State.Injected;
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

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.