Class InputElement

  • All Implemented Interfaces:
    InputNode, Node

    class InputElement
    extends java.lang.Object
    implements InputNode
    The InputElement represents a self contained element that will allow access to its child elements. If the next element read from the NodeReader is not a child then this will return null. The input element node also allows the attribute values associated with the node to be accessed.
    See Also:
    NodeReader
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private InputNodeMap map
      This contains all the attributes associated with the element.
      private EventNode node
      This is the XML element that this node provides access to.
      private InputNode parent
      This is the parent node for this XML input element node.
      private NodeReader reader
      This is the node reader that reads from the XML document.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      InputNode getAttribute​(java.lang.String name)
      Provides an attribute from the element represented.
      NodeMap<InputNode> getAttributes()
      This returns a map of the attributes contained within the element.
      java.lang.String getName()
      Returns the name of the node that this represents.
      InputNode getNext()
      The method is used to acquire the next child attribute of this element.
      InputNode getNext​(java.lang.String name)
      The method is used to acquire the next child attribute of this element.
      InputNode getParent()
      This is used to acquire the Node that is the parent of this node.
      Position getPosition()
      This provides the position of this node within the document.
      java.lang.String getPrefix()
      This is used to acquire the namespace prefix for the node.
      java.lang.String getReference()
      This allows the namespace reference URI to be determined.
      java.lang.Object getSource()
      This is used to return the source object for this node.
      java.lang.String getValue()
      Returns the value for the node that this represents.
      boolean isElement()
      This is used to determine if this node is an element.
      boolean isEmpty()
      This is used to determine if this input node is empty.
      boolean isRoot()
      This method is used to determine if this node is the root node for the XML document.
      void skip()
      This method is used to skip all child elements from this element.
      java.lang.String toString()
      This is the string representation of the element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • map

        private final InputNodeMap map
        This contains all the attributes associated with the element.
      • reader

        private final NodeReader reader
        This is the node reader that reads from the XML document.
      • parent

        private final InputNode parent
        This is the parent node for this XML input element node.
      • node

        private final EventNode node
        This is the XML element that this node provides access to.
    • Constructor Detail

      • InputElement

        public InputElement​(InputNode parent,
                            NodeReader reader,
                            EventNode node)
        Constructor for the InputElement object. This is used to create an input node that will provide access to an XML element. All attributes associated with the element given are extracted and exposed via the attribute node map.
        Parameters:
        parent - this is the parent XML element for this
        reader - this is the reader used to read XML elements
        node - this is the XML element wrapped by this node
    • Method Detail

      • getSource

        public java.lang.Object getSource()
        This is used to return the source object for this node. This is used primarily as a means to determine which XML provider is parsing the source document and producing the nodes. It is useful to be able to determine the XML provider like this.
        Specified by:
        getSource in interface InputNode
        Returns:
        this returns the source of this input node
      • getParent

        public InputNode getParent()
        This is used to acquire the Node that is the parent of this node. This will return the node that is the direct parent of this node and allows for siblings to make use of nodes with their parents if required.
        Specified by:
        getParent in interface InputNode
        Specified by:
        getParent in interface Node
        Returns:
        this returns the parent node for this node
      • getPosition

        public Position getPosition()
        This provides the position of this node within the document. This allows the user of this node to report problems with the location within the document, allowing the XML to be debugged if it does not match the class schema.
        Specified by:
        getPosition in interface InputNode
        Returns:
        this returns the position of the XML read cursor
      • getName

        public java.lang.String getName()
        Returns the name of the node that this represents. This is an immutable property and should not change for any node. This provides the name without the name space part.
        Specified by:
        getName in interface Node
        Returns:
        returns the name of the node that this represents
      • getPrefix

        public java.lang.String getPrefix()
        This is used to acquire the namespace prefix for the node. If there is no namespace prefix for the node then this will return null. Acquiring the prefix enables the qualification of the node to be determined. It also allows nodes to be grouped by its prefix and allows group operations.
        Specified by:
        getPrefix in interface InputNode
        Returns:
        this returns the prefix associated with this node
      • getReference

        public java.lang.String getReference()
        This allows the namespace reference URI to be determined. A reference is a globally unique string that allows the node to be identified. Typically the reference will be a URI but it can be any unique string used to identify the node. This allows the node to be identified within the namespace.
        Specified by:
        getReference in interface InputNode
        Returns:
        this returns the associated namespace reference URI
      • isRoot

        public boolean isRoot()
        This method is used to determine if this node is the root node for the XML document. The root node is the first node in the document and has no sibling nodes. This is false if the node has a parent node or a sibling node.
        Specified by:
        isRoot in interface InputNode
        Returns:
        true if this is the root node within the document
      • isElement

        public boolean isElement()
        This is used to determine if this node is an element. This allows users of the framework to make a distinction between nodes that represent attributes and nodes that represent elements. This is particularly useful given that attribute nodes do not maintain a node map of attributes.
        Specified by:
        isElement in interface InputNode
        Returns:
        this returns true as this instance is an element
      • getAttribute

        public InputNode getAttribute​(java.lang.String name)
        Provides an attribute from the element represented. If an attribute for the specified name does not exist within the element represented then this method will return null.
        Specified by:
        getAttribute in interface InputNode
        Parameters:
        name - this is the name of the attribute to retrieve
        Returns:
        this returns the value for the named attribute
      • getAttributes

        public NodeMap<InputNode> getAttributes()
        This returns a map of the attributes contained within the element. If no elements exist within the element then this returns an empty map.
        Specified by:
        getAttributes in interface InputNode
        Returns:
        this returns a map of attributes for the element
      • getValue

        public java.lang.String getValue()
                                  throws java.lang.Exception
        Returns the value for the node that this represents. This is an immutable value for the node and cannot be changed. If there is a problem reading an exception is thrown.
        Specified by:
        getValue in interface Node
        Returns:
        the name of the value for this node instance
        Throws:
        java.lang.Exception - if there is a problem getting the value
      • getNext

        public InputNode getNext()
                          throws java.lang.Exception
        The method is used to acquire the next child attribute of this element. If the next element from the NodeReader is not a child node to the element that this represents then this will return null, which ensures each element represents a self contained collection of child nodes.
        Specified by:
        getNext in interface InputNode
        Returns:
        this returns the next child element of this node
        Throws:
        java.lang.Exception - thrown if there is a problem reading
      • getNext

        public InputNode getNext​(java.lang.String name)
                          throws java.lang.Exception
        The method is used to acquire the next child attribute of this element. If the next element from the NodeReader is not a child node to the element that this represents then this will return null, also if the next element does not match the specified name then this will return null.
        Specified by:
        getNext in interface InputNode
        Parameters:
        name - this is the name expected fromt he next element
        Returns:
        this returns the next child element of this node
        Throws:
        java.lang.Exception - thrown if there is a problem reading
      • skip

        public void skip()
                  throws java.lang.Exception
        This method is used to skip all child elements from this element. This allows elements to be effectively skipped such that when parsing a document if an element is not required then that element can be completely removed from the XML.
        Specified by:
        skip in interface InputNode
        Throws:
        java.lang.Exception - thrown if there was a parse error
      • isEmpty

        public boolean isEmpty()
                        throws java.lang.Exception
        This is used to determine if this input node is empty. An empty node is one with no attributes or children. This can be used to determine if a given node represents an empty entity, with which no extra data can be extracted.
        Specified by:
        isEmpty in interface InputNode
        Returns:
        this returns true if the node is an empty element
        Throws:
        java.lang.Exception - thrown if there was a parse error
      • toString

        public java.lang.String toString()
        This is the string representation of the element. It is used for debugging purposes. When evaluating the element the to string can be used to print out the element name.
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns a text description of the element