factory.setCallbacks(new Callback[] {NoOp.INSTANCE, new LookupOverrideMethodInterceptor(this.beanDefinition, this.owner), new ReplaceOverrideMethodInterceptor(this.beanDefinition, this.owner)});
((Factory) proxyInstance).setCallbacks(callbacks); return proxyInstance;
factory.setCallbacks(new Callback[] {NoOp.INSTANCE, new LookupOverrideMethodInterceptor(this.beanDefinition, this.owner), new ReplaceOverrideMethodInterceptor(this.beanDefinition, this.owner)});
((Factory) proxy).setCallbacks(new Callback[] {interceptor}); return (T) proxy;
/** * Creates a proxy for the given {@link MongoPersistentProperty} using the given {@link DbRefResolverCallback} to * eventually resolve the value of the property. * * @param property must not be {@literal null}. * @param dbref can be {@literal null}. * @param callback must not be {@literal null}. * @return */ private Object createLazyLoadingProxy(MongoPersistentProperty property, @Nullable DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler handler) { Class<?> propertyType = property.getType(); LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor(property, dbref, exceptionTranslator, callback); if (!propertyType.isInterface()) { Factory factory = (Factory) objenesis.newInstance(getEnhancedTypeFor(propertyType)); factory.setCallbacks(new Callback[] { interceptor }); return handler.populateId(property, dbref, factory); } ProxyFactory proxyFactory = new ProxyFactory(); for (Class<?> type : propertyType.getInterfaces()) { proxyFactory.addInterface(type); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addInterface(propertyType); proxyFactory.addAdvice(interceptor); return handler.populateId(property, dbref, proxyFactory.getProxy()); }
((Factory) proxy).setCallbacks(new Callback[] {interceptor}); return (T) proxy;
((Factory) proxy).setCallbacks(new Callback[] {interceptor}); return (T) proxy;
((Factory) proxy).setCallbacks(new Callback[] {interceptor}); return (T) proxy;
((Factory) proxy).setCallbacks(new Callback[] {interceptor}); return (T) proxy;
@SuppressWarnings("unchecked") private static <T> T getProxyWithInterceptor(Class<?> type, InvocationRecordingMethodInterceptor interceptor, ClassLoader classLoader) { if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type); factory.addInterface(LastInvocationAware.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } Factory factory = (Factory) OBJENESIS.newInstance(getOrCreateEnhancedClass(type, classLoader)); factory.setCallbacks(new Callback[] { interceptor }); return (T) factory; }
/** * Creates a proxy for the given {@link MongoPersistentProperty} using the given {@link DbRefResolverCallback} to * eventually resolve the value of the property. * * @param property must not be {@literal null}. * @param dbref can be {@literal null}. * @param callback must not be {@literal null}. * @return */ private Object createLazyLoadingProxy(MongoPersistentProperty property, @Nullable DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler handler) { Class<?> propertyType = property.getType(); LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor(property, dbref, exceptionTranslator, callback); if (!propertyType.isInterface()) { Factory factory = (Factory) objenesis.newInstance(getEnhancedTypeFor(propertyType)); factory.setCallbacks(new Callback[] { interceptor }); return handler.populateId(property, dbref, factory); } ProxyFactory proxyFactory = new ProxyFactory(); for (Class<?> type : propertyType.getInterfaces()) { proxyFactory.addInterface(type); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addInterface(propertyType); proxyFactory.addAdvice(interceptor); return handler.populateId(property, dbref, proxyFactory.getProxy()); }
((Factory) proxyInstance).setCallbacks(callbacks); return proxyInstance;
factory.setCallbacks(new Callback[] {NoOp.INSTANCE, new LookupOverrideMethodInterceptor(this.beanDefinition, this.owner), new ReplaceOverrideMethodInterceptor(this.beanDefinition, this.owner)});
@SuppressWarnings("unchecked") private static <T> T getProxyWithInterceptor(Class<?> type, InvocationRecordingMethodInterceptor interceptor, ClassLoader classLoader) { if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type); factory.addInterface(LastInvocationAware.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } Factory factory = (Factory) OBJENESIS.newInstance(getOrCreateEnhancedClass(type, classLoader)); factory.setCallbacks(new Callback[] { interceptor }); return (T) factory; }
@Override @SuppressWarnings("unchecked") protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) { Class<?> proxyClass = enhancer.createClass(); Object proxyInstance = null; if (objenesis.isWorthTrying()) { try { proxyInstance = objenesis.newInstance(proxyClass, enhancer.getUseCache()); } catch (Throwable ex) { logger.debug("Unable to instantiate proxy using Objenesis, " + "falling back to regular proxy construction", ex); } } if (proxyInstance == null) { // Regular instantiation via default constructor... try { proxyInstance = (this.constructorArgs != null ? proxyClass.getConstructor(this.constructorArgTypes).newInstance(this.constructorArgs) : proxyClass.newInstance()); } catch (Throwable ex) { throw new AopConfigException("Unable to instantiate proxy using Objenesis, " + "and regular proxy instantiation via default constructor fails as well", ex); } } ((Factory) proxyInstance).setCallbacks(callbacks); return proxyInstance; }
public static <T> T createProxy(Class<T> type, List<MethodCallListener> listeners, ScanDepthStrategy scanDepthStrategy) { final ScanInterceptor scanInterceptor = new ScanInterceptor(type, listeners, scanDepthStrategy); if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type); factory.addAdvice(scanInterceptor); return (T) factory.getProxy(); } Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); enhancer.setClassLoader(type.getClassLoader()); Factory factory = (Factory) OBJENESIS.newInstance(enhancer.createClass()); factory.setCallbacks(new Callback[]{ scanInterceptor }); return (T) factory; }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object proxy( final String id, final TypeInformation<?> type, final A annotation, final ResolverCallback<A> callback) { final ProxyInterceptor interceptor = new ProxyInterceptor(id, type, annotation, callback, conversionService); if (type.getType().isInterface()) { final ProxyFactory proxyFactory = new ProxyFactory(new Class<?>[] { type.getType() }); for (final Class<?> interf : type.getType().getInterfaces()) { proxyFactory.addInterface(interf); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addAdvice(interceptor); return proxyFactory.getProxy(); } else { final Factory factory = (Factory) objenesis.newInstance(enhancedTypeFor(type.getType())); factory.setCallbacks(new Callback[] { interceptor }); return factory; } }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object proxy( final String id, final TypeInformation<?> type, final A annotation, final ResolverCallback<A> callback) { final ProxyInterceptor interceptor = new ProxyInterceptor(id, type, annotation, callback, conversionService); if (type.getType().isInterface()) { final ProxyFactory proxyFactory = new ProxyFactory(new Class<?>[] { type.getType() }); for (final Class<?> interf : type.getType().getInterfaces()) { proxyFactory.addInterface(interf); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addAdvice(interceptor); return proxyFactory.getProxy(); } else { final Factory factory = (Factory) objenesis.newInstance(enhancedTypeFor(type.getType())); factory.setCallbacks(new Callback[] { interceptor }); return factory; } }
/** * Creates a proxy for the given {@link MongoPersistentProperty} using the given {@link DbRefResolverCallback} to * eventually resolve the value of the property. * * @param property must not be {@literal null}. * @param dbref can be {@literal null}. * @param callback must not be {@literal null}. * @return */ private Object createLazyLoadingProxy(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler handler) { Class<?> propertyType = property.getType(); LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor(property, dbref, exceptionTranslator, callback); if (!propertyType.isInterface()) { Factory factory = (Factory) objenesis.newInstance(getEnhancedTypeFor(propertyType)); factory.setCallbacks(new Callback[] { interceptor }); return handler.populateId(property, dbref, factory); } ProxyFactory proxyFactory = new ProxyFactory(); for (Class<?> type : propertyType.getInterfaces()) { proxyFactory.addInterface(type); } proxyFactory.addInterface(LazyLoadingProxy.class); proxyFactory.addInterface(propertyType); proxyFactory.addAdvice(interceptor); return handler.populateId(property, dbref, proxyFactory.getProxy()); }
@SuppressWarnings("unchecked") private static <T> T getProxyWithInterceptor(final Class<?> type, final RecordingMethodInterceptor interceptor, final ClassLoader classLoader, final boolean isfinal) { if (type.isInterface()) { ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); factory.addInterface(type); factory.addInterface(LastInvocationAware.class); factory.addAdvice(interceptor); return (T) factory.getProxy(); } Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setInterfaces(new Class<?>[] { LastInvocationAware.class }); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); enhancer.setClassLoader(classLoader); Factory factory = (Factory) OBJENESIS.newInstance(enhancer.createClass()); factory.setCallbacks(new Callback[] { interceptor }); return (T) factory; }