Package org.osjava.jardiff
Class DOMDiffHandler
- java.lang.Object
-
- org.osjava.jardiff.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.NodecurrentNodeThe current Node.private org.w3c.dom.DocumentdocThe document object we're buildingprivate javax.xml.transform.ResultresultWhere we write the result to.private javax.xml.transform.TransformertransformerThe javax.xml.transform.sax.Transformer used to convert the DOM to text.static java.lang.StringXML_URIThe XML namespace used.
-
Constructor Summary
Constructors Constructor Description DOMDiffHandler()Create a new DOMDiffHandler which writes to System.outDOMDiffHandler(javax.xml.transform.Transformer transformer, javax.xml.transform.Result result)Create a new DOMDiffHandler with the specified Transformer and Result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAccessFlags(AbstractInfo info)Add attributes describing some access flags.protected voidaddMethodNodes(java.lang.String desc)Add the method nodes for the method descriptor.protected voidaddTypeNode(java.lang.String desc)Add a type node for the specified descriptor.protected voidaddTypeNode(org.objectweb.asm.Type type)Add a type node for the specified type.voidclassAdded(ClassInfo info)Write out the class info for an added class.voidclassChanged(ClassInfo oldInfo, ClassInfo newInfo)Write out info aboout a changed class.voidclassRemoved(ClassInfo info)Write out class info for a removed class.voidcontains(ClassInfo info)Add a contained class.voidendAdded()End the added section.voidendChanged()End the changed section.voidendClassChanged()End the changed section for an individual class.voidendDiff()End the diff.voidendNewContents()End the list of new contents.voidendOldContents()End the list of old contents.voidendRemoved()End the removed section.voidfieldAdded(FieldInfo info)Write out info about an added field.voidfieldChanged(FieldInfo oldInfo, FieldInfo newInfo)Write out info aboout a changed field.voidfieldRemoved(FieldInfo info)Write out info about a removed field.voidmethodAdded(MethodInfo info)Write out info about a added method.voidmethodChanged(MethodInfo oldInfo, MethodInfo newInfo)Write out info aboout a changed method.voidmethodRemoved(MethodInfo info)Write out info about a removed method.voidstartAdded()Start the added section.voidstartChanged()Start the changed section.voidstartClassChanged(java.lang.String internalName)Start a changed section for an individual class.voidstartDiff(java.lang.String oldJar, java.lang.String newJar)Start the diff.voidstartNewContents()Start the list of old contents.voidstartOldContents()Start the list of old contents.voidstartRemoved()Start the removed node.protected voidwriteClassInfo(ClassInfo info)Write out information about a class.protected voidwriteFieldInfo(FieldInfo info)Write out information about a field.protected voidwriteMethodInfo(MethodInfo info)Write out information about a method.
-
-
-
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 DiffExceptionCreate 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 DiffExceptionCreate 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 DiffExceptionStart the diff. This writes out the start of a <diff> node.- Specified by:
startDiffin interfaceDiffHandler- Parameters:
oldJar- ignorednewJar- ignored- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
startOldContents
public void startOldContents() throws DiffExceptionStart the list of old contents.- Specified by:
startOldContentsin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
startNewContents
public void startNewContents() throws DiffExceptionStart the list of old contents.- Specified by:
startNewContentsin interfaceDiffHandler- 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:
containsin interfaceDiffHandler- 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 DiffExceptionEnd the list of old contents.- Specified by:
endOldContentsin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
endNewContents
public void endNewContents() throws DiffExceptionEnd the list of new contents.- Specified by:
endNewContentsin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
startRemoved
public void startRemoved() throws DiffExceptionStart the removed node. This writes out a <removed> node.- Specified by:
startRemovedin interfaceDiffHandler- 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:
classRemovedin interfaceDiffHandler- 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 DiffExceptionEnd the removed section. This closes the <removed> tag.- Specified by:
endRemovedin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
startAdded
public void startAdded() throws DiffExceptionStart the added section. This opens the <added> tag.- Specified by:
startAddedin interfaceDiffHandler- 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:
classAddedin interfaceDiffHandler- 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 DiffExceptionEnd the added section. This closes the <added> tag.- Specified by:
endAddedin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
startChanged
public void startChanged() throws DiffExceptionStart the changed section. This writes out the <changed> node.- Specified by:
startChangedin interfaceDiffHandler- 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 DiffExceptionStart a changed section for an individual class. This writes out an <classchanged> node with the real class name as the name attribute.- Specified by:
startClassChangedin interfaceDiffHandler- 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:
fieldRemovedin interfaceDiffHandler- 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:
methodRemovedin interfaceDiffHandler- 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:
fieldAddedin interfaceDiffHandler- 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:
methodAddedin interfaceDiffHandler- 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:
classChangedin interfaceDiffHandler- 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:
fieldChangedin interfaceDiffHandler- 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:
methodChangedin interfaceDiffHandler- 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 DiffExceptionEnd the changed section for an individual class. This closes the <classchanged> node.- Specified by:
endClassChangedin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
endChanged
public void endChanged() throws DiffExceptionEnd the changed section. This closes the <changed> node.- Specified by:
endChangedin interfaceDiffHandler- Throws:
DiffException- when there is an underlying exception, e.g. writing to a file caused an IOException
-
endDiff
public void endDiff() throws DiffExceptionEnd the diff. This closes the <diff> node.- Specified by:
endDiffin interfaceDiffHandler- 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.
-
-