Package org.jrd.agent

Class Transformer

  • All Implemented Interfaces:
    java.lang.instrument.ClassFileTransformer

    public class Transformer
    extends java.lang.Object
    implements java.lang.instrument.ClassFileTransformer
    This class represent our transformer for retrieving bytecode.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean allowToSaveBytecode  
      private java.util.HashMap<java.lang.String,​byte[]> overrides  
      private java.util.HashMap<java.lang.String,​byte[]> results  
    • Constructor Summary

      Constructors 
      Constructor Description
      Transformer()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void allowToSaveBytecode()
      This method allows saving of bytecode
      void denyToSaveBytecode()
      This method denies the bytecode to be saved during transformation.
      byte[] getResult​(java.lang.String name)
      Returns bytecode of transformed class.
      void resetLastValidResult()
      Resets the map with results to empty map
      void resetOverrides()  
      void setOverride​(java.lang.String name, byte[] body)  
      byte[] transform​(java.lang.ClassLoader loader, java.lang.String className, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.instrument.ClassFileTransformer

        transform
    • Field Detail

      • allowToSaveBytecode

        private boolean allowToSaveBytecode
      • results

        private java.util.HashMap<java.lang.String,​byte[]> results
      • overrides

        private java.util.HashMap<java.lang.String,​byte[]> overrides
    • Constructor Detail

      • Transformer

        public Transformer()
    • Method Detail

      • transform

        public byte[] transform​(java.lang.ClassLoader loader,
                                java.lang.String className,
                                java.lang.Class<?> classBeingRedefined,
                                java.security.ProtectionDomain protectionDomain,
                                byte[] classfileBuffer)
                         throws java.lang.instrument.IllegalClassFormatException
        Specified by:
        transform in interface java.lang.instrument.ClassFileTransformer
        Throws:
        java.lang.instrument.IllegalClassFormatException
      • getResult

        public byte[] getResult​(java.lang.String name)
        Returns bytecode of transformed class.
        Parameters:
        name - name of class we want to get
        Returns:
        bytes of given class
      • setOverride

        public void setOverride​(java.lang.String name,
                                byte[] body)
      • resetLastValidResult

        public void resetLastValidResult()
        Resets the map with results to empty map
      • resetOverrides

        public void resetOverrides()
      • allowToSaveBytecode

        public void allowToSaveBytecode()
        This method allows saving of bytecode
      • denyToSaveBytecode

        public void denyToSaveBytecode()
        This method denies the bytecode to be saved during transformation.