Class NodeIterator

  • All Implemented Interfaces:
    Iterator<Object>

    public class NodeIterator
    extends Object
    implements Iterator<Object>
    The NodeIterator is an Iterator for nodes of an XML document.

    This iterator offers a simple mechanism iterating through Node* objects by considering the required or optional occurrences of attributes, values or list of values.

    Author:
    Michael Grammling - Initial contribution
    • Constructor Detail

      • NodeIterator

        public NodeIterator​(List<?> nodes)
        Creates a new instance of this class with the specified argument.
        Parameters:
        nodes - the list of nodes to be iterated through (could be null or empty)
    • Method Detail

      • revert

        public void revert()
        Reverts the last next() call.

        After this method returns, the iteration counter is the same as before the last next() call. Calling this method multiple times decreases the iteration counter by one until the index of 0 has been reached.

      • assertEndOfType

        public void assertEndOfType()
                             throws com.thoughtworks.xstream.converters.ConversionException
        Ensures that the end of the node has been reached.
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the end of the node has not reached yet
      • next

        public Object next​(String nodeName,
                           boolean required)
                    throws com.thoughtworks.xstream.converters.ConversionException
        Returns the next object if the specified name of the node fits to the next node, or null if the node does not exist. In the last case the iterator will not increase its iteration counter.
        Parameters:
        nodeName - the name of the node to be read next (must neither be null, nor empty)
        required - true if the occurrence of the node has to be ensured
        Returns:
        the next object if the specified name of the node fits to the next node, otherwise null
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the specified node could not be found in the next node however it was specified as required
      • nextAttribute

        public String nextAttribute​(String nodeName,
                                    String attributeName,
                                    boolean required)
                             throws com.thoughtworks.xstream.converters.ConversionException
        Returns the next attribute if the specified name of the node fits to the next node and the attribute with the specified name could be found, or null if the node or attribute does not exist. In the last case the iterator will not increase its iteration counter.

        The next node must be of the type NodeAttributes.

        Parameters:
        nodeName - the name of the node to be read next (must neither be null, nor empty)
        attributeName - the name of the attribute of the node to be read next (must neither be null, nor empty)
        required - true if the occurrence of the node's attribute has to be ensured
        Returns:
        the next attribute of the specified name of the node and attribute (could be null or empty)
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the specified node's attribute could not be found in the next node however it was specified as required
      • nextValue

        public Object nextValue​(String nodeName,
                                boolean required)
                         throws com.thoughtworks.xstream.converters.ConversionException
        Returns the next value if the specified name of the node fits to the next node, or null if the node does not exist. In the last case the iterator will not increase its iteration counter.

        The next node must be of the type NodeValue.

        Parameters:
        nodeName - the name of the node to be read next (must neither be null, nor empty)
        required - true if the occurrence of the node's value has to be ensured
        Returns:
        the next value of the specified name of the node (could be null or empty)
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the specified node's value could not be found in the next node however it was specified as required
      • nextList

        public List<?> nextList​(String nodeName,
                                boolean required)
                         throws com.thoughtworks.xstream.converters.ConversionException
        Returns the next list of values if the specified name of the node fits to the next node, or null if the node does not exist. In the last case the iterator will not increase its iteration counter.

        The next node must be of the type NodeList.

        Parameters:
        nodeName - the name of the node to be read next (must neither be null, nor empty)
        required - true if the occurrence of the node's list of values has to be ensured
        Returns:
        the next list of values of the specified name of the node (could be null or empty)
        Throws:
        com.thoughtworks.xstream.converters.ConversionException - if the specified node's list of values could not be found in the next node however it was specified as required