Class Proxetta<T extends Proxetta,A>
- java.lang.Object
-
- jodd.proxetta.Proxetta<T,A>
-
- Direct Known Subclasses:
InvokeProxetta
,ProxyProxetta
,WrapperProxetta
public abstract class Proxetta<T extends Proxetta,A> extends java.lang.Object
Proxetta creates dynamic proxy classes in the run-time.To wrap a class with proxy Proxetta needs a target class (or its name or
InputStream
) and one or moreproxy aspects
that will be applied to target. Proxetta will examine target class and check if there are any methods to wrap, as defined by aspects pointcut. If there is at least one matched method, new proxy class will be created that extends target class.If no matching method founded, Proxetta may or may not create an empty proxy class. This behaviour is defined by forced mode during creation.
There are several options that describes how proxy class will be named. By default, proxy class name is created from target class name by adding default suffix. Suffix can be changed, also, name can be variable, so each time class is created it will have a new name.
It is also possible to set proxy simple class name and/or package name. This is useful when proxyfing JDK classes or any other that can't be loaded by some classloader. Requested proxy name can be in the following forms:
- .Foo (starting with a dot) - proxy package name is equal to target package, just proxy simple class name is set.
- foo. (ending with a dot) - proxy package is set, proxy simple name is create from target simple class name.
- foo.Foo - full proxy class name is specified.
- See Also:
ProxettaFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoader
classLoader
protected java.lang.String
classNameSuffix
protected java.io.File
debugFolder
protected boolean
forced
protected java.util.List<A>
proxyAspectList
protected boolean
variableClassName
-
Constructor Summary
Constructors Constructor Description Proxetta()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected T
_this()
A[]
getAspects(A[] array)
java.lang.ClassLoader
getClassLoader()
Returns specified classloader for loading created classes.java.lang.String
getClassNameSuffix()
java.io.File
getDebugFolder()
Returns debug folder ornull
if debug folder does not exist.static InvokeProxetta
invokeProxetta()
Creates a new instance ofInvokeProxetta
.boolean
isForced()
boolean
isVariableClassName()
abstract ProxettaFactory
proxy()
CreatesProxettaFactory
with of this Proxetta.static ProxyProxetta
proxyProxetta()
Creates a new instance ofProxyProxetta
.T
setClassLoader(java.lang.ClassLoader classLoader)
Specifies classloaders for loading created classes.T
setClassNameSuffix(java.lang.String suffix)
Specifies custom classname suffix to be added to the class name of created proxy.T
setDebugFolder(java.io.File debugFolder)
T
setDebugFolder(java.lang.String debugFolder)
Specifies the debug folder where all created classes will be written to, for debugging purposes.T
setForced(boolean forced)
Specifies 'forced' mode.T
setVariableClassName(boolean variableClassName)
Sets variable proxy class name so every time when new proxy class is created its name will be different,so one classloader may load it without a problem.T
withAspect(A proxyAspect)
Adds an aspect.T
withAspects(A... aspects)
static WrapperProxetta
wrapperProxetta()
Creates a new instance ofWrapperProxetta
.
-
-
-
Field Detail
-
forced
protected boolean forced
-
classLoader
protected java.lang.ClassLoader classLoader
-
variableClassName
protected boolean variableClassName
-
classNameSuffix
protected java.lang.String classNameSuffix
-
debugFolder
protected java.io.File debugFolder
-
proxyAspectList
protected final java.util.List<A> proxyAspectList
-
-
Method Detail
-
wrapperProxetta
public static WrapperProxetta wrapperProxetta()
Creates a new instance ofWrapperProxetta
.
-
proxyProxetta
public static ProxyProxetta proxyProxetta()
Creates a new instance ofProxyProxetta
.
-
invokeProxetta
public static InvokeProxetta invokeProxetta()
Creates a new instance ofInvokeProxetta
.
-
_this
protected T _this()
-
setForced
public T setForced(boolean forced)
Specifies 'forced' mode. Iftrue
, new proxy class will be created even if there are no matching pointcuts. Iffalse
, new proxy class will be created only if there is at least one matching pointcut - otherwise, original class will be returned.
-
isForced
public boolean isForced()
-
setClassLoader
public T setClassLoader(java.lang.ClassLoader classLoader)
Specifies classloaders for loading created classes. If classloader not specified, default one will be used.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns specified classloader for loading created classes. If classloader is not specified, returnsnull
.
-
setVariableClassName
public T setVariableClassName(boolean variableClassName)
Sets variable proxy class name so every time when new proxy class is created its name will be different,so one classloader may load it without a problem. Otherwise, sets constant proxy class name so each time created proxy class will have the same name. Such class can be loaded only once by a classloader.This prevents "
java.lang.LinkageError: duplicate class definition
" errors.
-
isVariableClassName
public boolean isVariableClassName()
-
setClassNameSuffix
public T setClassNameSuffix(java.lang.String suffix)
Specifies custom classname suffix to be added to the class name of created proxy. Warning: when class name suffix is not used, full classname has to be specified that differs from target class name.
-
getClassNameSuffix
public java.lang.String getClassNameSuffix()
-
setDebugFolder
public T setDebugFolder(java.lang.String debugFolder)
Specifies the debug folder where all created classes will be written to, for debugging purposes.
-
setDebugFolder
public T setDebugFolder(java.io.File debugFolder)
-
getDebugFolder
public java.io.File getDebugFolder()
Returns debug folder ornull
if debug folder does not exist.
-
proxy
public abstract ProxettaFactory proxy()
CreatesProxettaFactory
with of this Proxetta.
-
-