Package org.aspectj.weaver.tools
Class WeavingAdaptor
java.lang.Object
org.aspectj.weaver.tools.WeavingAdaptor
- All Implemented Interfaces:
IMessageContext
- Direct Known Subclasses:
ClassLoaderWeavingAdaptor
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
Modifier and TypeClassDescriptionprotected class
Processes messages arising from weaver operations.protected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected ProtectionDomain
protected BcelWorld
protected WeavedClassCache
protected Map<String,IUnwovenClassFile>
protected GeneratedClassHandler
static String
static String
protected boolean
protected BcelWeaver
static String
System property used to turn on verbose weaving messages -
Constructor Summary
ModifierConstructorDescriptionprotected
WeavingAdaptor(GeneratedClassHandler handler, URL[] classURLs, URL[] aspectURLs)
Construct a WeavingAdaptor with a reference to aGeneratedClassHandler
, 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
Modifier and TypeMethodDescriptionprotected boolean
void
Appends URL to path used by the WeavingAdptor to resolve classesprotected void
protected boolean
protected void
disable()
protected void
Dump the given bytcode in _dump/...protected void
enable()
protected void
ensureDelegateInitialized(String name, byte[] bytes)
protected boolean
protected boolean
protected String
getFullClassPath(ClassLoader loader)
protected IMessageHandler
protected boolean
protected void
initializeCache(ClassLoader loader, List<String> aspects, GeneratedClassHandler existingClassHandler, IMessageHandler myMessageHandler)
If the cache is enabled, initialize it and swap out the existing classhandler for the caching one -protected boolean
void
setActiveProtectionDomain(ProtectionDomain protectionDomain)
protected void
protected boolean
shouldDump(String name, boolean before)
protected boolean
protected boolean
byte[]
weaveClass(String name, byte[] bytes)
Weave a class using aspects previously supplied to the adaptor.byte[]
weaveClass(String name, byte[] bytes, boolean mustWeave)
Weave a class using aspects previously supplied to the adaptor.
-
Field Details
-
WEAVING_ADAPTOR_VERBOSE
System property used to turn on verbose weaving messages- See Also:
- Constant Field Values
-
SHOW_WEAVE_INFO_PROPERTY
- See Also:
- Constant Field Values
-
TRACE_MESSAGES_PROPERTY
- See Also:
- Constant Field Values
-
verbose
protected boolean verbose -
bcelWorld
-
weaver
-
generatedClassHandler
-
generatedClasses
-
delegateForCurrentClass
-
activeProtectionDomain
-
cache
-
-
Constructor Details
-
WeavingAdaptor
protected WeavingAdaptor() -
WeavingAdaptor
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 for weaving.- Parameters:
loader
- instance ofClassLoader
-
WeavingAdaptor
Construct a WeavingAdaptor with a reference to aGeneratedClassHandler
, 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 classesaspectURLs
- the aspects used to weave classes defined by this class loader
-
-
Method Details
-
getFullClassPath
-
initializeCache
protected void initializeCache(ClassLoader loader, List<String> aspects, GeneratedClassHandler existingClassHandler, IMessageHandler myMessageHandler)If the cache is enabled, initialize it and swap out the existing classhandler for the caching one -- Parameters:
loader
- classloader for this adapter, may be nullaspects
- List of strings representing aspects managed by the adapter; these could be urls or classnamesexistingClassHandler
- current class handlermyMessageHandler
- current message handler
-
createMessageHandler
protected void createMessageHandler() -
getMessageHandler
-
getMessageHolder
-
setMessageHandler
-
disable
protected void disable() -
enable
protected void enable() -
isEnabled
protected boolean isEnabled() -
addURL
Appends URL to path used by the WeavingAdptor to resolve classes- Parameters:
url
- to be appended to search path
-
weaveClass
Weave a class using aspects previously supplied to the adaptor.- Parameters:
name
- the name of the classbytes
- the class bytes- Returns:
- the woven bytes
- Throws:
IOException
- weave failed
-
weaveClass
Weave a class using aspects previously supplied to the adaptor.- Parameters:
name
- the name of the classbytes
- the class bytesmustWeave
- if true then this class *must* get woven (used for concrete aspects generated from XML)- Returns:
- the woven bytes
- Throws:
IOException
- weave failed
-
accept
-
shouldDump
-
ensureDelegateInitialized
-
debug
-
info
-
warn
-
warn
-
error
-
error
-
getContextId
- Specified by:
getContextId
in interfaceIMessageContext
-
dump
Dump the given bytcode in _dump/... (dev mode)- Parameters:
name
-b
-before
- whether we are dumping before weaving
-
getDumpDir
- Returns:
- the directory in which to dump - default is _ajdump but it
-
setActiveProtectionDomain
-