Package org.aspectj.weaver.tools
Class WeavingAdaptor
- java.lang.Object
-
- org.aspectj.weaver.tools.WeavingAdaptor
-
- All Implemented Interfaces:
org.aspectj.bridge.IMessageContext
- Direct Known Subclasses:
ClassLoaderWeavingAdaptor
public class WeavingAdaptor extends java.lang.Object implements org.aspectj.bridge.IMessageContextThis 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
WeavingAdaptorbefore 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
Nested Classes Modifier and Type Class Description protected classWeavingAdaptor.WeavingAdaptorMessageHolderProcesses messages arising from weaver operations.protected classWeavingAdaptor.WeavingAdaptorMessageWriter
-
Field Summary
Fields Modifier and Type Field Description protected java.security.ProtectionDomainactiveProtectionDomainprotected org.aspectj.weaver.bcel.BcelWorldbcelWorldprotected org.aspectj.weaver.tools.cache.WeavedClassCachecacheorg.aspectj.weaver.bcel.BcelObjectTypedelegateForCurrentClassprotected java.util.Map<java.lang.String,org.aspectj.weaver.IUnwovenClassFile>generatedClassesprotected org.aspectj.weaver.tools.GeneratedClassHandlergeneratedClassHandlerstatic java.lang.StringSHOW_WEAVE_INFO_PROPERTYstatic java.lang.StringTRACE_MESSAGES_PROPERTYprotected booleanverboseprotected org.aspectj.weaver.bcel.BcelWeaverweaverstatic java.lang.StringWEAVING_ADAPTOR_VERBOSESystem property used to turn on verbose weaving messages
-
Constructor Summary
Constructors Modifier Constructor Description protectedWeavingAdaptor()WeavingAdaptor(org.aspectj.weaver.tools.GeneratedClassHandler handler, java.net.URL[] classURLs, java.net.URL[] aspectURLs)Construct a WeavingAdaptor with a reference to aGeneratedClassHandler, a full search path for resolving classes and a complete set of aspects.WeavingAdaptor(org.aspectj.weaver.tools.WeavingClassLoader loader)Construct a WeavingAdaptor with a reference to a weaving class loader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanaccept(java.lang.String name, byte[] bytes)voidaddURL(java.net.URL url)Appends URL to path used by the WeavingAdptor to resolve classesprotected voidcreateMessageHandler()protected booleandebug(java.lang.String message)protected voiddisable()protected voiddump(java.lang.String name, byte[] b, boolean before)Dump the given bytcode in _dump/...protected voidenable()protected voidensureDelegateInitialized(java.lang.String name, byte[] bytes)protected booleanerror(java.lang.String message)protected booleanerror(java.lang.String message, java.lang.Throwable th)java.lang.StringgetContextId()protected java.lang.StringgetDumpDir()protected java.util.List<java.lang.String>getFullClassPath(java.lang.ClassLoader loader)protected org.aspectj.bridge.IMessageHandlergetMessageHandler()org.aspectj.bridge.IMessageHoldergetMessageHolder()protected booleaninfo(java.lang.String message)protected voidinitializeCache(java.lang.ClassLoader loader, java.util.List<java.lang.String> aspects, org.aspectj.weaver.tools.GeneratedClassHandler existingClassHandler, org.aspectj.bridge.IMessageHandler myMessageHandler)If the cache is enabled, initialize it and swap out the existing classhandler for the caching one -protected booleanisEnabled()voidsetActiveProtectionDomain(java.security.ProtectionDomain protectionDomain)protected voidsetMessageHandler(org.aspectj.bridge.IMessageHandler mh)protected booleanshouldDump(java.lang.String name, boolean before)protected booleanwarn(java.lang.String message)protected booleanwarn(java.lang.String message, java.lang.Throwable th)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.
-
-
-
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
-
verbose
protected boolean verbose
-
bcelWorld
protected org.aspectj.weaver.bcel.BcelWorld bcelWorld
-
weaver
protected org.aspectj.weaver.bcel.BcelWeaver weaver
-
generatedClassHandler
protected org.aspectj.weaver.tools.GeneratedClassHandler generatedClassHandler
-
generatedClasses
protected java.util.Map<java.lang.String,org.aspectj.weaver.IUnwovenClassFile> generatedClasses
-
delegateForCurrentClass
public org.aspectj.weaver.bcel.BcelObjectType delegateForCurrentClass
-
activeProtectionDomain
protected java.security.ProtectionDomain activeProtectionDomain
-
cache
protected org.aspectj.weaver.tools.cache.WeavedClassCache cache
-
-
Constructor Detail
-
WeavingAdaptor
protected WeavingAdaptor()
-
WeavingAdaptor
public WeavingAdaptor(org.aspectj.weaver.tools.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 for weaving.- Parameters:
loader- instance ofClassLoader
-
WeavingAdaptor
public WeavingAdaptor(org.aspectj.weaver.tools.GeneratedClassHandler handler, java.net.URL[] classURLs, java.net.URL[] aspectURLs)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-GeneratedClassHandlerclassURLs- the URLs from which to resolve classesaspectURLs- the aspects used to weave classes defined by this class loader
-
-
Method Detail
-
getFullClassPath
protected java.util.List<java.lang.String> getFullClassPath(java.lang.ClassLoader loader)
-
initializeCache
protected void initializeCache(java.lang.ClassLoader loader, java.util.List<java.lang.String> aspects, org.aspectj.weaver.tools.GeneratedClassHandler existingClassHandler, org.aspectj.bridge.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
protected org.aspectj.bridge.IMessageHandler getMessageHandler()
-
getMessageHolder
public org.aspectj.bridge.IMessageHolder getMessageHolder()
-
setMessageHandler
protected void setMessageHandler(org.aspectj.bridge.IMessageHandler mh)
-
disable
protected void disable()
-
enable
protected void enable()
-
isEnabled
protected boolean isEnabled()
-
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.IOExceptionWeave a class using aspects previously supplied to the adaptor.- Parameters:
name- the name of the classbytes- 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.IOExceptionWeave 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:
java.io.IOException- weave failed
-
accept
protected boolean accept(java.lang.String name, byte[] bytes)
-
shouldDump
protected boolean shouldDump(java.lang.String name, boolean before)
-
ensureDelegateInitialized
protected void ensureDelegateInitialized(java.lang.String name, byte[] bytes)
-
debug
protected boolean debug(java.lang.String message)
-
info
protected boolean info(java.lang.String message)
-
warn
protected boolean warn(java.lang.String message)
-
warn
protected boolean warn(java.lang.String message, java.lang.Throwable th)
-
error
protected boolean error(java.lang.String message)
-
error
protected boolean error(java.lang.String message, java.lang.Throwable th)
-
getContextId
public java.lang.String getContextId()
- Specified by:
getContextIdin interfaceorg.aspectj.bridge.IMessageContext
-
dump
protected void dump(java.lang.String name, byte[] b, boolean before)Dump the given bytcode in _dump/... (dev mode)- Parameters:
name-b-before- whether we are dumping before weaving- Throws:
java.lang.Throwable
-
getDumpDir
protected java.lang.String getDumpDir()
- Returns:
- the directory in which to dump - default is _ajdump but it
-
setActiveProtectionDomain
public void setActiveProtectionDomain(java.security.ProtectionDomain protectionDomain)
-
-