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 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
FieldsModifier and TypeFieldDescriptionprivate static final String
A format for constructing a node name with a namespace prefix.private final ConfigurationNodePointer
<T> Stores the parent node pointer.private int
Stores the current position.private static final String
Constant for the prefix separator.private final boolean
Stores the reverse flag.private int
Stores the start offset of the iterator. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractConfigurationNodeIterator
(ConfigurationNodePointer<T> parent, boolean reverse) Creates a new instance ofConfigurationNodeIteratorBase
and initializes it. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract org.apache.commons.jxpath.ri.model.NodePointer
createNodePointer
(int position) Creates the configuration node pointer for the current position.protected int
Gets the maximum position for this iterator.protected NodeHandler
<T> Gets the node handler for the managed nodes.org.apache.commons.jxpath.ri.model.NodePointer
Gets the current node pointer.protected ConfigurationNodePointer
<T> Gets the parent node pointer.int
Gets the position of the iteration.protected int
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 String
prefixName
(String prefix, String name) Generates a qualified name with a namespace prefix.protected static 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 Details
-
PREFIX_SEPARATOR
Constant for the prefix separator.- See Also:
-
FMT_NAMESPACE
A format for constructing a node name with a namespace prefix.- See Also:
-
parent
Stores the parent node pointer. -
position
private int positionStores the current position. -
startOffset
private int startOffsetStores the start offset of the iterator. -
reverse
private final boolean reverseStores the reverse flag.
-
-
Constructor Details
-
AbstractConfigurationNodeIterator
Creates a new instance ofConfigurationNodeIteratorBase
and initializes it.- Parameters:
parent
- the parent pointerreverse
- the reverse flag
-
-
Method Details
-
prefixName
Generates a qualified name with a namespace prefix.- Parameters:
prefix
- the prefixname
- the name (may be null)- Returns:
- the qualified name
-
qualifiedName
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
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
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
-