Class AbstractConfigurationNodeIterator<T>
- java.lang.Object
-
- org.apache.commons.configuration2.tree.xpath.AbstractConfigurationNodeIterator<T>
-
- Type Parameters:
T
- the type of the nodes this iterator deals with
- All Implemented Interfaces:
org.apache.commons.jxpath.ri.model.NodeIterator
- Direct Known Subclasses:
ConfigurationNodeIteratorAttribute
,ConfigurationNodeIteratorChildren
abstract class AbstractConfigurationNodeIterator<T> extends java.lang.Object implements org.apache.commons.jxpath.ri.model.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
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
FMT_NAMESPACE
A format for constructing a node name with a namespace prefix.private ConfigurationNodePointer<T>
parent
Stores the parent node pointer.private int
position
Stores the current position.private static java.lang.String
PREFIX_SEPARATOR
Constant for the prefix separator.private boolean
reverse
Stores the reverse flag.private int
startOffset
Stores the start offset of the iterator.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConfigurationNodeIterator(ConfigurationNodePointer<T> parent, boolean reverse)
Creates a new instance ofConfigurationNodeIteratorBase
and initializes it.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract org.apache.commons.jxpath.ri.model.NodePointer
createNodePointer(int position)
Creates the configuration node pointer for the current position.protected int
getMaxPosition()
Gets the maximum position for this iterator.protected NodeHandler<T>
getNodeHandler()
Gets the node handler for the managed nodes.org.apache.commons.jxpath.ri.model.NodePointer
getNodePointer()
Gets the current node pointer.protected ConfigurationNodePointer<T>
getParent()
Gets the parent node pointer.int
getPosition()
Gets the position of the iteration.protected int
getStartOffset()
Gets the start offset of the iteration.protected int
positionToIndex(int pos)
Returns the index in the data list for the given position.protected static java.lang.String
prefixName(java.lang.String prefix, java.lang.String name)
Generates a qualified name with a namespace prefix.protected static java.lang.String
qualifiedName(org.apache.commons.jxpath.ri.QName name)
Returns the qualified name from the givenQName
.boolean
setPosition(int pos)
Sets the position of the iteration.protected void
setStartOffset(int startOffset)
Sets the start offset of the iteration.protected abstract int
size()
Returns the number of elements in this iteration.
-
-
-
Field Detail
-
PREFIX_SEPARATOR
private static final java.lang.String PREFIX_SEPARATOR
Constant for the prefix separator.- See Also:
- Constant Field Values
-
FMT_NAMESPACE
private static final java.lang.String FMT_NAMESPACE
A format for constructing a node name with a namespace prefix.- See Also:
- Constant Field Values
-
parent
private final ConfigurationNodePointer<T> parent
Stores the parent node pointer.
-
position
private int position
Stores the current position.
-
startOffset
private int startOffset
Stores the start offset of the iterator.
-
reverse
private final boolean reverse
Stores the reverse flag.
-
-
Constructor Detail
-
AbstractConfigurationNodeIterator
protected AbstractConfigurationNodeIterator(ConfigurationNodePointer<T> parent, boolean reverse)
Creates a new instance ofConfigurationNodeIteratorBase
and initializes it.- Parameters:
parent
- the parent pointerreverse
- the reverse flag
-
-
Method Detail
-
prefixName
protected static java.lang.String prefixName(java.lang.String prefix, java.lang.String name)
Generates a qualified name with a namespace prefix.- Parameters:
prefix
- the prefixname
- the name (may be null)- Returns:
- the qualified name
-
qualifiedName
protected static java.lang.String qualifiedName(org.apache.commons.jxpath.ri.QName name)
Returns the qualified name from the givenQName
. If the name has no namespace, result is the simple name. Otherwise, the namespace prefix is added.- Parameters:
name
- theQName
- Returns:
- the qualified name
-
createNodePointer
protected abstract org.apache.commons.jxpath.ri.model.NodePointer createNodePointer(int position)
Creates the configuration node pointer for the current position. This method is called bygetNodePointer()
. Derived classes must create the correct pointer object.- Parameters:
position
- the current position in the iteration- Returns:
- the node pointer
-
getMaxPosition
protected int getMaxPosition()
Gets the maximum position for this iterator.- Returns:
- the maximum allowed position
-
getNodeHandler
protected NodeHandler<T> getNodeHandler()
Gets the node handler for the managed nodes. This is a convenience method.- Returns:
- the node handler
-
getNodePointer
public org.apache.commons.jxpath.ri.model.NodePointer getNodePointer()
Gets the current node pointer.- Specified by:
getNodePointer
in interfaceorg.apache.commons.jxpath.ri.model.NodeIterator
- Returns:
- the current pointer in this iteration
-
getParent
protected ConfigurationNodePointer<T> getParent()
Gets the parent node pointer.- Returns:
- the parent node pointer
-
getPosition
public int getPosition()
Gets the position of the iteration.- Specified by:
getPosition
in interfaceorg.apache.commons.jxpath.ri.model.NodeIterator
- Returns:
- the position
-
getStartOffset
protected int getStartOffset()
Gets the start offset of the iteration.- Returns:
- the start offset
-
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.- Specified by:
setPosition
in interfaceorg.apache.commons.jxpath.ri.model.NodeIterator
- 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
-
size
protected abstract int size()
Returns the number of elements in this iteration.- Returns:
- the number of elements
-
-