Package jodd.proxetta

Class Proxetta<T extends Proxetta,​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 more proxy 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 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
    • Constructor Detail

      • Proxetta

        public Proxetta()
    • Method Detail

      • _this

        protected T _this()
      • withAspect

        public T withAspect​(A proxyAspect)
        Adds an aspect.
      • withAspects

        public T withAspects​(A... aspects)
      • getAspects

        public A[] getAspects​(A[] array)
      • setForced

        public T setForced​(boolean forced)
        Specifies 'forced' mode. If true, new proxy class will be created even if there are no matching pointcuts. If false, 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, returns null.
      • 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 or null if debug folder does not exist.