Search in sources :

Example 6 with Enhancer

use of net.sf.cglib.proxy.Enhancer in project rest.li by linkedin.

the class GeneratePatchProxyFactory method newInstance.

@SuppressWarnings("unchecked")
static <T> T newInstance(Class<T> clazz, PatchTree patchTree, PathSpec pathSpec) {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(clazz);
    enhancer.setCallback(newMethodInterceptor(clazz, patchTree, pathSpec));
    return (T) enhancer.create();
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer)

Example 7 with Enhancer

use of net.sf.cglib.proxy.Enhancer 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 8 with Enhancer

use of net.sf.cglib.proxy.Enhancer 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 9 with Enhancer

use of net.sf.cglib.proxy.Enhancer 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 10 with Enhancer

use of net.sf.cglib.proxy.Enhancer in project simplejpa by appoxy.

the class ObjectBuilder method newEnancedInstance.

private static ObjectWithInterceptor newEnancedInstance(EntityManagerSimpleJPA em, Class tClass) {
    LazyInterceptor interceptor = new LazyInterceptor(em);
    Enhancer e = new Enhancer();
    e.setSuperclass(tClass);
    e.setCallback(interceptor);
    Object bean = e.create();
    ObjectWithInterceptor cwi = new ObjectWithInterceptor(bean, interceptor);
    return cwi;
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer)

Aggregations

Enhancer (net.sf.cglib.proxy.Enhancer)27 MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)8 Callback (net.sf.cglib.proxy.Callback)6 Method (java.lang.reflect.Method)5 MethodProxy (net.sf.cglib.proxy.MethodProxy)5 FastClass (net.sf.cglib.reflect.FastClass)3 InjectionPoint (com.google.inject.spi.InjectionPoint)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Factory (net.sf.cglib.proxy.Factory)2 UndeclaredThrowableStrategy (net.sf.cglib.transform.impl.UndeclaredThrowableStrategy)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ShardingJdbcException (com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CellConfig (com.facebook.buck.config.CellConfig)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 Watchman (com.facebook.buck.io.Watchman)1 NULL_WATCHMAN (com.facebook.buck.io.Watchman.NULL_WATCHMAN)1