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);
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations