OpenOffice.org
XMerge API

org.openoffice.xmerge.merger.diff
Class NodeIterator

java.lang.Object
  |
  +--org.openoffice.xmerge.merger.diff.NodeIterator
All Implemented Interfaces:
Iterator
Direct Known Subclasses:
CellNodeIterator, ParaNodeIterator, RowIterator, TextNodeIterator

public abstract class NodeIterator
extends java.lang.Object
implements Iterator

This is an implementation of the Iterator interface. It will traverse the tree and find Node sequences.

Note: Once the XML Tree is parsed, then the Iterator will be a snap shot of that tree. That means even the tree is modified later, than the cached paragraph Node list will not be updated accordingly. For this reason and for performance reasons this Iterator does not support any operation methods such as insert, remove or replace. The main purpose of this Iterator is to be used with difference, not with merge.


Constructor Summary
NodeIterator(ConverterCapabilities cc, org.w3c.dom.Node node)
          Standard constructor.
 
Method Summary
protected  boolean attributesEqual(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
          Compare attributes of two Node objects.
protected  boolean childrenEqual(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
          Compare the children of two Node objects.
protected  boolean compareNode(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
          Used to compare two Node objects (type/name/value) and all their children Node objects.
 java.lang.Object currentElement()
          Return the current element Object content.
 int elementCount()
          Return the total element count in the sequence.
 java.lang.Object end()
          Move to the end of the sequence.
 boolean equivalent(java.lang.Object obj1, java.lang.Object obj2)
          A method to allow the difference algorithm to test whether the obj1 and obj2 in the Iterator are considered equal.
 java.lang.Object next()
          Move to next element in the sequence.
protected abstract  boolean nodeSupported(org.w3c.dom.Node node)
          Check whether a Node is supported.
 java.lang.Object previous()
          Move to previous element in the sequence.
 void refresh()
          A method to force the Iterator to transverse the tree again to refresh the content.
 java.lang.Object start()
          Move to the beginning of the sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeIterator

public NodeIterator(ConverterCapabilities cc,
                    org.w3c.dom.Node node)
Standard constructor.
Parameters:
cc - The ConverterCapabilities.
node - The initial root Node.
Method Detail

attributesEqual

protected boolean attributesEqual(org.w3c.dom.Node node1,
                                  org.w3c.dom.Node node2)
Compare attributes of two Node objects. This method can be intentionally overridden by any class that extends from NodeIterator so that it can have its own attribute comparison.
Parameters:
node1 - The first Node to compare.
node2 - The second Node to compare.
Returns:
true if attributes are equal, false otherwise.

childrenEqual

protected boolean childrenEqual(org.w3c.dom.Node node1,
                                org.w3c.dom.Node node2)
Compare the children of two Node objects. This method can be intentionally overridden by any class that extend from NodeIterator so that it can have its own children comparison if necessary.
Parameters:
node1 - The first Node to compare.
node2 - The second Node to compare.
Returns:
true if children are equal, false otherwise.

compareNode

protected boolean compareNode(org.w3c.dom.Node node1,
                              org.w3c.dom.Node node2)
Used to compare two Node objects (type/name/value) and all their children Node objects.
Parameters:
node1 - The first Node to compare.
node2 - The second Node to compare.
Returns:
true if Node is equal, false otherwise.

currentElement

public java.lang.Object currentElement()
Description copied from interface: Iterator
Return the current element Object content.
Specified by:
currentElement in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The Object at current position.

elementCount

public int elementCount()
Description copied from interface: Iterator
Return the total element count in the sequence.
Specified by:
elementCount in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The total element count.

end

public java.lang.Object end()
Description copied from interface: Iterator
Move to the end of the sequence.
Specified by:
end in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The Object of the last element in the sequence. If it is empty, then return null.

equivalent

public boolean equivalent(java.lang.Object obj1,
                          java.lang.Object obj2)
Description copied from interface: Iterator
A method to allow the difference algorithm to test whether the obj1 and obj2 in the Iterator are considered equal. As not every Object in the Iterator can implement its own equal method, with this equivalent method, we can allow flexibility for the Iterator to choose a custom way to compare two objects. Two objects can even be compared based on the position in the Iterator rather than by the content via this option.
Specified by:
equivalent in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Parameters:
obj1 - The first Object.
obj2 - The second Object.
Returns:
true if equal, false otherwise.

next

public java.lang.Object next()
Description copied from interface: Iterator
Move to next element in the sequence.
Specified by:
next in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The Object of the next element in the sequence. If there is no next element, then return null.

nodeSupported

protected abstract boolean nodeSupported(org.w3c.dom.Node node)
Check whether a Node is supported. This method can be intentionally overridden by any class that extends from NodeIterator so that it can specify which Node to support.
Parameters:
node - Node to check.
Returns:
true if Node is supported, false otherwise.

previous

public java.lang.Object previous()
Description copied from interface: Iterator
Move to previous element in the sequence.
Specified by:
previous in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The Object of the previous element in the sequence. If there is no previous element, then return null.

refresh

public void refresh()
Description copied from interface: Iterator

A method to force the Iterator to transverse the tree again to refresh the content.

It is used mainly for Iterator objects which take a snap shot instead of dynamically transversing the tree. The current position will be set to the beginning.

Specified by:
refresh in interface Iterator

start

public java.lang.Object start()
Description copied from interface: Iterator
Move to the beginning of the sequence.
Specified by:
start in interface Iterator
Following copied from interface: org.openoffice.xmerge.merger.Iterator
Returns:
The Object of the first element in the sequence. If it is empty, then return null.

OpenOffice.org
XMerge API

Copyright © 2002 OpenOffice.org