|
|
@@ -4,12 +4,12 @@
|
|
|
*/
|
|
|
package net.ranides.assira.asm;
|
|
|
|
|
|
+import java.lang.reflect.InvocationHandler;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.lang.reflect.Proxy;
|
|
|
import net.ranides.assira.collection.ArrayUtils;
|
|
|
import net.ranides.assira.generic.BiFunction;
|
|
|
-import net.sf.cglib.proxy.Enhancer;
|
|
|
-import net.sf.cglib.proxy.MethodInterceptor;
|
|
|
-import net.sf.cglib.proxy.MethodProxy;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -22,14 +22,13 @@ public final class ProxyDelegator {
|
|
|
// utility class
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public static <T> T paramWrapper(T object, BiFunction<Object,Object> function) {
|
|
|
- return (T)Enhancer.create(object.getClass(), new ParamWrapper(object, function));
|
|
|
+ public static <T> T paramWrapper(final T object, Class<T> intface, final BiFunction<Object,Object> function) {
|
|
|
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
|
+ return (T)Proxy.newProxyInstance(loader, new Class[]{intface}, new ParamWrapper(object, function));
|
|
|
}
|
|
|
|
|
|
- private static class ParamWrapper implements MethodInterceptor {
|
|
|
-
|
|
|
+ private static class ParamWrapper implements InvocationHandler {
|
|
|
private final Object delegator;
|
|
|
private final BiFunction<Object, Object> function;
|
|
|
|
|
|
@@ -39,7 +38,7 @@ public final class ProxyDelegator {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
|
|
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
|
return function.apply(method.invoke(delegator, ArrayUtils.inverse(args, function)));
|
|
|
}
|
|
|
}
|