Klasse WeavingAdaptor

java.lang.Object
org.aspectj.weaver.tools.WeavingAdaptor
Alle implementierten Schnittstellen:
IMessageContext
Bekannte direkte Unterklassen:
ClassLoaderWeavingAdaptor

public class WeavingAdaptor extends 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.

  • Felddetails

  • Konstruktordetails

    • WeavingAdaptor

      protected WeavingAdaptor()
    • 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 for weaving.
      Parameter:
      loader - instance of ClassLoader
    • WeavingAdaptor

      public WeavingAdaptor(GeneratedClassHandler handler, URL[] classURLs, URL[] aspectURLs)
      Construct a WeavingAdaptor 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.
      Parameter:
      handler - GeneratedClassHandler
      classURLs - the URLs from which to resolve classes
      aspectURLs - the aspects used to weave classes defined by this class loader
  • Methodendetails

    • getFullClassPath

      protected List<String> getFullClassPath(ClassLoader loader)
    • 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 -
      Parameter:
      loader - classloader for this adapter, may be null
      aspects - List of strings representing aspects managed by the adapter; these could be urls or classnames
      existingClassHandler - current class handler
      myMessageHandler - current message handler
    • createMessageHandler

      protected void createMessageHandler()
    • getMessageHandler

      protected IMessageHandler getMessageHandler()
    • getMessageHolder

      public IMessageHolder getMessageHolder()
    • setMessageHandler

      protected void setMessageHandler(IMessageHandler mh)
    • disable

      protected void disable()
    • enable

      protected void enable()
    • isEnabled

      protected boolean isEnabled()
    • addURL

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

      public byte[] weaveClass(String name, byte[] bytes) throws IOException
      Weave a class using aspects previously supplied to the adaptor.
      Parameter:
      name - the name of the class
      bytes - the class bytes
      Gibt zurück:
      the woven bytes
      Löst aus:
      IOException - weave failed
    • weaveClass

      public byte[] weaveClass(String name, byte[] bytes, boolean mustWeave) throws IOException
      Weave a class using aspects previously supplied to the adaptor.
      Parameter:
      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)
      Gibt zurück:
      the woven bytes
      Löst aus:
      IOException - weave failed
    • accept

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

      protected boolean shouldDump(String name, boolean before)
    • ensureDelegateInitialized

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

      protected boolean debug(String message)
    • info

      protected boolean info(String message)
    • warn

      protected boolean warn(String message)
    • warn

      protected boolean warn(String message, Throwable th)
    • error

      protected boolean error(String message)
    • error

      protected boolean error(String message, Throwable th)
    • getContextId

      public String getContextId()
      Angegeben von:
      getContextId in Schnittstelle IMessageContext
    • dump

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

      protected String getDumpDir()
      Gibt zurück:
      the directory in which to dump - default is _ajdump but it
    • setActiveProtectionDomain

      public void setActiveProtectionDomain(ProtectionDomain protectionDomain)