Package org.jibx.runtime.impl
Class StAXWriter
- java.lang.Object
-
- org.jibx.runtime.impl.XMLWriterNamespaceBase
-
- org.jibx.runtime.impl.StAXWriter
-
- All Implemented Interfaces:
IExtensibleWriter,IXMLWriter
public class StAXWriter extends XMLWriterNamespaceBase implements IExtensibleWriter
Writer generating StAX parse event stream output.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
-
Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
-
-
Constructor Summary
Constructors Constructor Description StAXWriter(String[] uris)Constructor.StAXWriter(String[] uris, XMLStreamWriter wrtr)Constructor with writer supplied.StAXWriter(StAXWriter base, String[] uris)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(int index, String name, String value)Add attribute to current open start tag.voidclose()Close document output.voidcloseEmptyTag()Close the current open start tag as an empty element.voidcloseStartTag()Close the current open start tag.IXMLWritercreateChildWriter(String[] uris)Create a child writer instance to be used for a separate binding.protected voiddefineNamespace(int index, String prefix)Report to subclass that namespace has been defined.voidendTag(int index, String name)Generate end tag.voidflush()Flush document output.voidindent()Request output indent.voidinit()Initialize writer.voidsetIndentSpaces(int count, String newline, char indent)Set nesting indentation.voidsetWriter(XMLStreamWriter wrtr)Set StAX writer.voidstartTagClosed(int index, String name)Generate closed start tag.voidstartTagNamespaces(int index, String name, int[] nums, String[] prefs)Generate start tag for element with namespaces.voidstartTagOpen(int index, String name)Generate open start tag.protected voidundefineNamespace(int index)Report to subclass that namespace has been undefined.voidwriteCData(String text)Write CDATA text to document.voidwriteComment(String text)Write comment to document.voidwriteDocType(String name, String sys, String pub, String subset)Write DOCTYPE declaration to document.voidwriteEntityRef(String name)Write entity reference to document.voidwritePI(String target, String data)Write processing instruction to document.voidwriteTextContent(String text)Write ordinary character data text content to document.voidwriteXMLDecl(String version, String encoding, String standalone)Write XML declaration to document.-
Methods inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
decrementNesting, getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, growArray, incrementNesting, internalNamespacePrefix, internalNamespaceUri, internalSetUris, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable, reset, shrinkArray, translateNamespace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jibx.runtime.IXMLWriter
getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable, reset
-
-
-
-
Constructor Detail
-
StAXWriter
public StAXWriter(String[] uris)
Constructor.- Parameters:
uris- ordered array of URIs for namespaces used in document (must be constant; the value in position 0 must always be the empty string "", and the value in position 1 must always be the XML namespace "http://www.w3.org/XML/1998/namespace")
-
StAXWriter
public StAXWriter(String[] uris, XMLStreamWriter wrtr)
Constructor with writer supplied.- Parameters:
uris- ordered array of URIs for namespaces used in document (must be constant; the value in position 0 must always be the empty string "", and the value in position 1 must always be the XML namespace "http://www.w3.org/XML/1998/namespace")wrtr- StAX writer for parse event output
-
StAXWriter
public StAXWriter(StAXWriter base, String[] uris)
Copy constructor. This initializes the writer and extension namespace information from an existing instance.- Parameters:
base- existing instanceuris- ordered array of URIs for namespaces used in document
-
-
Method Detail
-
init
public void init()
Initialize writer.- Specified by:
initin interfaceIXMLWriter
-
setWriter
public void setWriter(XMLStreamWriter wrtr)
Set StAX writer.- Parameters:
wrtr- StAX writer for parse event output
-
defineNamespace
protected void defineNamespace(int index, String prefix) throws IOExceptionDescription copied from class:XMLWriterNamespaceBaseReport to subclass that namespace has been defined.- Specified by:
defineNamespacein classXMLWriterNamespaceBase- Parameters:
index- post-translation namespace URI index numberprefix- prefix used for namespace- Throws:
IOException- if error writing to document
-
undefineNamespace
protected void undefineNamespace(int index)
Description copied from class:XMLWriterNamespaceBaseReport to subclass that namespace has been undefined.- Specified by:
undefineNamespacein classXMLWriterNamespaceBase- Parameters:
index- post-translation namespace URI index number
-
setIndentSpaces
public void setIndentSpaces(int count, String newline, char indent)Description copied from interface:IXMLWriterSet nesting indentation. This is advisory only, and implementations of this interface are free to ignore it. The intent is to indicate that the generated output should use indenting to illustrate element nesting.- Specified by:
setIndentSpacesin interfaceIXMLWriter- Parameters:
count- number of character to indent per level, or disable indentation if negative (zero means new line only)newline- sequence of characters used for a line ending (nullmeans use the single character '\n')indent- whitespace character used for indentation
-
writeXMLDecl
public void writeXMLDecl(String version, String encoding, String standalone) throws IOException
Description copied from interface:IXMLWriterWrite XML declaration to document. This can only be called before any other methods in the interface are called.- Specified by:
writeXMLDeclin interfaceIXMLWriter- Parameters:
version- XML version textencoding- text for encoding attribute (unspecified ifnull)standalone- text for standalone attribute (unspecified ifnull)- Throws:
IOException- on error writing to document
-
startTagOpen
public void startTagOpen(int index, String name) throws IOExceptionDescription copied from interface:IXMLWriterGenerate open start tag. This allows attributes and/or namespace declarations to be added to the start tag, but must be followed by aIXMLWriter.closeStartTag()call.- Specified by:
startTagOpenin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
startTagNamespaces
public void startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws IOExceptionDescription copied from interface:IXMLWriterGenerate start tag for element with namespaces. This creates the actual start tag, along with any necessary namespace declarations. Previously active namespace declarations are not duplicated. The tag is left incomplete, allowing other attributes to be added.- Specified by:
startTagNamespacesin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- element namenums- array of namespace indexes defined by this element (must be constant, reference is kept until end of element)prefs- array of namespace prefixes mapped by this element (nonullvalues, use "" for default namespace declaration)- Throws:
IOException- on error writing to document
-
addAttribute
public void addAttribute(int index, String name, String value) throws IOExceptionDescription copied from interface:IXMLWriterAdd attribute to current open start tag. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String)and before the corresponding call toIXMLWriter.closeStartTag().- Specified by:
addAttributein interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified attribute namevalue- text value for attribute- Throws:
IOException- on error writing to document
-
closeStartTag
public void closeStartTag() throws IOExceptionDescription copied from interface:IXMLWriterClose the current open start tag. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String).- Specified by:
closeStartTagin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
closeEmptyTag
public void closeEmptyTag() throws IOExceptionDescription copied from interface:IXMLWriterClose the current open start tag as an empty element. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String).- Specified by:
closeEmptyTagin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
startTagClosed
public void startTagClosed(int index, String name) throws IOExceptionDescription copied from interface:IXMLWriterGenerate closed start tag. No attributes or namespaces can be added to a start tag written using this call.- Specified by:
startTagClosedin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
endTag
public void endTag(int index, String name) throws IOExceptionDescription copied from interface:IXMLWriterGenerate end tag.- Specified by:
endTagin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
writeTextContent
public void writeTextContent(String text) throws IOException
Description copied from interface:IXMLWriterWrite ordinary character data text content to document.- Specified by:
writeTextContentin interfaceIXMLWriter- Parameters:
text- content value text (must not benull)- Throws:
IOException- on error writing to document
-
writeCData
public void writeCData(String text) throws IOException
Description copied from interface:IXMLWriterWrite CDATA text to document.- Specified by:
writeCDatain interfaceIXMLWriter- Parameters:
text- content value text (must not benull)- Throws:
IOException- on error writing to document
-
writeComment
public void writeComment(String text) throws IOException
Description copied from interface:IXMLWriterWrite comment to document.- Specified by:
writeCommentin interfaceIXMLWriter- Parameters:
text- comment text (must not benull)- Throws:
IOException- on error writing to document
-
writeEntityRef
public void writeEntityRef(String name) throws IOException
Description copied from interface:IXMLWriterWrite entity reference to document.- Specified by:
writeEntityRefin interfaceIXMLWriter- Parameters:
name- entity name (must not benull)- Throws:
IOException- on error writing to document
-
writeDocType
public void writeDocType(String name, String sys, String pub, String subset) throws IOException
Description copied from interface:IXMLWriterWrite DOCTYPE declaration to document.- Specified by:
writeDocTypein interfaceIXMLWriter- Parameters:
name- root element namesys- system ID (nullif none, must be non-nullfor public ID to be used)pub- public ID (nullif none)subset- internal subset (nullif none)- Throws:
IOException- on error writing to document
-
writePI
public void writePI(String target, String data) throws IOException
Description copied from interface:IXMLWriterWrite processing instruction to document.- Specified by:
writePIin interfaceIXMLWriter- Parameters:
target- processing instruction target name (must not benull)data- processing instruction data (must not benull)- Throws:
IOException- on error writing to document
-
indent
public void indent() throws IOExceptionDescription copied from interface:IXMLWriterRequest output indent. The writer implementation should normally indent output as appropriate. This method can be used to request indenting of output that might otherwise not be indented. The normal effect when used with a text-oriented writer should be to output the appropriate line end sequence followed by the appropriate number of indent characters for the current nesting level.- Specified by:
indentin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
flush
public void flush() throws IOExceptionDescription copied from interface:IXMLWriterFlush document output. Writes any buffered data to the output medium. This does not flush the output medium itself, only any internal buffering within the writer.- Specified by:
flushin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
close
public void close() throws IOExceptionDescription copied from interface:IXMLWriterClose document output. Completes writing of document output, including flushing and closing the output medium.- Specified by:
closein interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
createChildWriter
public IXMLWriter createChildWriter(String[] uris)
Create a child writer instance to be used for a separate binding. The child writer inherits the output handling from this writer, while using the supplied namespace URIs.- Specified by:
createChildWriterin interfaceIExtensibleWriter- Parameters:
uris- ordered array of URIs for namespaces used in document (seeStAXWriter(String[]))- Returns:
- child writer
-
-