Package org.proxy4j.core
Class BaseProxyFactory
- java.lang.Object
-
- org.proxy4j.core.BaseProxyFactory
-
- All Implemented Interfaces:
ProxyFactory
- Direct Known Subclasses:
CglibProxyFactory,JavassistProxyFactory,JdkProxyFactory
public abstract class BaseProxyFactory extends Object implements ProxyFactory
Abstract base implementation of
ProxyFactory.- Author:
- Brennan Spies
-
-
Constructor Summary
Constructors Constructor Description BaseProxyFactory()Default constructor with no preferred class loader.BaseProxyFactory(ClassLoader preferredClassLoader)Constructor that takes the preferred class loader for loading proxy interfaces.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertClassVisible(ClassLoader loader, Class<?> type)Verifies that the given class is visible from the given class loader.protected voidassertInterfaces(Class<?>... types)Verifies that all the given classes are interfaces.<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.protected NamingPolicygetNamingStrategy()Returns aNamingPolicythat can be used to create proxy class names.protected ClassLoadergetPreferredClassLoader()Returns the specifiedClassLoaderthat is used to define any proxy interfaces.protected ClassLoadergetProxyClassLoader(Class<?> proxyType)Returns theClassLoaderthat should be used to load the proxy.voidsetNamingStrategy(NamingPolicy namingPolicy)Sets the naming policy used to determine the proxy class name.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.proxy4j.core.ProxyFactory
buildInterceptor, createProxy, createProxy, createProxy
-
-
-
-
Constructor Detail
-
BaseProxyFactory
public BaseProxyFactory()
Default constructor with no preferred class loader.
-
BaseProxyFactory
public BaseProxyFactory(ClassLoader preferredClassLoader)
Constructor that takes the preferred class loader for loading proxy interfaces.- Parameters:
preferredClassLoader- The class loader for proxy interfaces
-
-
Method Detail
-
getNamingStrategy
protected NamingPolicy getNamingStrategy()
Returns aNamingPolicythat can be used to create proxy class names.- Returns:
- The naming strategy
-
setNamingStrategy
@Inject public void setNamingStrategy(NamingPolicy namingPolicy)
Sets the naming policy used to determine the proxy class name.- Parameters:
namingPolicy- The naming policy to set
-
getPreferredClassLoader
protected ClassLoader getPreferredClassLoader()
Returns the specifiedClassLoaderthat is used to define any proxy interfaces.- Returns:
- The
ClassLoaderused to define proxy interfaces
-
getProxyClassLoader
protected ClassLoader getProxyClassLoader(Class<?> proxyType)
Returns theClassLoaderthat should be used to load the proxy.- Parameters:
proxyType- The class of the proxy- Returns:
- The
ClassLoader
-
assertClassVisible
protected void assertClassVisible(ClassLoader loader, Class<?> type) throws GenerationException
Verifies that the given class is visible from the given class loader.- Parameters:
loader- The class loader that needs visibility to the classtype- The class to verity- Throws:
GenerationException- Iftypeis not visible from the class loader
-
assertInterfaces
protected void assertInterfaces(Class<?>... types) throws GenerationException
Verifies that all the given classes are interfaces.- Parameters:
types- The classes to test- Throws:
GenerationException- If at least one class is not an interface
-
createProxy
public <T> T createProxy(Class<T> proxyClass, T target, Class<? extends Annotation> marker, org.aopalliance.intercept.MethodInterceptor... interceptors) throws GenerationException
Description copied from interface:ProxyFactoryCreates a "protection" proxy where method invocations on the proxy are intercepted by the chain ofMethodInterceptorsbefore (optionally) being invoked on the target.- Specified by:
createProxyin interfaceProxyFactory- 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- See Also:
ProxyFactory.createProxy(Class, Object, Class, org.aopalliance.intercept.MethodInterceptor...)
-
-