use of net.sf.cglib.proxy.MethodProxy in project cloudstack by apache.
the class AsyncCallbackDispatcher method getTarget.
@SuppressWarnings("unchecked")
public T getTarget() {
Class<?> clz = _targetObject.getClass();
String clzName = clz.getName();
if (clzName.contains("EnhancerByCloudStack"))
clz = clz.getSuperclass();
Enhancer en = null;
synchronized (enMap) {
en = enMap.get(clz);
if (en == null) {
en = new Enhancer();
en.setSuperclass(clz);
en.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
return null;
}
});
enMap.put(clz, en);
}
}
try {
T t = (T) en.create();
Factory factory = (Factory) t;
factory.setCallback(0, new MethodInterceptor() {
@Override
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize")) {
return null;
} else {
_callbackMethod = arg1;
_callbackMethod.setAccessible(true);
return null;
}
}
});
return t;
} catch (Throwable e) {
s_logger.error("Unexpected exception", e);
}
return null;
}
use of net.sf.cglib.proxy.MethodProxy in project yyl_example by Relucent.
the class EnhancerTest method main.
public static void main(String[] args) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(null);
enhancer.setInterfaces(new Class[] { I.class });
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return methodProxy.invokeSuper(o, args);
}
System.out.println("->" + method.getName());
return null;
}
});
I a = I.class.cast(enhancer.create());
a.method();
}
use of net.sf.cglib.proxy.MethodProxy in project cxf by apache.
the class CglibProxyHelper method getProxyInternal.
@Override
protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, final java.lang.reflect.InvocationHandler h) {
Class<?> superClass = null;
List<Class<?>> theInterfaces = new ArrayList<Class<?>>();
for (Class<?> c : interfaces) {
if (!c.isInterface()) {
if (superClass != null) {
throw new IllegalArgumentException("Only a single superclass is supported");
}
superClass = c;
} else {
theInterfaces.add(c);
}
}
if (superClass != null) {
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(loader);
enhancer.setSuperclass(superClass);
enhancer.setInterfaces(theInterfaces.toArray(new Class<?>[theInterfaces.size()]));
enhancer.setCallback(new MethodInterceptor() {
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
return h.invoke(obj, method, args);
}
});
return enhancer.create();
}
return super.getProxyInternal(loader, interfaces, h);
}
Aggregations