}
private static Object createCGLibProxy(Class<? extends Object> targetClass, final InvocationHandler invocationHandler) {
Object proxy;
// Create CGLib Method interceptor
MethodInterceptor interceptor = new MethodInterceptor() {
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return invocationHandler.invoke(obj, method, args);
}
};
// Create the proxy
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(targetClass);
enhancer.setCallbackType(interceptor.getClass());
Class<?> proxiedClass = enhancer.createClass();
Enhancer.registerCallbacks(proxiedClass, new Callback[] { interceptor });
/* To make the proxy creator work with Eclipse plugins */
enhancer.setClassLoader(ProxyCreator.class.getClassLoader());