use of net.sf.cglib.proxy.Enhancer in project cloudstack by apache.
the class MethodCapturer method capture.
@SuppressWarnings("unchecked")
public static <T> MethodCapturer<T> capture(T obj) {
synchronized (s_cache) {
MethodCapturer<T> capturer = (MethodCapturer<T>) s_cache.get(obj);
if (capturer != null) {
return capturer;
}
final MethodCapturer<T> capturerNew = new MethodCapturer<T>();
Enhancer en = new Enhancer();
en.setSuperclass(obj.getClass());
en.setCallbacks(new Callback[] { new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
capturerNew.setMethod(arg1);
return null;
}
}, new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return null;
}
} });
en.setCallbackFilter(new CallbackFilter() {
@Override
public int accept(Method method) {
if (method.getParameterTypes().length == 0 && method.getName().equals("finalize")) {
return 1;
}
return 0;
}
});
capturerNew.setInstance((T) en.create());
// here
if (s_cache.size() < CACHE_SIZE) {
s_cache.put(obj, capturerNew);
}
return capturerNew;
}
}
use of net.sf.cglib.proxy.Enhancer in project cloudstack by apache.
the class ComponentInstantiationPostProcessor method postProcessBeforeInstantiation.
@Override
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
if (_interceptors != null && _interceptors.size() > 0) {
if (ComponentMethodInterceptable.class.isAssignableFrom(beanClass)) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(beanClass);
enhancer.setCallbacks(getCallbacks());
enhancer.setCallbackFilter(getCallbackFilter());
enhancer.setNamingPolicy(ComponentNamingPolicy.INSTANCE);
Object bean = enhancer.create();
return bean;
}
}
return null;
}
Aggregations