org.aspectj.weaver.tools

Class WeavingAdaptor

Implemented Interfaces:
IMessageContext
Known Direct 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.

Nested Class Summary

protected class
WeavingAdaptor.WeavingAdaptorMessageHolder
Processes messages arising from weaver operations.
protected class
WeavingAdaptor.WeavingAdaptorMessageWriter

Field Summary

static String
SHOW_WEAVE_INFO_PROPERTY
static String
TRACE_MESSAGES_PROPERTY
static String
WEAVING_ADAPTOR_VERBOSE
System property used to turn on verbose weaving messages
protected org.aspectj.weaver.bcel.BcelWorld
bcelWorld
protected org.aspectj.weaver.bcel.BcelObjectType
delegateForCurrentClass
protected GeneratedClassHandler
generatedClassHandler
protected Map
generatedClasses
protected boolean
verbose
protected org.aspectj.weaver.bcel.BcelWeaver
weaver

Constructor Summary

WeavingAdaptor()
WeavingAdaptor(GeneratedClassHandler handler, URL[] classURLs, 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

protected boolean
accept(String name, byte[] bytes)
void
addURL(URL url)
Appends URL to path used by the WeavingAdptor to resolve classes
protected void
createMessageHandler()
protected boolean
debug(String message)
protected void
disable()
protected void
dump(String name, byte[] b, boolean before)
Dump the given bytcode in _dump/...
protected void
enable()
protected void
ensureDelegateInitialized(String name, byte[] bytes)
protected boolean
error(String message)
protected boolean
error(String message, Throwable th)
String
getContextId()
protected IMessageHandler
getMessageHandler()
IMessageHolder
getMessageHolder()
protected boolean
info(String message)
protected boolean
isEnabled()
protected void
setMessageHandler(IMessageHandler mh)
protected boolean
shouldDump(String name, boolean before)
protected boolean
warn(String message)
protected boolean
warn(String message, Throwable th)
byte[]
weaveClass(String name, byte[] bytes)
Weave a class using aspects previously supplied to the adaptor.

Field Details

SHOW_WEAVE_INFO_PROPERTY

public static final String SHOW_WEAVE_INFO_PROPERTY

TRACE_MESSAGES_PROPERTY

public static final String TRACE_MESSAGES_PROPERTY

WEAVING_ADAPTOR_VERBOSE

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

bcelWorld

protected org.aspectj.weaver.bcel.BcelWorld bcelWorld

delegateForCurrentClass

protected org.aspectj.weaver.bcel.BcelObjectType delegateForCurrentClass

generatedClassHandler

protected GeneratedClassHandler generatedClassHandler

generatedClasses

protected Map generatedClasses

verbose

protected boolean verbose

weaver

protected org.aspectj.weaver.bcel.BcelWeaver weaver

Constructor Details

WeavingAdaptor

protected WeavingAdaptor()

WeavingAdaptor

public WeavingAdaptor(GeneratedClassHandler handler,
                      URL[] classURLs,
                      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

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

Method Details

accept

protected boolean accept(String name,
                         byte[] bytes)

addURL

public void addURL(URL url)
Appends URL to path used by the WeavingAdptor to resolve classes
Parameters:
url - to be appended to search path

createMessageHandler

protected void createMessageHandler()

debug

protected boolean debug(String message)

disable

protected void disable()

dump

protected void dump(String name,
                    byte[] b,
                    boolean before)
Dump the given bytcode in _dump/... (dev mode)
Parameters:
name -
b -
before - whether we are dumping before weaving

enable

protected void enable()

ensureDelegateInitialized

protected void ensureDelegateInitialized(String name,
                                         byte[] bytes)

error

protected boolean error(String message)

error

protected boolean error(String message,
                        Throwable th)

getContextId

public String getContextId()

getMessageHandler

protected IMessageHandler getMessageHandler()

getMessageHolder

public IMessageHolder getMessageHolder()

info

protected boolean info(String message)

isEnabled

protected boolean isEnabled()

setMessageHandler

protected void setMessageHandler(IMessageHandler mh)

shouldDump

protected boolean shouldDump(String name,
                             boolean before)

warn

protected boolean warn(String message)

warn

protected boolean warn(String message,
                       Throwable th)

weaveClass

public byte[] weaveClass(String name,
                         byte[] bytes)
            throws 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