ClassToBeProxied - public class ProxyFactory<ClassToBeProxied> extends Object
Usually there are many object created for the same class and for this reason a factory keeps track of the already generated classes and when a class can be reused it will not be generated again, but the already loaded class will be used.
| Constructor and Description |
|---|
ProxyFactory() |
| Modifier and Type | Method and Description |
|---|---|
ClassToBeProxied |
create(ClassToBeProxied originalObject,
MethodInterceptor interceptor)
Create a new proxy object.
|
Class<?> |
createClass(Class<?> originalClass)
Create a new proxy class that is capable proxying an object that is an
instance of the class.
|
String |
getCompilerErrorOutput() |
String |
getGeneratedClassName()
Get the name of the class that was generated last time.
|
String |
getGeneratedSource()
Get the source code that was generated by the factory last time.
|
ProxySetter |
instantiateProxy(Class<?> proxyClass)
Instantiate a proxy object from a proxyClass.
|
void |
setCallbackFilter(CallbackFilter callbackFilter)
Set a valid callback filter.
|
void |
setClassLoader(ClassLoader classLoader)
By the default the classloader used to load the original class is used to
load the proxy class.
|
public void setCallbackFilter(CallbackFilter callbackFilter)
callbackFilter - is the callback filter object and can not be null. When null
argument is passed IllegalArgumentException is thrown.public void setClassLoader(ClassLoader classLoader)
ProxySetter and/or MethodInterceptor classes. This is typically in the weird case when the
you want to proxy some of the system classes. In that case you can set
the classloader calling this method. For example you can
ProxyFactory<Object> factory = new ProxyFactory<>(); factory.setClassLoader(this.getClass().getClassLoader());
classLoader - public String getGeneratedSource()
public String getGeneratedClassName()
getGeneratedSource().public String getCompilerErrorOutput()
public ClassToBeProxied create(ClassToBeProxied originalObject, MethodInterceptor interceptor) throws Exception
originalObject - the object to be proxiedException - when the proxy can not be created. This can be for several
reasons. Identified reasons:
public Class<?> createClass(Class<?> originalClass) throws Exception
originalObject - interceptor - Exceptionpublic ProxySetter instantiateProxy(Class<?> proxyClass) throws Exception
proxyClass - ExceptionCopyright © 2013. All Rights Reserved.