Class DOMDiffHandler

  • All Implemented Interfaces:
    DiffHandler

    public class DOMDiffHandler
    extends java.lang.Object
    implements DiffHandler
    A specific type of DiffHandler which uses DOM to create an XML document describing the changes in the diff.
    Author:
    Antony Riley
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.w3c.dom.Node currentNode
      The current Node.
      private org.w3c.dom.Document doc
      The document object we're building
      private javax.xml.transform.Result result
      Where we write the result to.
      private javax.xml.transform.Transformer transformer
      The javax.xml.transform.sax.Transformer used to convert the DOM to text.
      static java.lang.String XML_URI
      The XML namespace used.
    • Constructor Summary

      Constructors 
      Constructor Description
      DOMDiffHandler()
      Create a new DOMDiffHandler which writes to System.out
      DOMDiffHandler​(javax.xml.transform.Transformer transformer, javax.xml.transform.Result result)
      Create a new DOMDiffHandler with the specified Transformer and Result.
    • Field Detail

      • XML_URI

        public static final java.lang.String XML_URI
        The XML namespace used.
        See Also:
        Constant Field Values
      • transformer

        private final javax.xml.transform.Transformer transformer
        The javax.xml.transform.sax.Transformer used to convert the DOM to text.
      • result

        private final javax.xml.transform.Result result
        Where we write the result to.
      • doc

        private final org.w3c.dom.Document doc
        The document object we're building
      • currentNode

        private org.w3c.dom.Node currentNode
        The current Node.
    • Constructor Detail

      • DOMDiffHandler

        public DOMDiffHandler()
                       throws DiffException
        Create a new DOMDiffHandler which writes to System.out
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • DOMDiffHandler

        public DOMDiffHandler​(javax.xml.transform.Transformer transformer,
                              javax.xml.transform.Result result)
                       throws DiffException
        Create a new DOMDiffHandler with the specified Transformer and Result. This method allows the user to choose what they are going to do with the output in a flexible manner, allowing a stylesheet to be specified and some result object.
        Parameters:
        transformer - The transformer to transform the output with.
        result - Where to put the result.
        Throws:
        DiffException
    • Method Detail

      • startDiff

        public void startDiff​(java.lang.String oldJar,
                              java.lang.String newJar)
                       throws DiffException
        Start the diff. This writes out the start of a <diff> node.
        Specified by:
        startDiff in interface DiffHandler
        Parameters:
        oldJar - ignored
        newJar - ignored
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startOldContents

        public void startOldContents()
                              throws DiffException
        Start the list of old contents.
        Specified by:
        startOldContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startNewContents

        public void startNewContents()
                              throws DiffException
        Start the list of old contents.
        Specified by:
        startNewContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • contains

        public void contains​(ClassInfo info)
                      throws DiffException
        Add a contained class.
        Specified by:
        contains in interface DiffHandler
        Parameters:
        info - information about a class
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endOldContents

        public void endOldContents()
                            throws DiffException
        End the list of old contents.
        Specified by:
        endOldContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endNewContents

        public void endNewContents()
                            throws DiffException
        End the list of new contents.
        Specified by:
        endNewContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startRemoved

        public void startRemoved()
                          throws DiffException
        Start the removed node. This writes out a <removed> node.
        Specified by:
        startRemoved in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classRemoved

        public void classRemoved​(ClassInfo info)
                          throws DiffException
        Write out class info for a removed class. This writes out the nodes describing a class
        Specified by:
        classRemoved in interface DiffHandler
        Parameters:
        info - The info to write out.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endRemoved

        public void endRemoved()
                        throws DiffException
        End the removed section. This closes the <removed> tag.
        Specified by:
        endRemoved in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startAdded

        public void startAdded()
                        throws DiffException
        Start the added section. This opens the <added> tag.
        Specified by:
        startAdded in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classAdded

        public void classAdded​(ClassInfo info)
                        throws DiffException
        Write out the class info for an added class. This writes out the nodes describing an added class.
        Specified by:
        classAdded in interface DiffHandler
        Parameters:
        info - The class info describing the added class.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endAdded

        public void endAdded()
                      throws DiffException
        End the added section. This closes the <added> tag.
        Specified by:
        endAdded in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startChanged

        public void startChanged()
                          throws DiffException
        Start the changed section. This writes out the <changed> node.
        Specified by:
        startChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startClassChanged

        public void startClassChanged​(java.lang.String internalName)
                               throws DiffException
        Start a changed section for an individual class. This writes out an <classchanged> node with the real class name as the name attribute.
        Specified by:
        startClassChanged in interface DiffHandler
        Parameters:
        internalName - the internal name of the class that has changed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldRemoved

        public void fieldRemoved​(FieldInfo info)
                          throws DiffException
        Write out info about a removed field. This just writes out the field info, it will be inside a start/end removed section.
        Specified by:
        fieldRemoved in interface DiffHandler
        Parameters:
        info - Info about the field that's been removed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodRemoved

        public void methodRemoved​(MethodInfo info)
                           throws DiffException
        Write out info about a removed method. This just writes out the method info, it will be inside a start/end removed section.
        Specified by:
        methodRemoved in interface DiffHandler
        Parameters:
        info - Info about the method that's been removed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldAdded

        public void fieldAdded​(FieldInfo info)
                        throws DiffException
        Write out info about an added field. This just writes out the field info, it will be inside a start/end added section.
        Specified by:
        fieldAdded in interface DiffHandler
        Parameters:
        info - Info about the added field.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodAdded

        public void methodAdded​(MethodInfo info)
                         throws DiffException
        Write out info about a added method. This just writes out the method info, it will be inside a start/end added section.
        Specified by:
        methodAdded in interface DiffHandler
        Parameters:
        info - Info about the added method.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classChanged

        public void classChanged​(ClassInfo oldInfo,
                                 ClassInfo newInfo)
                          throws DiffException
        Write out info aboout a changed class. This writes out a <classchange> node, followed by a <from> node, with the old information about the class followed by a <to> node with the new information about the class.
        Specified by:
        classChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old class.
        newInfo - Info about the new class.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldChanged

        public void fieldChanged​(FieldInfo oldInfo,
                                 FieldInfo newInfo)
                          throws DiffException
        Write out info aboout a changed field. This writes out a <fieldchange> node, followed by a <from> node, with the old information about the field followed by a <to> node with the new information about the field.
        Specified by:
        fieldChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old field.
        newInfo - Info about the new field.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodChanged

        public void methodChanged​(MethodInfo oldInfo,
                                  MethodInfo newInfo)
                           throws DiffException
        Write out info aboout a changed method. This writes out a <methodchange> node, followed by a <from> node, with the old information about the method followed by a <to> node with the new information about the method.
        Specified by:
        methodChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old method.
        newInfo - Info about the new method.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endClassChanged

        public void endClassChanged()
                             throws DiffException
        End the changed section for an individual class. This closes the <classchanged> node.
        Specified by:
        endClassChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endChanged

        public void endChanged()
                        throws DiffException
        End the changed section. This closes the <changed> node.
        Specified by:
        endChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endDiff

        public void endDiff()
                     throws DiffException
        End the diff. This closes the <diff> node.
        Specified by:
        endDiff in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • writeClassInfo

        protected void writeClassInfo​(ClassInfo info)
        Write out information about a class. This writes out a <class> node, which contains information about what interfaces are implemented each in a <implements> node.
        Parameters:
        info - Info about the class to write out.
      • writeMethodInfo

        protected void writeMethodInfo​(MethodInfo info)
        Write out information about a method. This writes out a <method> node which contains information about the arguments, the return type, and the exceptions thrown by the method.
        Parameters:
        info - Info about the method.
      • writeFieldInfo

        protected void writeFieldInfo​(FieldInfo info)
        Write out information about a field. This writes out a <field> node with attributes describing the field.
        Parameters:
        info - Info about the field.
      • addAccessFlags

        protected void addAccessFlags​(AbstractInfo info)
        Add attributes describing some access flags. This adds the attributes to the attr field.
        Parameters:
        info - Info describing the access flags.
        See Also:
        #attr
      • addMethodNodes

        protected void addMethodNodes​(java.lang.String desc)
        Add the method nodes for the method descriptor. This writes out an <arguments> node containing the argument types for the method, followed by a <return> node containing the return type.
        Parameters:
        desc - The descriptor for the method to write out.
      • addTypeNode

        protected void addTypeNode​(java.lang.String desc)
        Add a type node for the specified descriptor.
        Parameters:
        desc - A type descriptor.
      • addTypeNode

        protected void addTypeNode​(org.objectweb.asm.Type type)
        Add a type node for the specified type. This writes out a <type> node with attributes describing the type.
        Parameters:
        type - The type to describe.