com.fasterxml.jackson.dataformat.xml
Class XmlFactory

java.lang.Object
  extended by com.fasterxml.jackson.core.JsonFactory
      extended by com.fasterxml.jackson.dataformat.xml.XmlFactory
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, Serializable

public class XmlFactory
extends com.fasterxml.jackson.core.JsonFactory

Factory used for constructing FromXmlParser and ToXmlGenerator instances.

Implements JsonFactory 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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonFactory
com.fasterxml.jackson.core.JsonFactory.Feature
 
Field Summary
protected  String _cfgNameForTextElement
           
protected  String _jdkXmlInFactory
          Hiding place for JDK-serialization unthawed factories...
protected  String _jdkXmlOutFactory
          Hiding place for JDK-serialization unthawed factories...
protected  int _xmlGeneratorFeatures
           
protected  XMLInputFactory _xmlInputFactory
           
protected  XMLOutputFactory _xmlOutputFactory
           
protected  int _xmlParserFeatures
           
static String FORMAT_NAME_XML
          Name used to identify XML format (and returned by getFormatName()
 
Fields inherited from class com.fasterxml.jackson.core.JsonFactory
_characterEscapes, _factoryFeatures, _generatorFeatures, _inputDecorator, _objectCodec, _outputDecorator, _parserFeatures, _recyclerRef, _rootByteSymbols, _rootCharSymbols, _rootValueSeparator, DEFAULT_FACTORY_FEATURE_FLAGS, DEFAULT_GENERATOR_FEATURE_FLAGS, DEFAULT_PARSER_FEATURE_FLAGS, FORMAT_NAME_JSON
 
Constructor Summary
XmlFactory()
          Default constructor used to create factory instances.
XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc)
           
XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc, XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
           
