org.apache.commons.configuration.tree.xpath

Class ConfigurationNodeIteratorBase

abstract class ConfigurationNodeIteratorBase extends Object implements NodeIterator

A base class for implementing iterators over configuration nodes.

This class already provides common functionality for implementing the iteration process. Derived classes will implement specific behavior based on the concrete node type (child node or attribute node).

Since: 1.3

Version: $Id: ConfigurationNodeIteratorBase.java 439648 2006-09-02 20:42:10Z oheger $

Author: Oliver Heger

Field Summary
NodePointerparent
Stores the parent node pointer.
intposition
Stores the current position.
booleanreverse
Stores the reverse flag.
intstartOffset
Stores the start offset of the iterator.
ListsubNodes
Stores the list with the sub nodes.
Constructor Summary
protected ConfigurationNodeIteratorBase(NodePointer parent, boolean reverse)
Creates a new instance of ConfigurationNodeIteratorBase and initializes it.
Method Summary
protected NodePointercreateNodePointer(ConfigurationNode node)
Creates the configuration node pointer for the current position.
protected intgetMaxPosition()
Returns the maximum position for this iterator.
NodePointergetNodePointer()
Returns the current node pointer.
protected NodePointergetParent()
Returns the parent node pointer.
intgetPosition()
Returns the position of the iteration.
protected intgetStartOffset()
Returns the start offset of the iteration.
protected voidinitSubNodeList(List nodes)
Initializes the list of sub nodes for the iteration.
protected intpositionToIndex(int pos)
Returns the index in the data list for the given position.
booleansetPosition(int pos)
Sets the position of the iteration.
protected voidsetStartOffset(int startOffset)
Sets the start offset of the iteration.

Field Detail

parent

private NodePointer parent
Stores the parent node pointer.

position

private int position
Stores the current position.

reverse

private boolean reverse
Stores the reverse flag.

startOffset

private int startOffset
Stores the start offset of the iterator.

subNodes

private List subNodes
Stores the list with the sub nodes.

Constructor Detail

ConfigurationNodeIteratorBase

protected ConfigurationNodeIteratorBase(NodePointer parent, boolean reverse)
Creates a new instance of ConfigurationNodeIteratorBase and initializes it.

Parameters: parent the parent pointer reverse the reverse flag

Method Detail

createNodePointer

protected NodePointer createNodePointer(ConfigurationNode node)
Creates the configuration node pointer for the current position. This method is called by getNodePointer(). Derived classes must create the correct pointer object.

Parameters: node the current configuration node

Returns: the node pointer

getMaxPosition

protected int getMaxPosition()
Returns the maximum position for this iterator.

Returns: the maximum allowed position

getNodePointer

public NodePointer getNodePointer()
Returns the current node pointer.

Returns: the current pointer in this iteration

getParent

protected NodePointer getParent()
Returns the parent node pointer.

Returns: the parent node pointer

getPosition

public int getPosition()
Returns the position of the iteration.

Returns: the position

getStartOffset

protected int getStartOffset()
Returns the start offset of the iteration.

Returns: the start offset

initSubNodeList

protected void initSubNodeList(List nodes)
Initializes the list of sub nodes for the iteration. This method must be called during initialization phase.

Parameters: nodes the list with the sub nodes

positionToIndex

protected int positionToIndex(int pos)
Returns the index in the data list for the given position. This method also checks the reverse flag.

Parameters: pos the position (1-based)

Returns: the corresponding list index

setPosition

public boolean setPosition(int pos)
Sets the position of the iteration.

Parameters: pos the new position

Returns: a flag if this is a valid position

setStartOffset

protected void setStartOffset(int startOffset)
Sets the start offset of the iteration. This is used when a start element was set.

Parameters: startOffset the start offset