XmlObjectFactory (xmlbeans API)

org.apache.xmlbeans.impl.schema

## Class XmlObjectFactory<T>

- java.lang.Object
- - org.apache.xmlbeans.impl.schema.ElementFactory<T>
  - - org.apache.xmlbeans.impl.schema.AbstractDocumentFactory<T>
    - - org.apache.xmlbeans.impl.schema.DocumentFactory<T>
      - - org.apache.xmlbeans.impl.schema.XmlObjectFactory<T>

-     public class XmlObjectFactory<T>
      extends DocumentFactory<T>

  Factory class for creating new instances. Note that if a type can be inferred from the XML being loaded (for example, by recognizing the document element QName), then the instance returned by a factory will have the inferred type. Otherwise the Factory will returned an untyped document.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XmlObjectFactory(SchemaTypeSystem typeSystem, String typeHandle)` This constructor is only used as a workaround for bootstrapping the XML schemas - don't use it!
    `XmlObjectFactory(String typeHandle)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DOMImplementation` | `newDomImplementation()` Creates a new DOMImplementation object
    `DOMImplementation` | `newDomImplementation(XmlOptions options)` Creates a new DOMImplementation object, taking options
    `T` | `newInstance()` Creates a new, completely empty instance.
    `T` | `newInstance(XmlOptions options)` Creates a new, completely empty instance, specifying options for the root element's document type and/or whether to validate value facets as they are set.
    `T` | `newValue(Object obj)` Creates an immutable `XmlObject` value
    `XmlSaxHandler` | `newXmlSaxHandler()` Returns an `XmlSaxHandler` that can load an XmlObject from SAX events.
    `XmlSaxHandler` | `newXmlSaxHandler(XmlOptions options)` Returns an `XmlSaxHandler` that can load an XmlObject from SAX events.
    `T` | `parse(File file)` Parses the given `File` as XML.
    `T` | `parse(File file, XmlOptions options)` Parses the given `File` as XML.
    `T` | `parse(InputStream is)` Decodes and parses the given `InputStream` as XML.
    `T` | `parse(InputStream is, XmlOptions options)` Decodes and parses the given `InputStream` as XML.
    `T` | `parse(Node node)` Converts the given DOM `Node` into an XmlObject.
    `T` | `parse(Node node, XmlOptions options)` Converts the given DOM `Node` into an XmlObject.
    `T` | `parse(Reader r)` Parses the given `Reader` as XML.
    `T` | `parse(Reader r, XmlOptions options)` Parses the given `Reader` as XML.
    `T` | `parse(String xmlAsString)` Parses the given `String` as XML.
    `T` | `parse(String xmlAsString, XmlOptions options)` Parses the given `String` as XML.
    `T` | `parse(URL u)` Downloads the given `URL` as XML.
    `T` | `parse(URL u, XmlOptions options)` Downloads the given `URL` as XML.
    `T` | `parse(XMLStreamReader xsr)` Decodes and parses the given `XMLStreamReader` as XML.
    `T` | `parse(XMLStreamReader xsr, XmlOptions options)` Parses the given `XMLStreamReader` as XML.

    - ### Methods inherited from class org.apache.xmlbeans.impl.schema.ElementFactory

      `getType, getTypeLoader`

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

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

- - ### Constructor Detail

    - #### XmlObjectFactory

          public XmlObjectFactory(String typeHandle)

    - #### XmlObjectFactory

          public XmlObjectFactory(SchemaTypeSystem typeSystem,
                                  String typeHandle)

      This constructor is only used as a workaround for bootstrapping the XML schemas - don't use it!

  - ### Method Detail

    - #### newInstance

          public T newInstance()

      Creates a new, completely empty instance.
      Overrides:
        `newInstance` in class `DocumentFactory<T>`

    - #### newInstance

          public T newInstance(XmlOptions options)

      Creates a new, completely empty instance, specifying options for the root element's document type and/or whether to validate value facets as they are set.

      Use the options parameter to specify the following:

      Option parameter
      To specify this | Use this method
      --- | ---
      The document type for the root element. | `XmlOptions.setDocumentType(org.apache.xmlbeans.SchemaType)`
      Whether value facets should be checked as they are set. | `XmlOptions.setValidateOnSet()`

      Overrides:
        `newInstance` in class `DocumentFactory<T>`
      Parameters:
        `options` - Options specifying root document type and/or value facet checking.
      Returns:
        A new, empty instance of XmlObject.

    - #### newValue

          public T newValue(Object obj)

      Creates an immutable `XmlObject` value

    - #### parse

          public T parse(String xmlAsString)
                  throws XmlException

      Parses the given `String` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Parameters:
        `xmlAsString` - the string value to parse
      Throws:
        `XmlException`

    - #### parse

          public T parse(String xmlAsString,
                         XmlOptions options)
                  throws XmlException

      Parses the given `String` as XML.

      Use the options parameter to specify the following:

      Option parameter
      To specify this | Use this method
      --- | ---
      The document type for the root element. | `XmlOptions.setDocumentType(org.apache.xmlbeans.SchemaType)`
      To place line number annotations in the store when parsing a document. | `XmlOptions.setLoadLineNumbers()`
      To replace the document element with the specified QName when parsing. | `XmlOptions.setLoadReplaceDocumentElement(javax.xml.namespace.QName)`
      To strip all insignificant whitespace when parsing a document. | `XmlOptions.setLoadStripWhitespace()`
      To strip all comments when parsing a document. | `XmlOptions.setLoadStripComments()`
      To strip all processing instructions when parsing a document. | `XmlOptions.setLoadStripProcinsts()`
      A map of namespace URI substitutions to use when parsing a document. | `XmlOptions.setLoadSubstituteNamespaces(java.util.Map<java.lang.String, java.lang.String>)`
      Additional namespace mappings to be added when parsing a document. | `XmlOptions.setLoadAdditionalNamespaces(java.util.Map<java.lang.String, java.lang.String>)`
      To trim the underlying XML text buffer immediately after parsing a document, resulting in a smaller memory footprint. | `XmlOptions.setLoadTrimTextBuffer()`

      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Parameters:
        `xmlAsString` - The string to parse.
        `options` - Options as specified.
      Returns:
        A new instance containing the specified XML.
      Throws:
        `XmlException`

    - #### parse

          public T parse(File file)
                  throws XmlException,
                         IOException

      Parses the given `File` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Parameters:
        `file` - the file from which to load an xml document
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(File file,
                         XmlOptions options)
                  throws XmlException,
                         IOException

      Parses the given `File` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(URL u)
                  throws XmlException,
                         IOException

      Downloads the given `URL` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(URL u,
                         XmlOptions options)
                  throws XmlException,
                         IOException

      Downloads the given `URL` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(InputStream is)
                  throws XmlException,
                         IOException

      Decodes and parses the given `InputStream` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(XMLStreamReader xsr)
                  throws XmlException

      Decodes and parses the given `XMLStreamReader` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`

    - #### parse

          public T parse(InputStream is,
                         XmlOptions options)
                  throws XmlException,
                         IOException

      Decodes and parses the given `InputStream` as XML.

      Use the options parameter to specify the following:

      Option parameter
      To specify this | Use this method
      --- | ---
      The character encoding to use when parsing or writing a document. | `XmlOptions.setCharacterEncoding(java.lang.String)`
      The document type for the root element. | `XmlOptions.setDocumentType(org.apache.xmlbeans.SchemaType)`
      Place line number annotations in the store when parsing a document. | `XmlOptions.setLoadLineNumbers()`
      Replace the document element with the specified QName when parsing. | `XmlOptions.setLoadReplaceDocumentElement(javax.xml.namespace.QName)`
      Strip all insignificant whitespace when parsing a document. | `XmlOptions.setLoadStripWhitespace()`
      Strip all comments when parsing a document. | `XmlOptions.setLoadStripComments()`
      Strip all processing instructions when parsing a document. | `XmlOptions.setLoadStripProcinsts()`
      Set a map of namespace URI substitutions to use when parsing a document. | `XmlOptions.setLoadSubstituteNamespaces(java.util.Map<java.lang.String, java.lang.String>)`
      Set additional namespace mappings to be added when parsing a document. | `XmlOptions.setLoadAdditionalNamespaces(java.util.Map<java.lang.String, java.lang.String>)`
      Trim the underlying XML text buffer immediately after parsing a document, resulting in a smaller memory footprint. | `XmlOptions.setLoadTrimTextBuffer()`

      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(XMLStreamReader xsr,
                         XmlOptions options)
                  throws XmlException

      Parses the given `XMLStreamReader` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`

    - #### parse

          public T parse(Reader r)
                  throws XmlException,
                         IOException

      Parses the given `Reader` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(Reader r,
                         XmlOptions options)
                  throws XmlException,
                         IOException

      Parses the given `Reader` as XML.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`
        `IOException`

    - #### parse

          public T parse(Node node)
                  throws XmlException

      Converts the given DOM `Node` into an XmlObject.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`

    - #### parse

          public T parse(Node node,
                         XmlOptions options)
                  throws XmlException

      Converts the given DOM `Node` into an XmlObject.
      Overrides:
        `parse` in class `AbstractDocumentFactory<T>`
      Throws:
        `XmlException`

    - #### newXmlSaxHandler

          public XmlSaxHandler newXmlSaxHandler()

      Returns an `XmlSaxHandler` that can load an XmlObject from SAX events.

    - #### newXmlSaxHandler

          public XmlSaxHandler newXmlSaxHandler(XmlOptions options)

      Returns an `XmlSaxHandler` that can load an XmlObject from SAX events.

    - #### newDomImplementation

          public DOMImplementation newDomImplementation()

      Creates a new DOMImplementation object

    - #### newDomImplementation

          public DOMImplementation newDomImplementation(XmlOptions options)

      Creates a new DOMImplementation object, taking options