XmlFactory(XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
           
 
Method Summary
protected  FromXmlParser _createJsonParser(byte[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt)
          Deprecated. 
protected  FromXmlParser _createJsonParser(InputStream in, com.fasterxml.jackson.core.io.IOContext ctxt)
          Deprecated. 
protected  FromXmlParser _createJsonParser(Reader r, com.fasterxml.jackson.core.io.IOContext ctxt)
          Deprecated. 
protected  FromXmlParser _createParser(byte[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt)
           
protected  FromXmlParser _createParser(InputStream in, com.fasterxml.jackson.core.io.IOContext ctxt)
           
protected  FromXmlParser _createParser(Reader r, com.fasterxml.jackson.core.io.IOContext ctxt)
           
protected  XMLStreamWriter _createXmlWriter(OutputStream out)
           
protected  XMLStreamWriter _createXmlWriter(Writer w)
           
protected  void _initFactories(XMLInputFactory xmlIn, XMLOutputFactory xmlOut)
           
protected  XMLStreamReader _initializeXmlReader(XMLStreamReader sr)
           
protected  XMLStreamWriter _initializeXmlWriter(XMLStreamWriter sw)
           
 XmlFactory configure(FromXmlParser.Feature f, boolean state)
          Method for enabling or disabling specified XML parser feature.
 XmlFactory configure(ToXmlGenerator.Feature f, boolean state)
          Method for enabling or disabling specified XML generator feature.
 XmlFactory copy()
          Note: compared to base implementation by JsonFactory, here the copy will actually share underlying XML input and output factories, as there is no way to make copies of those.
 ToXmlGenerator createGenerator(File f, com.fasterxml.jackson.core.JsonEncoding enc)
           
 ToXmlGenerator createGenerator(OutputStream out)
           
 ToXmlGenerator createGenerator(OutputStream out, com.fasterxml.jackson.core.JsonEncoding enc)
           
 ToXmlGenerator createGenerator(Writer out)
           
 ToXmlGenerator createJsonGenerator(File f, com.fasterxml.jackson.core.JsonEncoding enc)
           
 ToXmlGenerator createJsonGenerator(OutputStream out, com.fasterxml.jackson.core.JsonEncoding enc)
           note: co-variant return type
 ToXmlGenerator createJsonGenerator(Writer out)
           
 XmlFactory disable(FromXmlParser.Feature f)
          Method for disabling specified XML parser feature.
 XmlFactory disable(ToXmlGenerator.Feature f)
          Method for disabling specified XML generator feature.
 XmlFactory enable(FromXmlParser.Feature f)
          Method for enabling specified XML parser feature.
 XmlFactory enable(ToXmlGenerator.Feature f)
          Method for enabling specified XML generator feature.
 String getFormatName()
          Method that returns short textual id identifying format this factory supports.
 com.fasterxml.jackson.core.format.MatchStrength hasFormat(com.fasterxml.jackson.core.format.InputAccessor acc)
           
static com.fasterxml.jackson.core.format.MatchStrength hasXMLFormat(com.fasterxml.jackson.core.format.InputAccessor acc)
          Method that tries to figure out if content seems to be in some kind of XML format.
 boolean isEnabled(FromXmlParser.Feature f)
          Checked whether specified XML parser feature is enabled.
 boolean isEnabled(ToXmlGenerator.Feature f)
          Check whether specified XML generator feature is enabled.
protected  Object readResolve()
          Method that we need to override to actually make restoration go through constructors etc.
 boolean requiresCustomCodec()
          XML format does require support from custom ObjectCodec (that is, XmlMapper), so need to return true here.
 void setXMLInputFactory(XMLInputFactory f)
           
 void setXMLOutputFactory(XMLOutputFactory f)
           
 void setXMLTextElementName(String name)
           
 com.fasterxml.jackson.core.Version version()
           
 
Methods inherited from class com.fasterxml.jackson.core.JsonFactory
_checkInvalidCopy, _createContext, _createGenerator, _createJsonGenerator, _createUTF8Generator, _createUTF8JsonGenerator, _createWriter, _getBufferRecycler, _optimizedStreamFromURL, canUseSchema, configure, configure, configure, createJsonGenerator, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, disable, disable, disable, enable, enable, enable, getCharacterEscapes, getCodec, getInputDecorator, getOutputDecorator, getRootValueSeparator, hasJSONFormat, isEnabled, isEnabled, isEnabled, setCharacterEscapes, setCodec, setInputDecorator, setOutputDecorator, setRootValueSeparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_NAME_XML

public static final String FORMAT_NAME_XML
Name used to identify XML format (and returned by getFormatName()

See Also:
Constant Field Values

_xmlParserFeatures

protected int _xmlParserFeatures

_xmlGeneratorFeatures

protected int _xmlGeneratorFeatures

_xmlInputFactory

protected transient XMLInputFactory _xmlInputFactory

_xmlOutputFactory

protected transient XMLOutputFactory _xmlOutputFactory

_cfgNameForTextElement

protected String _cfgNameForTextElement

_jdkXmlInFactory

protected transient String _jdkXmlInFactory
Hiding place for JDK-serialization unthawed factories...


_jdkXmlOutFactory

protected transient String _jdkXmlOutFactory
Hiding place for JDK-serialization unthawed factories...

Constructor Detail

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(com.fasterxml.jackson.core.ObjectCodec oc)

XmlFactory

public XmlFactory(XMLInputFactory xmlIn,
                  XMLOutputFactory xmlOut)

XmlFactory

public XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc,
                  XMLInputFactory xmlIn,
                  XMLOutputFactory xmlOut)
Method Detail

_initFactories

protected void _initFactories(XMLInputFactory xmlIn,
                              XMLOutputFactory xmlOut)

copy

public XmlFactory copy()
Note: compared to base implementation by JsonFactory, here the copy will actually share underlying XML input and output factories, as there is no way to make copies of those.

Overrides:
copy in class com.fasterxml.jackson.core.JsonFactory
Since:
2.1

version

public com.fasterxml.jackson.core.Version version()
Specified by:
version in interface com.fasterxml.jackson.core.Versioned
Overrides:
version in class com.fasterxml.jackson.core.JsonFactory

readResolve

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

Overrides:
readResolve in class com.fasterxml.jackson.core.JsonFactory

setXMLTextElementName

public void setXMLTextElementName(String name)

configure

public final XmlFactory configure(FromXmlParser.Feature f,
                                  boolean state)
Method for enabling or disabling specified XML parser feature.


enable

public XmlFactory enable(FromXmlParser.Feature f)
Method for enabling specified XML parser feature.


disable

public XmlFactory disable(FromXmlParser.Feature f)
Method for disabling specified XML parser feature.


isEnabled

public final boolean isEnabled(FromXmlParser.Feature f)
Checked whether specified XML parser feature is enabled.


configure

public final XmlFactory configure(ToXmlGenerator.Feature f,
                                  boolean state)
Method for enabling or disabling specified XML generator feature.


enable

public XmlFactory enable(ToXmlGenerator.Feature f)
Method for enabling specified XML generator feature.


disable

public XmlFactory disable(ToXmlGenerator.Feature f)
Method for disabling specified XML generator feature.


isEnabled

public final boolean isEnabled(ToXmlGenerator.Feature f)
Check whether specified XML generator feature is enabled.


setXMLInputFactory

public void setXMLInputFactory(XMLInputFactory f)

setXMLOutputFactory

public void setXMLOutputFactory(XMLOutputFactory f)

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

Overrides:
getFormatName in class com.fasterxml.jackson.core.JsonFactory

hasFormat

public com.fasterxml.jackson.core.format.MatchStrength hasFormat(com.fasterxml.jackson.core.format.InputAccessor acc)
                                                          throws IOException
Overrides:
hasFormat in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

requiresCustomCodec

public boolean requiresCustomCodec()
XML format does require support from custom ObjectCodec (that is, XmlMapper), so need to return true here.

Overrides:
requiresCustomCodec in class com.fasterxml.jackson.core.JsonFactory
Returns:
True since XML format does require support from codec

createGenerator

public ToXmlGenerator createGenerator(OutputStream out)
                               throws IOException
Overrides:
createGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createGenerator

public ToXmlGenerator createGenerator(OutputStream out,
                                      com.fasterxml.jackson.core.JsonEncoding enc)
                               throws IOException
Overrides:
createGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createGenerator

public ToXmlGenerator createGenerator(Writer out)
                               throws IOException
Overrides:
createGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createGenerator

public ToXmlGenerator createGenerator(File f,
                                      com.fasterxml.jackson.core.JsonEncoding enc)
                               throws IOException
Overrides:
createGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createJsonGenerator

public ToXmlGenerator createJsonGenerator(OutputStream out,
                                          com.fasterxml.jackson.core.JsonEncoding enc)
                                   throws IOException

note: co-variant return type

Overrides:
createJsonGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createJsonGenerator

public ToXmlGenerator createJsonGenerator(Writer out)
                                   throws IOException
Overrides:
createJsonGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

createJsonGenerator

public ToXmlGenerator createJsonGenerator(File f,
                                          com.fasterxml.jackson.core.JsonEncoding enc)
                                   throws IOException
Overrides:
createJsonGenerator in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException

_createParser

protected FromXmlParser _createParser(InputStream in,
                                      com.fasterxml.jackson.core.io.IOContext ctxt)
                               throws IOException,
                                      com.fasterxml.jackson.core.JsonParseException
Overrides:
_createParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createParser

protected FromXmlParser _createParser(Reader r,
                                      com.fasterxml.jackson.core.io.IOContext ctxt)
                               throws IOException,
                                      com.fasterxml.jackson.core.JsonParseException
Overrides:
_createParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createParser

protected FromXmlParser _createParser(byte[] data,
                                      int offset,
                                      int len,
                                      com.fasterxml.jackson.core.io.IOContext ctxt)
                               throws IOException,
                                      com.fasterxml.jackson.core.JsonParseException
Overrides:
_createParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createJsonParser

@Deprecated
protected FromXmlParser _createJsonParser(InputStream in,
                                                     com.fasterxml.jackson.core.io.IOContext ctxt)
                                   throws IOException,
                                          com.fasterxml.jackson.core.JsonParseException
Deprecated. 

Overridable factory method that actually instantiates desired parser.

Overrides:
_createJsonParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createJsonParser

@Deprecated
protected FromXmlParser _createJsonParser(Reader r,
                                                     com.fasterxml.jackson.core.io.IOContext ctxt)
                                   throws IOException,
                                          com.fasterxml.jackson.core.JsonParseException
Deprecated. 

Overridable factory method that actually instantiates desired parser.

Overrides:
_createJsonParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createJsonParser

@Deprecated
protected FromXmlParser _createJsonParser(byte[] data,
                                                     int offset,
                                                     int len,
                                                     com.fasterxml.jackson.core.io.IOContext ctxt)
                                   throws IOException,
                                          com.fasterxml.jackson.core.JsonParseException
Deprecated. 

Overridable factory method that actually instantiates desired parser.

Overrides:
_createJsonParser in class com.fasterxml.jackson.core.JsonFactory
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_createXmlWriter

protected XMLStreamWriter _createXmlWriter(OutputStream out)
                                    throws IOException
Throws:
IOException

_createXmlWriter

protected XMLStreamWriter _createXmlWriter(Writer w)
                                    throws IOException
Throws:
IOException

_initializeXmlWriter

protected final XMLStreamWriter _initializeXmlWriter(XMLStreamWriter sw)
                                              throws IOException,
                                                     XMLStreamException
Throws:
IOException
XMLStreamException

_initializeXmlReader

protected final XMLStreamReader _initializeXmlReader(XMLStreamReader sr)
                                              throws IOException,
                                                     XMLStreamException
Throws:
IOException
XMLStreamException

hasXMLFormat

public static com.fasterxml.jackson.core.format.MatchStrength hasXMLFormat(com.fasterxml.jackson.core.format.InputAccessor acc)
                                                                    throws IOException
Method that tries to figure out if content seems to be in some kind of XML format. Note that implementation here is not nearly as robust as what underlying Stax parser will do; the idea is to first support common encodings, then expand as needed (for example, it is not all that hard to support UTF-16; but it is some work and not needed quite yet)

Throws:
IOException


Copyright © 2012 FasterXML. All Rights Reserved.