Search in sources :

Example 1 with Callback

use of net.sf.cglib.proxy.Callback in project JessMA by ldcsaa.

the class FacadeProxy method getProxy.

@SuppressWarnings("unchecked")
private static final <F extends AbstractFacade<M, S>, M extends SessionMgr<S>, S> F getProxy(Class<F> daoClass, M mgr, Callback intercepter) {
    Enhancer en = new Enhancer();
    en.setSuperclass(daoClass);
    en.setCallbackFilter(InterceptFilter.INSTANCE);
    Callback[] callbacks = { NoOp.INSTANCE, intercepter };
    en.setCallbacks(callbacks);
    en.setInterceptDuringConstruction(false);
    Class<?>[] argTypes = mgr != null ? new Class<?>[] { mgr.getClass() } : new Class<?>[] {};
    Object[] args = mgr != null ? new Object[] { mgr } : new Object[] {};
    return (F) en.create(argTypes, args);
}
Also used : Callback(net.sf.cglib.proxy.Callback) Enhancer(net.sf.cglib.proxy.Enhancer)

Example 2 with Callback

use of net.sf.cglib.proxy.Callback in project spring-loaded by spring-projects.

the class ProxyBuilder method createProxyFor.

static <T> T createProxyFor(Class<T> clazz, MethodInterceptor mi) {
    Enhancer enhancer = new Enhancer();
    //		if (classLoader != null) {
    //			enhancer.setClassLoader(classLoader);
    //			if (classLoader instanceof SmartClassLoader &&
    //					((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) {
    //				enhancer.setUseCache(false);
    //			}
    //		}
    enhancer.setSuperclass(clazz);
    enhancer.setStrategy(new UndeclaredThrowableStrategy(UndeclaredThrowableException.class));
    //AopProxyUtils.completeProxiedInterfaces(this.advised));
    enhancer.setInterfaces(null);
    enhancer.setInterceptDuringConstruction(false);
    //getCallbacks(rootClass);
    Callback[] callbacks = new Callback[] { mi };
    enhancer.setCallbacks(callbacks);
    //		enhancer.setCallbackFilter(new ProxyCallbackFilter(
    //				this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset));
    Class<?>[] types = new Class[callbacks.length];
    for (int x = 0; x < types.length; x++) {
        types[x] = callbacks[x].getClass();
    }
    enhancer.setCallbackTypes(types);
    // Generate the proxy class and create a proxy instance.
    //		Object proxy;
    //		if (this.constructorArgs != null) {
    //			proxy = enhancer.create(this.constructorArgTypes, this.constructorArgs);
    //		}
    //		else {
    @SuppressWarnings("unchecked") T proxy = (T) enhancer.create();
    //		}
    return proxy;
}
Also used : Callback(net.sf.cglib.proxy.Callback) Enhancer(net.sf.cglib.proxy.Enhancer) UndeclaredThrowableStrategy(net.sf.cglib.transform.impl.UndeclaredThrowableStrategy) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 3 with Callback

use of net.sf.cglib.proxy.Callback in project spring-loaded by spring-projects.

the class ProxyBuilder method createProxyFor.

static <T> T createProxyFor(Class<T> clazz, MethodInterceptor mi) {
    Enhancer enhancer = new Enhancer();
    //		if (classLoader != null) {
    //			enhancer.setClassLoader(classLoader);
    //			if (classLoader instanceof SmartClassLoader &&
    //					((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) {
    //				enhancer.setUseCache(false);
    //			}
    //		}
    enhancer.setSuperclass(clazz);
    enhancer.setStrategy(new UndeclaredThrowableStrategy(UndeclaredThrowableException.class));
    //AopProxyUtils.completeProxiedInterfaces(this.advised));
    enhancer.setInterfaces(null);
    enhancer.setInterceptDuringConstruction(false);
    //getCallbacks(rootClass);
    Callback[] callbacks = new Callback[] { mi };
    enhancer.setCallbacks(callbacks);
    //		enhancer.setCallbackFilter(new ProxyCallbackFilter(
    //				this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset));
    Class<?>[] types = new Class[callbacks.length];
    for (int x = 0; x < types.length; x++) {
        types[x] = callbacks[x].getClass();
    }
    enhancer.setCallbackTypes(types);
    // Generate the proxy class and create a proxy instance.
    //		Object proxy;
    //		if (this.constructorArgs != null) {
    //			proxy = enhancer.create(this.constructorArgTypes, this.constructorArgs);
    //		}
    //		else {
    @SuppressWarnings("unchecked") T proxy = (T) enhancer.create();
    //		}
    return proxy;
}
Also used : Callback(net.sf.cglib.proxy.Callback) Enhancer(net.sf.cglib.proxy.Enhancer) UndeclaredThrowableStrategy(net.sf.cglib.transform.impl.UndeclaredThrowableStrategy) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 4 with Callback

use of net.sf.cglib.proxy.Callback in project guice by google.

the class ProxyFactory method create.

@Override
public ConstructionProxy<T> create() throws ErrorsException {
    if (interceptors.isEmpty()) {
        return new DefaultConstructionProxyFactory<T>(injectionPoint).create();
    }
    @SuppressWarnings("unchecked") Class<? extends Callback>[] callbackTypes = new Class[callbacks.length];
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) {
            callbackTypes[i] = net.sf.cglib.proxy.NoOp.class;
        } else {
            callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
        }
    }
    // to this injector. Otherwise, the proxies for each injector will waste PermGen memory
    try {
        Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility);
        enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
        enhancer.setCallbackTypes(callbackTypes);
        return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors);
    } catch (Throwable e) {
        throw new Errors().errorEnhancingClass(declaringClass, e).toException();
    }
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) InjectionPoint(com.google.inject.spi.InjectionPoint) Callback(net.sf.cglib.proxy.Callback) FastClass(net.sf.cglib.reflect.FastClass)

Example 5 with Callback

use of net.sf.cglib.proxy.Callback in project CloudStack-archive by CloudStack-extras.

the class GenericDaoBase method toEntityBean.

@SuppressWarnings("unchecked")
@DB(txn = false)
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T) _factory.newInstance(new Callback[] { NoOp.INSTANCE, new UpdateBuilder(this) });
    toEntityBean(result, entity);
    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }
    return entity;
}
Also used : Callback(net.sf.cglib.proxy.Callback) Element(net.sf.ehcache.Element) URISyntaxException(java.net.URISyntaxException) EntityExistsException(javax.persistence.EntityExistsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException)

Aggregations

Callback (net.sf.cglib.proxy.Callback)10 Enhancer (net.sf.cglib.proxy.Enhancer)6 FastClass (net.sf.cglib.reflect.FastClass)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 InjectionPoint (com.google.inject.spi.InjectionPoint)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 SQLException (java.sql.SQLException)2 ConfigurationException (javax.naming.ConfigurationException)2 EntityExistsException (javax.persistence.EntityExistsException)2 UndeclaredThrowableStrategy (net.sf.cglib.transform.impl.UndeclaredThrowableStrategy)2 Element (net.sf.ehcache.Element)2 Service (org.apache.axis.client.Service)2 BytecodeGen.newFastClass (com.google.inject.internal.BytecodeGen.newFastClass)1 Method (java.lang.reflect.Method)1 Remote (java.rmi.Remote)1 Iterator (java.util.Iterator)1