org.aspectj.weaver.tools
Class WeavingAdaptor

java.lang.Object
  extended by org.aspectj.weaver.tools.WeavingAdaptor
All Implemented Interfaces:
IMessageContext
Direct Known Subclasses:
ClassLoaderWeavingAdaptor

public class WeavingAdaptor
extends java.lang.Object
implements IMessageContext

This adaptor allows the AspectJ compiler to be embedded in an existing system to facilitate load-time weaving. It provides an interface for a weaving class loader to provide a classpath to be woven by a set of aspects. A callback is supplied to allow a class loader to define classes generated by the compiler during the weaving process.

A weaving class loader should create a WeavingAdaptor before any classes are defined, typically during construction. The set of aspects passed to the adaptor is fixed for the lifetime of the adaptor although the classpath can be augmented. A system property can be set to allow verbose weaving messages to be written to the console.


Field Summary
 BcelObjectType delegateForCurrentClass
           
static java.lang.String SHOW_WEAVE_INFO_PROPERTY
           
static java.lang.String TRACE_MESSAGES_PROPERTY
           
static java.lang.String WEAVING_ADAPTOR_VERBOSE
          System property used to turn on verbose weaving messages
 
Constructor Summary
WeavingAdaptor(GeneratedClassHandler handler, java.net.URL[] classURLs, java.net.URL[] aspectURLs)
          Construct a WeavingAdator with a reference to a GeneratedClassHandler, a full search path for resolving classes and a complete set of aspects.
WeavingAdaptor(WeavingClassLoader loader)
          Construct a WeavingAdaptor with a reference to a weaving class loader.
 
Method Summary
 void addURL(java.net.URL url)
          Appends URL to path used by the WeavingAdptor to resolve classes
 java.lang.String getContextId()
           
 IMessageHolder getMessageHolder()
           
 byte[] weaveClass(java.lang.String name, byte[] bytes)
          Weave a class using aspects previously supplied to the adaptor.
 byte[] weaveClass(java.lang.String name, byte[] bytes, boolean mustWeave)
          Weave a class using aspects previously supplied to the adaptor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEAVING_ADAPTOR_VERBOSE

public static final java.lang.String WEAVING_ADAPTOR_VERBOSE
System property used to turn on verbose weaving messages

See Also:
Constant Field Values

SHOW_WEAVE_INFO_PROPERTY

public static final java.lang.String SHOW_WEAVE_INFO_PROPERTY
See Also:
Constant Field Values

TRACE_MESSAGES_PROPERTY

public static final java.lang.String TRACE_MESSAGES_PROPERTY
See Also:
Constant Field Values

delegateForCurrentClass

public BcelObjectType delegateForCurrentClass
Constructor Detail

WeavingAdaptor

public WeavingAdaptor(WeavingClassLoader loader)
Construct a WeavingAdaptor with a reference to a weaving class loader. The adaptor will automatically search the class loader hierarchy to resolve classes. The adaptor will also search the hierarchy for WeavingClassLoader instances to determine the set of aspects to be used ofr weaving.

Parameters:
loader - instance of ClassLoader

WeavingAdaptor

public WeavingAdaptor(GeneratedClassHandler handler,
                      java.net.URL[] classURLs,
                      java.net.URL[] aspectURLs)
Construct a WeavingAdator with a reference to a GeneratedClassHandler, a full search path for resolving classes and a complete set of aspects. The search path must include classes loaded by the class loader constructing the WeavingAdaptor and all its parents in the hierarchy.

Parameters:
handler - GeneratedClassHandler
classURLs - the URLs from which to resolve classes
aspectURLs - the aspects used to weave classes defined by this class loader
Method Detail

getMessageHolder

public IMessageHolder getMessageHolder()

addURL

public void addURL(java.net.URL url)
Appends URL to path used by the WeavingAdptor to resolve classes

Parameters:
url - to be appended to search path

weaveClass

public byte[] weaveClass(java.lang.String name,
                         byte[] bytes)
                  throws java.io.IOException
Weave a class using aspects previously supplied to the adaptor.

Parameters:
name - the name of the class
bytes - the class bytes
Returns:
the woven bytes
Throws:
java.io.IOException - weave failed

weaveClass

public byte[] weaveClass(java.lang.String name,
                         byte[] bytes,
                         boolean mustWeave)
                  throws java.io.IOException
Weave a class using aspects previously supplied to the adaptor.

Parameters:
name - the name of the class
bytes - the class bytes
mustWeave - if true then this class *must* get woven (used for concrete aspects generated from XML)
Returns:
the woven bytes
Throws:
java.io.IOException - weave failed

getContextId

public java.lang.String getContextId()
Specified by:
getContextId in interface IMessageContext