Package org.proxy4j.core
Interface ProxyFactory
-
- All Known Implementing Classes:
BaseProxyFactory,CglibProxyFactory,JavassistProxyFactory,JdkProxyFactory
public interface ProxyFactoryA factory interface for creating different types of proxies.
- Since:
- 1.0
- Author:
- Brennan Spies
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> InterceptorBuilder<T>buildInterceptor(Class<T> proxyClass)Creates a new builder for constructing an interceptor or "protection" proxy.ObjectcreateProxy(Class<?>[] proxyInterfaces, ProxyHandler<?> handler)Creates a proxy that implements multiple interfaces where invocations on that proxy are passed to a singleinvokemethod on theProxyHandler.<T> TcreateProxy(Class<T> proxyClass, javax.inject.Provider<T> provider)Creates a "virtual" proxy where method invocations on the proxy are delegated to the provided instance.<T> TcreateProxy(Class<T> proxyClass, ProxyHandler<T> handler)Creates a proxy where method invocations on the proxy are passed to a singleinvokemethod on theProxyHandler.<T> TcreateProxy(Class<T> proxyClass, T target, Class<? extends Annotation> marker, org.aopalliance.intercept.MethodInterceptor... interceptors)Creates a "protection" proxy where method invocations on the proxy are intercepted by the chain ofMethodInterceptorsbefore (optionally) being invoked on the target.
-
-
-
Method Detail
-
createProxy
<T> T createProxy(Class<T> proxyClass, javax.inject.Provider<T> provider) throws GenerationException
Creates a "virtual" proxy where method invocations on the proxy are delegated to the provided instance.- Type Parameters:
T- The proxy type- Parameters:
proxyClass- The proxied classprovider- The provider of the proxied object- Returns:
- The proxy
- Throws:
GenerationException- If an error occurs creating the proxy
-
createProxy
<T> T createProxy(Class<T> proxyClass, ProxyHandler<T> handler) throws GenerationException
Creates a proxy where method invocations on the proxy are passed to a singleinvokemethod on theProxyHandler.- Type Parameters:
T- The proxy type- Parameters:
proxyClass- The proxied interface classhandler- The handler for the method invocation- Returns:
- The proxy
- Throws:
GenerationException- If an error occurs creating the proxy
-
createProxy
Object createProxy(Class<?>[] proxyInterfaces, ProxyHandler<?> handler) throws GenerationException
Creates a proxy that implements multiple interfaces where invocations on that proxy are passed to a singleinvokemethod on theProxyHandler. Equivalent to the traditional JDK proxy creation method:Proxy.newProxyInstance(ClassLoader, Class[], java.lang.reflect.InvocationHandler).- Parameters:
proxyInterfaces- The interfaces that the proxy class must implementhandler- The handler for the method invocation- Returns:
- The proxy
- Throws:
GenerationException- If an error occurs creating the proxy
-
createProxy
<T> T createProxy(Class<T> proxyClass, T target, Class<? extends Annotation> marker, org.aopalliance.intercept.MethodInterceptor... interceptors) throws GenerationException
Creates a "protection" proxy where method invocations on the proxy are intercepted by the chain ofMethodInterceptorsbefore (optionally) being invoked on the target.- Type Parameters:
T- The proxy type- Parameters:
proxyClass- The proxy classtarget- The target of the invocationmarker- The annotation that marks intercepted methodsinterceptors- One or more method interceptors, which are called in order- Returns:
- The proxy
- Throws:
GenerationException- If an error occurs creating the proxy
-
buildInterceptor
<T> InterceptorBuilder<T> buildInterceptor(Class<T> proxyClass)
Creates a new builder for constructing an interceptor or "protection" proxy. The builder allows fine-grained customization of how the target's methods are intercepted.- Type Parameters:
T- The proxy type- Parameters:
proxyClass- The class of the proxy (and target)- Returns:
- The builder
-
-