Java 类net.sf.cglib.proxy.CallbackHelper 实例源码

项目:byte-buddy    文件:ClassByImplementationBenchmark.java   
/**
 * Performs a benchmark of an interface implementation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) {
        @Override
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {
                    @Override
                    public Object loadObject() throws Exception {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
项目:jpa-unit    文件:JpaUnitObjectFactory.java   
private <T> T createProxy(final Class<T> clazz) {
    if (invocationsMap == null) {
        invocationsMap = new HashMap<>();
    }

    try {
        final FeatureResolver resolver = FeatureResolver.newFeatureResolver(clazz).build();
        final TestInvocation invocation = new TestInvocationImpl(clazz, resolver);
        invocationsMap.put(clazz, invocation);

        executor.processBeforeAll(invocation);
    } catch (final Exception e) {
        throw new JpaUnitException("Could not execute beforeAll hook", e);
    }

    final T bean = createBean(clazz);
    final CallbackHelper helper = new CallbackHelper(clazz, new Class[0]) {

        @Override
        protected Object getCallback(final Method method) {
            if (hasCucumberAnnotations(method)) {
                return new CucumberInterceptor(executor, bean);
            } else if (method.getName().equals("equals")) {
                return new EqualsInterceptor(bean);
            } else {
                return (Dispatcher) () -> bean;
            }
        }
    };

    return clazz.cast(Enhancer.create(clazz, new Class[0], helper, helper.getCallbacks()));
}
项目:jpa-unit    文件:JpaUnitConcordionRunner.java   
private Object createProxy(final Object bean) {
    final CallbackHelper helper = new CallbackHelper(bean.getClass(), new Class[0]) {

        @Override
        protected Object getCallback(final Method method) {
            if (method.getName().equals("equals")) {
                return new EqualsInterceptor(bean);
            } else {
                return new ConcordionInterceptor(executor, bean);
            }
        }
    };

    return Enhancer.create(bean.getClass(), new Class[0], helper, helper.getCallbacks());
}