public class DifferenceEngine extends java.lang.Object implements DifferenceConstants, DifferenceEngineContract
Modifier and Type | Class and Description |
---|---|
protected static class |
DifferenceEngine.DifferenceFoundException
Marker exception thrown by the protected compare() method and passed
upwards through the call stack to the public compare() method.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTRIBUTE_ABSENT |
private ComparisonController |
controller |
private XpathNodeTracker |
controlTracker |
private static DifferenceEngine.DifferenceFoundException |
flowControlException
Exception instance used internally to control flow
when a difference is found
|
private MatchTracker |
matchTracker |
private static java.lang.String |
NOT_NULL_NODE |
private static java.lang.String |
NULL_NODE |
private XpathNodeTracker |
testTracker |
ATTR_NAME_NOT_FOUND, ATTR_NAME_NOT_FOUND_ID, ATTR_SEQUENCE, ATTR_SEQUENCE_ID, ATTR_VALUE, ATTR_VALUE_EXPLICITLY_SPECIFIED, ATTR_VALUE_EXPLICITLY_SPECIFIED_ID, ATTR_VALUE_ID, CDATA_VALUE, CDATA_VALUE_ID, CHILD_NODE_NOT_FOUND, CHILD_NODE_NOT_FOUND_ID, CHILD_NODELIST_LENGTH, CHILD_NODELIST_LENGTH_ID, CHILD_NODELIST_SEQUENCE, CHILD_NODELIST_SEQUENCE_ID, COMMENT_VALUE, COMMENT_VALUE_ID, DOCTYPE_NAME, DOCTYPE_NAME_ID, DOCTYPE_PUBLIC_ID, DOCTYPE_PUBLIC_ID_ID, DOCTYPE_SYSTEM_ID, DOCTYPE_SYSTEM_ID_ID, ELEMENT_NUM_ATTRIBUTES, ELEMENT_NUM_ATTRIBUTES_ID, ELEMENT_TAG_NAME, ELEMENT_TAG_NAME_ID, HAS_CHILD_NODES, HAS_CHILD_NODES_ID, HAS_DOCTYPE_DECLARATION, HAS_DOCTYPE_DECLARATION_ID, NAMESPACE_PREFIX, NAMESPACE_PREFIX_ID, NAMESPACE_URI, NAMESPACE_URI_ID, NO_NAMESPACE_SCHEMA_LOCATION, NO_NAMESPACE_SCHEMA_LOCATION_ID, NODE_TYPE, NODE_TYPE_ID, PROCESSING_INSTRUCTION_DATA, PROCESSING_INSTRUCTION_DATA_ID, PROCESSING_INSTRUCTION_TARGET, PROCESSING_INSTRUCTION_TARGET_ID, SCHEMA_LOCATION, SCHEMA_LOCATION_ID, TEXT_VALUE, TEXT_VALUE_ID
Constructor and Description |
---|
DifferenceEngine(ComparisonController controller)
Simple constructor that uses no MatchTracker at all.
|
DifferenceEngine(ComparisonController controller,
MatchTracker matchTracker)
Simple constructor
|
Modifier and Type | Method and Description |
---|---|
void |
compare(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener,
ElementQualifier elementQualifier)
Entry point for Node comparison testing.
|
protected void |
compare(java.lang.Object expected,
java.lang.Object actual,
org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener,
Difference difference)
If the expected and actual values are unequal then inform the listener of
a difference and throw a DifferenceFoundException.
|
protected void |
compare(java.lang.Object expected,
java.lang.Object actual,
org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener,
Difference difference,
XpathNodeTracker controlLoc,
XpathNodeTracker testLoc)
If the expected and actual values are unequal then inform the listener of
a difference and throw a DifferenceFoundException.
|
protected void |
compareAttribute(org.w3c.dom.Attr control,
org.w3c.dom.Attr test,
DifferenceListener listener)
Compare two attributes
|
protected void |
compareCDataSection(org.w3c.dom.CDATASection control,
org.w3c.dom.CDATASection test,
DifferenceListener listener)
Compare two CDATA sections - unused, kept for backwards compatibility
|
private void |
compareCharacterData(org.w3c.dom.CharacterData control,
org.w3c.dom.CharacterData test,
DifferenceListener listener,
Difference difference)
Character comparison method used by comments, text and CDATA sections
|
protected void |
compareComment(org.w3c.dom.Comment control,
org.w3c.dom.Comment test,
DifferenceListener listener)
Compare two comments
|
protected void |
compareDocument(org.w3c.dom.Document control,
org.w3c.dom.Document test,
DifferenceListener listener,
ElementQualifier elementQualifier)
Compare two Documents for doctype and then element differences
|
protected void |
compareDocumentType(org.w3c.dom.DocumentType control,
org.w3c.dom.DocumentType test,
DifferenceListener listener)
Compare two DocumentType nodes
|
protected void |
compareElement(org.w3c.dom.Element control,
org.w3c.dom.Element test,
DifferenceListener listener)
Compare 2 elements and their attributes
|
(package private) void |
compareElementAttributes(org.w3c.dom.Element control,
org.w3c.dom.Element test,
org.w3c.dom.NamedNodeMap controlAttr,
org.w3c.dom.NamedNodeMap testAttr,
DifferenceListener listener) |
protected void |
compareHasChildNodes(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener)
Compare the number of children, and if the same, compare the actual
children via their NodeLists.
|
protected void |
compareNode(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener,
ElementQualifier elementQualifier)
First point of call: if nodes are comparable it compares node values then
recurses to compare node children.
|
protected boolean |
compareNodeBasics(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener)
Compares node type and node namespace characteristics: basically
determines if nodes are comparable further
|
protected void |
compareNodeChildren(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener,
ElementQualifier elementQualifier)
Compare the number of children, and if the same, compare the actual
children via their NodeLists.
|
protected void |
compareNodeList(java.util.List<org.w3c.dom.Node> controlChildren,
java.util.List<org.w3c.dom.Node> testChildren,
int numNodes,
DifferenceListener listener,
ElementQualifier elementQualifier)
Compare the contents of two node list one by one, assuming that order
of children is NOT important: matching begins at same position in test
list as control list.
|
protected void |
compareProcessingInstruction(org.w3c.dom.ProcessingInstruction control,
org.w3c.dom.ProcessingInstruction test,
DifferenceListener listener)
Compare two processing instructions
|
protected void |
compareRecognizedXMLSchemaInstanceAttribute(org.w3c.dom.Attr control,
org.w3c.dom.Attr test,
DifferenceListener listener)
Compare two attributes
|
protected void |
compareText(org.w3c.dom.CharacterData control,
org.w3c.dom.CharacterData test,
DifferenceListener listener)
Compare text
|
protected void |
compareText(org.w3c.dom.Text control,
org.w3c.dom.Text test,
DifferenceListener listener)
Compare text - unused, kept for backwards compatibility
|
private boolean |
comparingTextAndCDATA(short controlType,
short testType) |
private java.lang.Integer |
getNonSpecialAttrLength(org.w3c.dom.NamedNodeMap attributes)
The number of attributes not related to namespace declarations
and/or Schema location.
|
private static java.lang.String |
getNullOrNotNull(org.w3c.dom.Node aNode) |
private java.lang.String |
getQName(org.w3c.dom.Node aNode) |
private static java.lang.String |
getQName(org.w3c.dom.Node aNode,
boolean isNamespacedNode) |
private java.lang.String |
getUnNamespacedNodeName(org.w3c.dom.Node aNode) |
private static java.lang.String |
getUnNamespacedNodeName(org.w3c.dom.Node aNode,
boolean isNamespacedNode) |
private java.lang.Boolean |
hasChildNodes(org.w3c.dom.Node n)
Tests whether a Node has children, taking ignoreComments
setting into account.
|
private static boolean |
isNamespaced(org.w3c.dom.Node aNode) |
private boolean |
isRecognizedXMLSchemaInstanceAttribute(org.w3c.dom.Attr attr) |
private boolean |
isXMLNSAttribute(org.w3c.dom.Attr attribute) |
private void |
missingNode(org.w3c.dom.Node control,
org.w3c.dom.Node test,
DifferenceListener listener) |
(package private) static java.util.List<org.w3c.dom.Node> |
nodeList2List(org.w3c.dom.NodeList nl)
Returns the NodeList's Nodes as List, taking ignoreComments
into account.
|
(package private) static java.lang.String |
normalizeWhitespace(java.lang.String orig)
Replace all whitespace characters with SPACE and collapse
consecutive whitespace chars to a single SPACE.
|
void |
setMatchTracker(MatchTracker matchTracker) |
private boolean |
unequal(java.lang.Object expected,
java.lang.Object actual)
Test two possibly null values for inequality
|
private boolean |
unequalNotNull(java.lang.Object expected,
java.lang.Object actual)
Test two non-null values for inequality
|
private static final DifferenceEngine.DifferenceFoundException flowControlException
private static final java.lang.String NULL_NODE
private static final java.lang.String NOT_NULL_NODE
private static final java.lang.String ATTRIBUTE_ABSENT
private final ComparisonController controller
private MatchTracker matchTracker
private final XpathNodeTracker controlTracker
private final XpathNodeTracker testTracker
public DifferenceEngine(ComparisonController controller)
controller
- the instance used to determine whether a Difference
detected by this class should halt further comparison or notComparisonController.haltComparison(Difference)
public DifferenceEngine(ComparisonController controller, MatchTracker matchTracker)
controller
- the instance used to determine whether a Difference
detected by this class should halt further comparison or notmatchTracker
- the instance that is notified on each
successful match. May be null.ComparisonController.haltComparison(Difference)
,
MatchTracker.matchFound(Difference)
public void setMatchTracker(MatchTracker matchTracker)
setMatchTracker
in interface DifferenceEngineContract
matchTracker
- the instance that is notified on each
successful match. May be null.public void compare(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener, ElementQualifier elementQualifier)
compare
in interface DifferenceEngineContract
control
- Control XML to comparetest
- Test XML to comparelistener
- Notified of any differences
detected
during node comparison testingelementQualifier
- Used to determine which elements qualify for
comparison e.g. when a node has repeated child elements that may occur
in any sequence and that sequence is not considered important.private static java.lang.String getNullOrNotNull(org.w3c.dom.Node aNode)
protected void compareNode(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- elementQualifier
- DifferenceEngine.DifferenceFoundException
protected void compareDocument(org.w3c.dom.Document control, org.w3c.dom.Document test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- elementQualifier
- DifferenceEngine.DifferenceFoundException
protected boolean compareNodeBasics(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
private boolean comparingTextAndCDATA(short controlType, short testType)
protected void compareHasChildNodes(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
private java.lang.Boolean hasChildNodes(org.w3c.dom.Node n)
static java.util.List<org.w3c.dom.Node> nodeList2List(org.w3c.dom.NodeList nl)
protected void compareNodeChildren(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- elementQualifier
- DifferenceEngine.DifferenceFoundException
protected void compareNodeList(java.util.List<org.w3c.dom.Node> controlChildren, java.util.List<org.w3c.dom.Node> testChildren, int numNodes, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
controlChildren
- testChildren
- numNodes
- convenience parameter because the calling method should
know the value alreadylistener
- elementQualifier
- used to determine which of the child elements in
the test NodeList should be compared to the current child element in the
control NodeList.DifferenceEngine.DifferenceFoundException
private void missingNode(org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
private static boolean isNamespaced(org.w3c.dom.Node aNode)
aNode
- protected void compareElement(org.w3c.dom.Element control, org.w3c.dom.Element test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
private java.lang.Integer getNonSpecialAttrLength(org.w3c.dom.NamedNodeMap attributes)
void compareElementAttributes(org.w3c.dom.Element control, org.w3c.dom.Element test, org.w3c.dom.NamedNodeMap controlAttr, org.w3c.dom.NamedNodeMap testAttr, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
private java.lang.String getUnNamespacedNodeName(org.w3c.dom.Node aNode)
private static java.lang.String getUnNamespacedNodeName(org.w3c.dom.Node aNode, boolean isNamespacedNode)
private java.lang.String getQName(org.w3c.dom.Node aNode)
private static java.lang.String getQName(org.w3c.dom.Node aNode, boolean isNamespacedNode)
private boolean isXMLNSAttribute(org.w3c.dom.Attr attribute)
attribute
- private boolean isRecognizedXMLSchemaInstanceAttribute(org.w3c.dom.Attr attr)
attr
- protected void compareRecognizedXMLSchemaInstanceAttribute(org.w3c.dom.Attr control, org.w3c.dom.Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareAttribute(org.w3c.dom.Attr control, org.w3c.dom.Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareCDataSection(org.w3c.dom.CDATASection control, org.w3c.dom.CDATASection test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareComment(org.w3c.dom.Comment control, org.w3c.dom.Comment test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareDocumentType(org.w3c.dom.DocumentType control, org.w3c.dom.DocumentType test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareProcessingInstruction(org.w3c.dom.ProcessingInstruction control, org.w3c.dom.ProcessingInstruction test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareText(org.w3c.dom.Text control, org.w3c.dom.Text test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
protected void compareText(org.w3c.dom.CharacterData control, org.w3c.dom.CharacterData test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- DifferenceEngine.DifferenceFoundException
private void compareCharacterData(org.w3c.dom.CharacterData control, org.w3c.dom.CharacterData test, DifferenceListener listener, Difference difference) throws DifferenceEngine.DifferenceFoundException
control
- test
- listener
- difference
- DifferenceEngine.DifferenceFoundException
protected void compare(java.lang.Object expected, java.lang.Object actual, org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener, Difference difference) throws DifferenceEngine.DifferenceFoundException
expected
- actual
- control
- test
- listener
- difference
- DifferenceEngine.DifferenceFoundException
protected void compare(java.lang.Object expected, java.lang.Object actual, org.w3c.dom.Node control, org.w3c.dom.Node test, DifferenceListener listener, Difference difference, XpathNodeTracker controlLoc, XpathNodeTracker testLoc) throws DifferenceEngine.DifferenceFoundException
expected
- actual
- control
- test
- listener
- difference
- controlLoc
- testLoc
- DifferenceEngine.DifferenceFoundException
private boolean unequal(java.lang.Object expected, java.lang.Object actual)
expected
- actual
- private boolean unequalNotNull(java.lang.Object expected, java.lang.Object actual)
expected
- actual
- static final java.lang.String normalizeWhitespace(java.lang.String orig)