java.lang.Object
tools.jackson.core.TokenStreamFactory
tools.jackson.core.base.DecorableTSFactory
tools.jackson.core.base.TextualTSFactory
tools.jackson.dataformat.xml.XmlFactory
All Implemented Interfaces:
Serializable, tools.jackson.core.util.Snapshottable<tools.jackson.core.TokenStreamFactory>, tools.jackson.core.Versioned

public class XmlFactory extends tools.jackson.core.base.TextualTSFactory implements Serializable
Factory used for constructing FromXmlParser and ToXmlGenerator instances.

Implements TokenStreamFactory since interface for constructing XML backed parsers and generators is quite similar to dealing with JSON.

Author:
Tatu Saloranta (tatu.saloranta@iki.fi)
See Also:
  • Field Details

    • FORMAT_NAME_XML

      public static final String FORMAT_NAME_XML
      Name used to identify XML format (and returned by getFormatName()
      See Also:
    • DEFAULT_XML_READ_FEATURE_FLAGS

      protected static final int DEFAULT_XML_READ_FEATURE_FLAGS
      Bitfield (set of flags) of all parser features that are enabled by default.
    • DEFAULT_XML_WRITE_FEATURE_FLAGS

      protected static final int DEFAULT_XML_WRITE_FEATURE_FLAGS
      Bitfield (set of flags) of all generator features that are enabled by default.
    • _cfgNameForTextElement

      protected final String _cfgNameForTextElement
    • _nameProcessor

      protected final XmlNameProcessor _nameProcessor
    • _xmlInputFactory

      protected final transient XMLInputFactory _xmlInputFactory
    • _xmlOutputFactory

      protected final transient XMLOutputFactory _xmlOutputFactory
    • _jdkXmlInFactory

      protected transient String _jdkXmlInFactory
    • _jdkXmlOutFactory

      protected transient String _jdkXmlOutFactory
  • Constructor Details

    • XmlFactory

      public XmlFactory()
      Default constructor used to create factory instances. Creation of a factory instance is a light-weight operation, but it is still a good idea to reuse limited number of factory instances (and quite often just a single instance): factories are used as context for storing some reused processing objects (such as symbol tables parsers use) and this reuse only works within context of a single factory instance.
    • XmlFactory

      public XmlFactory(XMLInputFactory xmlIn)
    • XmlFactory

      public XmlFactory(XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
    • XmlFactory

      protected XmlFactory(int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, XmlNameProcessor nameProcessor, String nameForTextElem)
    • XmlFactory

      protected XmlFactory(XmlFactoryBuilder b)
      Constructor used by XmlFactoryBuilder for instantiation.
    • XmlFactory

      protected XmlFactory(XmlFactory src)
      Constructor used by copy()
      Parameters:
      src - Factory to make copy of
    • XmlFactory

      protected XmlFactory(XmlFactory src, String nameForTextElement)
  • Method Details

    • _initFactories

      protected void _initFactories(XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
    • rebuild

      public XmlFactoryBuilder rebuild()
      Specified by:
      rebuild in class tools.jackson.core.TokenStreamFactory
    • builder

      public static XmlFactoryBuilder builder()
      Main factory method to use for constructing XmlFactory instances with different configuration.
    • builderWithJackson2Defaults

      public static XmlFactoryBuilder builderWithJackson2Defaults()
      The builder returned uses default settings more closely matching the default configs used in Jackson 2.x versions.

      This method is still a work in progress and may not yet fully replicate the default settings of Jackson 2.x.

    • copy

      public XmlFactory copy()
      Note: compared to base implementation by TokenStreamFactory, here the copy will actually share underlying XML input and output factories, as there is no way to make copies of those.
      Specified by:
      copy in class tools.jackson.core.TokenStreamFactory
    • snapshot

      public tools.jackson.core.TokenStreamFactory snapshot()
      Instances are immutable so just return `this`
      Specified by:
      snapshot in interface tools.jackson.core.util.Snapshottable<tools.jackson.core.TokenStreamFactory>
      Specified by:
      snapshot in class tools.jackson.core.TokenStreamFactory
    • withNameForTextElement

      public XmlFactory withNameForTextElement(String name)
      "Mutant factory" method used to allow XmlMapper.Builder to configure name used for text elements, instead of requiring defining it via XmlFactoryBuilder.
    • readResolve

      protected Object readResolve()
      Method that we need to override to actually make restoration go through constructors etc.
    • version

      public tools.jackson.core.Version version()
      Specified by:
      version in interface tools.jackson.core.Versioned
      Specified by:
      version in class tools.jackson.core.TokenStreamFactory
    • canParseAsync

      public boolean canParseAsync()
      Specified by:
      canParseAsync in class tools.jackson.core.TokenStreamFactory
    • canUseCharArrays

      public boolean canUseCharArrays()
      Since 2.4, we do have actual capability for passing char arrays efficiently, but unfortunately have no working mechanism for recycling buffers. So we have to admit that can not make efficient use.
      Overrides:
      canUseCharArrays in class tools.jackson.core.base.TextualTSFactory
    • getFormatName

      public String getFormatName()
      Method that returns short textual id identifying format this factory supports.

      Note: sub-classes should override this method; default implementation will return null for all sub-classes

      Specified by:
      getFormatName in class tools.jackson.core.TokenStreamFactory
    • canUseSchema

      public boolean canUseSchema(tools.jackson.core.FormatSchema schema)
      Specified by:
      canUseSchema in class tools.jackson.core.TokenStreamFactory
    • getFormatReadFeatureType

      public Class<XmlReadFeature> getFormatReadFeatureType()
      Overrides:
      getFormatReadFeatureType in class tools.jackson.core.TokenStreamFactory
    • getFormatWriteFeatureType

      public Class<XmlWriteFeature> getFormatWriteFeatureType()
      Overrides:
      getFormatWriteFeatureType in class tools.jackson.core.TokenStreamFactory
    • getFormatReadFeatures

      public int getFormatReadFeatures()
      Overrides:
      getFormatReadFeatures in class tools.jackson.core.TokenStreamFactory
    • getFormatWriteFeatures

      public int getFormatWriteFeatures()
      Overrides:
      getFormatWriteFeatures in class tools.jackson.core.TokenStreamFactory
    • getXMLTextElementName

      public String getXMLTextElementName()
    • getXMLInputFactory

      public XMLInputFactory getXMLInputFactory()
    • getXMLOutputFactory

      public XMLOutputFactory getXMLOutputFactory()
    • createParser

      public tools.jackson.core.JsonParser createParser(tools.jackson.core.ObjectReadContext readCtxt, String content)
      Overridden just to prevent trying to optimize access via char array; while nice idea, problem is that we don't have proper hooks to ensure that temporary buffer gets recycled; so let's just use StringReader.
      Overrides:
      createParser in class tools.jackson.core.base.TextualTSFactory
    • _createParser

      protected tools.jackson.core.JsonParser _createParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ctxt, DataInput input)
      Specified by:
      _createParser in class tools.jackson.core.base.TextualTSFactory
    • _createGenerator

      protected tools.jackson.core.JsonGenerator _createGenerator(tools.jackson.core.ObjectWriteContext writeCtxt, tools.jackson.core.io.IOContext ioCtxt, Writer out)
      Specified by:
      _createGenerator in class tools.jackson.core.base.TextualTSFactory
    • _createUTF8Generator

      protected tools.jackson.core.JsonGenerator _createUTF8Generator(tools.jackson.core.ObjectWriteContext writeCtxt, tools.jackson.core.io.IOContext ioCtxt, OutputStream out)
      Specified by:
      _createUTF8Generator in class tools.jackson.core.base.TextualTSFactory
    • _toXmlGenerator

      protected ToXmlGenerator _toXmlGenerator(tools.jackson.core.ObjectWriteContext writeCtxt, tools.jackson.core.io.IOContext ioCtxt, XMLStreamWriter sw)
      Overridable method to allow using custom FromXmlParser sub-classes.
    • createParser

      public FromXmlParser createParser(tools.jackson.core.ObjectReadContext readCtxt, XMLStreamReader sr) throws IOException
      Factory method that wraps given XMLStreamReader, usually to allow partial data-binding.
      Throws:
      IOException
    • createGenerator

      public ToXmlGenerator createGenerator(tools.jackson.core.ObjectWriteContext writeCtxt, XMLStreamWriter sw) throws IOException
      Factory method that wraps given XMLStreamWriter, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.
      Throws:
      IOException
    • _createParser

      protected FromXmlParser _createParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ioCtxt, InputStream in)
      Specified by:
      _createParser in class tools.jackson.core.base.TextualTSFactory
    • _createParser

      protected FromXmlParser _createParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ioCtxt, Reader r)
      Specified by:
      _createParser in class tools.jackson.core.base.TextualTSFactory
    • _createParser

      protected FromXmlParser _createParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ioCtxt, char[] data, int offset, int len, boolean recycleBuffer)
      Specified by:
      _createParser in class tools.jackson.core.base.TextualTSFactory
    • _createParser

      protected FromXmlParser _createParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ioCtxt, byte[] data, int offset, int len)
      Specified by:
      _createParser in class tools.jackson.core.base.TextualTSFactory
    • _fromXmlParser

      protected FromXmlParser _fromXmlParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ioCtxt, XMLStreamReader sr)
      Overridable method to allow using custom FromXmlParser sub-classes.
    • _createXmlWriter

      protected XMLStreamWriter _createXmlWriter(OutputStream out)
    • _createXmlWriter

      protected XMLStreamWriter _createXmlWriter(Writer w)
    • _initializeXmlWriter

      protected final XMLStreamWriter _initializeXmlWriter(XMLStreamWriter sw)
    • _initializeXmlReader

      protected final XMLStreamReader _initializeXmlReader(XMLStreamReader sr)