jodd.proxetta
Class Proxetta

java.lang.Object
  extended by jodd.proxetta.Proxetta
Direct Known Subclasses:
InvokeProxetta, ProxyProxetta

public abstract class Proxetta
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.


    Field Summary
    protected  java.lang.ClassLoader classLoader
               
    protected  java.lang.String classNameSuffix
               
    protected  boolean forced
               
    protected  boolean variableClassName
               
     
    Constructor Summary
    Proxetta()
               
     
    Method Summary
     Proxetta constantClassName()
              Sets constant proxy class name so each time created proxy class will have the same name.
    protected abstract  ClassProcessor createClassProcessor()
              Creates ProxettaCreator with current options.
     byte[] createProxy(java.lang.Class target)
              Generates proxy bytecode for provided class.
    protected  byte[] createProxy(ClassProcessor cp)
              Returns byte array of invoked proxetta creator.
     byte[] createProxy(java.lang.Class target, java.lang.String proxyClassName)
               
     byte[] createProxy(java.io.InputStream in)
              Generates proxy bytecode for class provided as InputStream.
     byte[] createProxy(java.io.InputStream in, java.lang.String proxyClassName)
               
     byte[] createProxy(java.lang.String targetName)
              Generates proxy bytecode for provided class.
     byte[] createProxy(java.lang.String targetName, java.lang.String proxyClassName)
               
    <T> T
    createProxyInstance(java.lang.Class<T> target)
               
    <T> T
    createProxyInstance(java.lang.Class<T> target, java.lang.String proxyClassName)
               
     java.lang.Object createProxyInstance(java.lang.String targetName)
               
     java.lang.Object createProxyInstance(java.lang.String targetName, java.lang.String proxyClassName)
               
     java.lang.Class defineProxy(java.lang.Class target)
              Defines new proxy class.
     java.lang.Class defineProxy(java.lang.Class target, java.lang.String proxyClassName)
               
     java.lang.Class defineProxy(java.lang.String targetName)
              Defines new proxy class.
     java.lang.Class defineProxy(java.lang.String targetName, java.lang.String proxyClassName)
               
     Proxetta dontUseClassNameSuffix()
              Specifies not to append class name suffix when creating proxy class.
     Proxetta forced(boolean forced)
              Specifies 'forced' mode.
     Proxetta loadsWith(java.lang.ClassLoader classLoader)
              Specifies classloaders for use.
    protected  ClassProcessor prepareClassProcessor()
              Creates and prepares class processor.
     Proxetta useClassNameSuffix(java.lang.String suffix)
              Specifies custom classname suffix to be added to the class name of created proxy.
     Proxetta 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.
    static Proxetta withAspects(InvokeAspect... aspects)
              Specifies invoke replacement aspects and creates Proxetta instance.
    static Proxetta withAspects(ProxyAspect... aspects)
              Specifies aspects for the target and creates Proxetta instance.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    forced

    protected boolean forced

    classLoader

    protected java.lang.ClassLoader classLoader

    variableClassName

    protected boolean variableClassName

    classNameSuffix

    protected java.lang.String classNameSuffix
    Constructor Detail

    Proxetta

    public Proxetta()
    Method Detail

    withAspects

    public static Proxetta withAspects(ProxyAspect... aspects)
    Specifies aspects for the target and creates Proxetta instance.


    withAspects

    public static Proxetta withAspects(InvokeAspect... aspects)
    Specifies invoke replacement aspects and creates Proxetta instance.


    forced

    public Proxetta forced(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.


    loadsWith

    public Proxetta loadsWith(java.lang.ClassLoader classLoader)
    Specifies classloaders for use.


    variableClassName

    public Proxetta 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.


    constantClassName

    public Proxetta constantClassName()
    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.


    useClassNameSuffix

    public Proxetta useClassNameSuffix(java.lang.String suffix)
    Specifies custom classname suffix to be added to the class name of created proxy.


    dontUseClassNameSuffix

    public Proxetta dontUseClassNameSuffix()
    Specifies not to append class name suffix when creating proxy class. Warning: when class name suffix is not used, full classname has to be specified that differs from target class name.


    createClassProcessor

    protected abstract ClassProcessor createClassProcessor()
    Creates ProxettaCreator with current options.


    prepareClassProcessor

    protected ClassProcessor prepareClassProcessor()
    Creates and prepares class processor.


    createProxy

    public byte[] createProxy(java.lang.Class target)
    Generates proxy bytecode for provided class. Returns null if there was no matching pointcuts and forced mode is off.


    createProxy

    public byte[] createProxy(java.lang.Class target,
                              java.lang.String proxyClassName)

    createProxy

    public byte[] createProxy(java.lang.String targetName)
    Generates proxy bytecode for provided class. Returns null if there was no matching pointcuts and forced mode is off.


    createProxy

    public byte[] createProxy(java.lang.String targetName,
                              java.lang.String proxyClassName)

    createProxy

    public byte[] createProxy(java.io.InputStream in)
    Generates proxy bytecode for class provided as InputStream. Returns null if there was no matching pointcuts and forced mode is off.


    createProxy

    public byte[] createProxy(java.io.InputStream in,
                              java.lang.String proxyClassName)

    createProxy

    protected byte[] createProxy(ClassProcessor cp)
    Returns byte array of invoked proxetta creator.


    defineProxy

    public java.lang.Class defineProxy(java.lang.Class target)
    Defines new proxy class.


    defineProxy

    public java.lang.Class defineProxy(java.lang.Class target,
                                       java.lang.String proxyClassName)

    defineProxy

    public java.lang.Class defineProxy(java.lang.String targetName)
    Defines new proxy class.


    defineProxy

    public java.lang.Class defineProxy(java.lang.String targetName,
                                       java.lang.String proxyClassName)

    createProxyInstance

    public <T> T createProxyInstance(java.lang.Class<T> target)

    createProxyInstance

    public <T> T createProxyInstance(java.lang.Class<T> target,
                                     java.lang.String proxyClassName)

    createProxyInstance

    public java.lang.Object createProxyInstance(java.lang.String targetName)

    createProxyInstance

    public java.lang.Object createProxyInstance(java.lang.String targetName,
                                                java.lang.String proxyClassName)


    Copyright © 2003-2011 Jodd Team