Package io.kojan.xml

Class XMLParserImpl

java.lang.Object
io.kojan.xml.XMLParserImpl
All Implemented Interfaces:
XMLParser

class XMLParserImpl extends Object implements XMLParser
An implementation of XMLParser using Java StAX API.
  • Field Details

    • XML_INPUT_FACTORY

      private static final XMLInputFactory XML_INPUT_FACTORY
    • cursor

      private final XMLStreamReader cursor
    • currText

      private String currText
    • currToken

      private int currToken
  • Constructor Details

  • Method Details

    • error

      private XMLException error(String message) throws XMLException
      Throws:
      XMLException
    • lookahead

      private void lookahead() throws XMLStreamException
      Populate parser lookahead state, i.e. update currText and currToken to reflect current cursor state. Needs to be called upon cursor initialization and every time the cursor is advanced.
      Throws:
      XMLStreamException
    • hasToken

      private boolean hasToken(int token) throws XMLException
      Throws:
      XMLException
    • advance

      private void advance() throws XMLStreamException
      Throws:
      XMLStreamException
    • parseText

      public String parseText() throws XMLException
      Description copied from interface: XMLParser
      Reads XML text content.

      If there is no XML text content at given parser position, then empty String is returned.

      Comments within the text are skipped.

      Specified by:
      parseText in interface XMLParser
      Returns:
      text content that was read
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • hasStartElement

      public boolean hasStartElement() throws XMLException
      Description copied from interface: XMLParser
      Determines whether at the current parser position there is an XML element opening tag.

      Comments and whitespace text preceding the XML tag are skipped.

      Specified by:
      hasStartElement in interface XMLParser
      Returns:
      true iff at the current parser position there is an XML element
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • hasStartElement

      public boolean hasStartElement(String tag) throws XMLException
      Description copied from interface: XMLParser
      Determines whether at the current parser position there is an XML element opening tag with specified tag name.

      Comments and whitespace text preceding the XML tag are skipped.

      Specified by:
      hasStartElement in interface XMLParser
      Parameters:
      tag - XML element tag name
      Returns:
      true iff at the current parser position there is an XML element with specified tag name
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • parseStartElement

      public String parseStartElement() throws XMLException
      Description copied from interface: XMLParser
      Reads XML element opening tag.

      Comments and whitespace text preceding the XML tag are skipped.

      XMLException is thrown if at the current position there is no XML element (but, for example, text data or element closing tag).

      Specified by:
      parseStartElement in interface XMLParser
      Returns:
      XML element tag name
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • parseStartElement

      public void parseStartElement(String tag) throws XMLException
      Description copied from interface: XMLParser
      Reads XML element opening tag with specified tag name.

      Comments and whitespace text preceding the XML tag are skipped.

      XMLException is thrown if at the current position there is no XML element opening tag with specified tag (but, for example, text data, element closing tag or element opening tag with a different tag name).

      Specified by:
      parseStartElement in interface XMLParser
      Parameters:
      tag - XML element tag name
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • expectToken

      private void expectToken(int token, String description) throws XMLException
      Throws:
      XMLException
    • parseEndElement

      public void parseEndElement(String tag) throws XMLException
      Description copied from interface: XMLParser
      Reads XML element closing tag with specified tag name.

      Comments and whitespace text preceding the XML tag are skipped.

      XMLException is thrown if at the current position there is no XML element closing tag with specified tag (but, for example, text data, element opening tag or XML element closing tag with a different tag name).

      Specified by:
      parseEndElement in interface XMLParser
      Parameters:
      tag - XML element tag name
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • parseStartDocument

      void parseStartDocument() throws XMLException
      Throws:
      XMLException
    • parseEndDocument

      void parseEndDocument() throws XMLException
      Throws:
      XMLException
    • tryParse

      private <Type, Bean, Value> boolean tryParse(Property<Type,Bean,Value> property, Bean bean) throws XMLException
      Throws:
      XMLException
    • parseEntity

      public <Type, Bean> void parseEntity(Entity<Type,Bean> entity, Bean bean) throws XMLException
      Description copied from interface: XMLParser
      Deserializes given Entity from XML form.
      Specified by:
      parseEntity in interface XMLParser
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      Parameters:
      entity - the entity type to deserialize
      bean - the entity bean to deserialize data into
      Throws:
      XMLException - in case exception occurs during XML deserialization
    • parseDocument

      <Type, Bean> Type parseDocument(Entity<Type,Bean> rootEntity) throws XMLException
      Throws:
      XMLException