Search in sources :

Example 11 with MethodInterceptor

use of net.sf.cglib.proxy.MethodInterceptor 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);
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) Enhancer(net.sf.cglib.proxy.Enhancer) ArrayList(java.util.ArrayList) MethodProxy(net.sf.cglib.proxy.MethodProxy) Method(java.lang.reflect.Method)

Aggregations

MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)11 Enhancer (net.sf.cglib.proxy.Enhancer)10 Method (java.lang.reflect.Method)6 MethodProxy (net.sf.cglib.proxy.MethodProxy)6 ArrayList (java.util.ArrayList)2 CallbackFilter (net.sf.cglib.proxy.CallbackFilter)2 Test (org.junit.Test)2 Aop (com.blade.aop.annotation.Aop)1 DalAnnotationValidator (com.ctrip.platform.dal.dao.client.DalAnnotationValidator)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CellConfig (com.facebook.buck.config.CellConfig)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 Watchman (com.facebook.buck.io.Watchman)1 NULL_WATCHMAN (com.facebook.buck.io.Watchman.NULL_WATCHMAN)1 ProjectBuildFileParserFactory (com.facebook.buck.json.ProjectBuildFileParserFactory)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 TestConsole (com.facebook.buck.testutil.TestConsole)1