Class XmlObjectParser

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Object>

    public class XmlObjectParser
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Object>
    An helper class that reads from a XML stream into specific objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String lang
      The language prefix to use
      private java.util.Map<java.lang.String,​XmlObjectParser.Entry> mapping  
      private org.xml.sax.helpers.DefaultHandler parser  
      private java.util.List<java.lang.Object> queue
      The queue of already parsed items from the parsing thread.
      private java.util.Iterator<java.lang.Object> queueIterator  
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlObjectParser()
      Constructs a new XmlObjectParser.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Check if there is a next parsed object available
      java.util.Iterator<java.lang.Object> iterator()  
      void map​(java.lang.String tagName, java.lang.Class<?> klass)
      Add a new tag name to class type mapping
      void mapBoth​(java.lang.String tagName, java.lang.Class<?> klass)  
      void mapOnStart​(java.lang.String tagName, java.lang.Class<?> klass)  
      java.lang.Object next()
      Get the next element that was parsed
      java.lang.Iterable<java.lang.Object> start​(java.io.Reader in)
      Starts parsing from the given input reader, without validation.
      private java.lang.Iterable<java.lang.Object> start​(java.io.Reader in, org.xml.sax.ContentHandler contentHandler)  
      java.lang.Iterable<java.lang.Object> startWithValidation​(java.io.Reader in, java.lang.String namespace, java.lang.String schemaSource)
      Starts parsing from the given input reader, with XSD validation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • lang

        public static final java.lang.String lang
        The language prefix to use
      • parser

        private final org.xml.sax.helpers.DefaultHandler parser
      • queue

        private final java.util.List<java.lang.Object> queue
        The queue of already parsed items from the parsing thread.
      • queueIterator

        private java.util.Iterator<java.lang.Object> queueIterator
    • Constructor Detail

      • XmlObjectParser

        public XmlObjectParser()
        Constructs a new XmlObjectParser.
    • Method Detail

      • start

        private java.lang.Iterable<java.lang.Object> start​(java.io.Reader in,
                                                           org.xml.sax.ContentHandler contentHandler)
                                                    throws org.xml.sax.SAXException,
                                                           java.io.IOException
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • start

        public java.lang.Iterable<java.lang.Object> start​(java.io.Reader in)
                                                   throws org.xml.sax.SAXException
        Starts parsing from the given input reader, without validation.
        Parameters:
        in - The input reader
        Returns:
        iterable collection of objects
        Throws:
        org.xml.sax.SAXException - if any XML or I/O error occurs
      • startWithValidation

        public java.lang.Iterable<java.lang.Object> startWithValidation​(java.io.Reader in,
                                                                        java.lang.String namespace,
                                                                        java.lang.String schemaSource)
                                                                 throws org.xml.sax.SAXException
        Starts parsing from the given input reader, with XSD validation.
        Parameters:
        in - The input reader
        namespace - default namespace
        schemaSource - XSD schema
        Returns:
        iterable collection of objects
        Throws:
        org.xml.sax.SAXException - if any XML or I/O error occurs
      • map

        public void map​(java.lang.String tagName,
                        java.lang.Class<?> klass)
        Add a new tag name to class type mapping
        Parameters:
        tagName - The tag name that should be converted to that class
        klass - The class the XML elements should be converted to.
      • mapOnStart

        public void mapOnStart​(java.lang.String tagName,
                               java.lang.Class<?> klass)
      • mapBoth

        public void mapBoth​(java.lang.String tagName,
                            java.lang.Class<?> klass)
      • next

        public java.lang.Object next()
        Get the next element that was parsed
        Returns:
        The next object
      • hasNext

        public boolean hasNext()
        Check if there is a next parsed object available
        Returns:
        true if there is a next object
      • iterator

        public java.util.Iterator<java.lang.Object> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Object>