info.bioinfweb.jphyloio.formats.xml

## Class AbstractXMLFactory

- java.lang.Object
- - info.bioinfweb.jphyloio.factory.AbstractSingleReaderWriterFactory
  - - info.bioinfweb.jphyloio.formats.xml.AbstractXMLFactory

- All Implemented Interfaces:
    SingleReaderWriterFactory
  Direct Known Subclasses:
    NeXMLFactory, PDEFactory, PhyloXMLFactory, XTGFactory

      public abstract class AbstractXMLFactory
      extends AbstractSingleReaderWriterFactory

  Implements shared functionality for reader and writer factories of XML formats.
  Since:
    0.0.0
  Author:
    Ben Stöver

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractXMLFactory(javax.xml.namespace.QName rootTag)` Creates a new instance of this class.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `checkFormat(java.io.Reader reader, ReadWriteParameterMap parameters)` Tests whether the specified reader provides an XML document and whether the local part of the start tag of it equals to the local part of `getRootTag()`.
    `protected boolean` | `checkRootTag(javax.xml.stream.events.StartElement startElement)` Implementations can overwrite this method in order to perform further tests on the root tag of the XML document.
    `protected javax.xml.namespace.QName` | `getRootTag()` Returns the root tag that was specified in the constructor.

    - ### Methods inherited from class info.bioinfweb.jphyloio.factory.AbstractSingleReaderWriterFactory

      `checkFormat, createFormatInfo, getFormatInfo`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface info.bioinfweb.jphyloio.factory.SingleReaderWriterFactory

      `getReader, getReader, getWriter, hasReader, hasWriter`

- - ### Constructor Detail

    - #### AbstractXMLFactory

          public AbstractXMLFactory(javax.xml.namespace.QName rootTag)

      Creates a new instance of this class.
      Parameters:
        `rootTag` - the root tag expected in the target format (which is used in `checkFormat(Reader, ReadWriteParameterMap)`)

  - ### Method Detail

    - #### getRootTag

          protected javax.xml.namespace.QName getRootTag()

      Returns the root tag that was specified in the constructor.
      Returns:
        the expected root tag of the target format

    - #### checkRootTag

          protected boolean checkRootTag(javax.xml.stream.events.StartElement startElement)

      Implementations can overwrite this method in order to perform further tests on the root tag of the XML document. It is only called from within the `checkFormat()` methods, if the document is a XML document and the local part of the root tag was equal to the local part of `getRootTag()`.

      This abstract implementation always returns `true`.

      Parameters:
        `startElement` - the event produced by the first start tag in the document
      Returns:
        `true` if the start element is valid for the target format or `false` otherwise

    - #### checkFormat

          public boolean checkFormat(java.io.Reader reader,
                                     ReadWriteParameterMap parameters)

      Tests whether the specified reader provides an XML document and whether the local part of the start tag of it equals to the local part of `getRootTag()`.

      For additional tests, `checkRootTag(StartElement)` can overwritten by inherited classes. Note that this class does not test of the namespace of `getRootTag()` matches that of the document root tag, to allow reading files without namespace definition (e.g. generated by third parts scripts). If an inherited class is associated with a reader that relies on finding a certain namespace, the namespace should additionally be tested in `checkRootTag(StartElement)`.

      Parameters:
        `reader` - the reader to read the first bytes from
        `parameters` - the parameters map that would also be used to create a reader
      Returns:
        `true` if the tested reader may return content in target format or `false` if the content is not in valid target format