org.jibx.runtime.impl
Class XMLWriterBase

java.lang.Object
  extended byorg.jibx.runtime.impl.XMLWriterNamespaceBase
      extended byorg.jibx.runtime.impl.XMLWriterBase
All Implemented Interfaces:
IXMLWriter
Direct Known Subclasses:
GenericXMLWriter, StreamWriterBase

public abstract class XMLWriterBase
extends XMLWriterNamespaceBase

Base implementation of XML writer interface. This provides common handling of indentation and formatting that can be used for all forms of text output.

Version:
1.0
Author:
Dennis M. Sosnoski

Nested Class Summary
 
Nested classes inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
 
Field Summary
private  boolean m_contentSeen
          Flag for current element has content.
private  boolean m_textSeen
          Flag for current element has text content.
 
Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
 
Constructor Summary
XMLWriterBase(java.lang.String[] uris)
          Constructor.
XMLWriterBase(XMLWriterBase base, java.lang.String[] uris)
          Copy constructor.
 
Method Summary
 void addAttribute(int index, java.lang.String name, java.lang.String value)
          Add attribute to current open start tag.
abstract  void close()
          Close document output.
 void closeEmptyTag()
          Close the current open start tag as an empty element.
 void closeStartTag()
          Close the current open start tag.
abstract  IXMLWriter createChildWriter(java.lang.String[] uris)
          Create a child writer instance to be used for a separate binding.
 void endTag(int index, java.lang.String name)
          Generate end tag.
protected  void flagContent()
          Set up for writing any content to element.
protected  void flagTextContent()
          Set up for writing text content to element.
abstract  void flush()
          Flush document output.
protected abstract  void indent(int bias)
          Request output indent with bias from current element nesting level.
 void reset()
          Reset to initial state for reuse.
 void startTagClosed(int index, java.lang.String name)
          Generate closed start tag.
 void startTagNamespaces(int index, java.lang.String name, int[] nums, java.lang.String[] prefs)
          Generate start tag for element with namespaces.
 void startTagOpen(int index, java.lang.String name)
          Generate open start tag.
protected abstract  void writeAttributeText(java.lang.String text)
          Write attribute text to output.
 void writeComment(java.lang.String text)
          Write comment to document.
 void writeDocType(java.lang.String name, java.lang.String sys, java.lang.String pub, java.lang.String subset)
          Write DOCTYPE declaration to document.
 void writeEntityRef(java.lang.String name)
          Write entity reference to document.
protected abstract  void writeMarkup(char chr)
          Write markup character to output.
protected abstract  void writeMarkup(java.lang.String text)
          Write markup text to output.
 void writePI(java.lang.String target, java.lang.String data)
          Write processing instruction to document.
protected abstract  void writePrefix(int index)
          Write namespace prefix to output.
 void writeXMLDecl(java.lang.String version, java.lang.String encoding, java.lang.String standalone)
          Write XML declaration to document.
 
Methods inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
decrementNesting, defineNamespace, getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, growArray, incrementNesting, openNamespaces, popExtensionNamespaces, pushExtensionNamespaces, shrinkArray, undefineNamespace
 
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
indent, setIndentSpaces, writeCData, writeTextContent
 

Field Detail

m_textSeen

private boolean m_textSeen
Flag for current element has text content.


m_contentSeen

private boolean m_contentSeen
Flag for current element has content.

Constructor Detail

XMLWriterBase

public XMLWriterBase(java.lang.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")

XMLWriterBase

public XMLWriterBase(XMLWriterBase base,
                     java.lang.String[] uris)
Copy constructor. This initializes the extension namespace information from an existing instance.

Parameters:
base - existing instance
uris - ordered array of URIs for namespaces used in document
Method Detail

writeMarkup

protected abstract void writeMarkup(java.lang.String text)
                             throws java.io.IOException
Write markup text to output. Markup text can be written directly to the output without the need for any escaping, but still needs to be properly encoded.

Parameters:
text - markup text to be written
Throws:
java.io.IOException - if error writing to document

writeMarkup

protected abstract void writeMarkup(char chr)
                             throws java.io.IOException
Write markup character to output. Markup text can be written directly to the output without the need for any escaping, but still needs to be properly encoded.

Parameters:
chr - markup character to be written
Throws:
java.io.IOException - if error writing to document

writePrefix

protected abstract void writePrefix(int index)
                             throws java.io.IOException
Write namespace prefix to output. This internal method is used to throw an exception when an undeclared prefix is used.

Parameters:
index - namespace URI index number
Throws:
java.io.IOException - if error writing to document

writeAttributeText

protected abstract void writeAttributeText(java.lang.String text)
                                    throws java.io.IOException
Write attribute text to output. This needs to write the text with any appropriate escaping.

Parameters:
text - attribute value text to be written
Throws:
java.io.IOException - if error writing to document

indent

protected abstract void indent(int bias)
                        throws java.io.IOException
Request output indent with bias from current element nesting level. This is used internally for proper indenting in special cases.

Throws:
java.io.IOException - on error writing to document

flagContent

protected final void flagContent()
                          throws java.io.IOException
Set up for writing any content to element. If the start tag for the element has not been closed, this will close it.

Throws:
java.io.IOException - on error writing to document

flagTextContent

protected final void flagTextContent()
                              throws java.io.IOException
Set up for writing text content to element. If the start tag for the element has not been closed, this will close it.

Throws:
java.io.IOException - on error writing to document

writeXMLDecl

public void writeXMLDecl(java.lang.String version,
                         java.lang.String encoding,
                         java.lang.String standalone)
                  throws java.io.IOException
Write XML declaration to document. This can only be called before any other methods in the interface are called.

Parameters:
version - XML version text
encoding - text for encoding attribute (unspecified if null)
standalone - text for standalone attribute (unspecified if null)
Throws:
java.io.IOException - on error writing to document

startTagOpen

public void startTagOpen(int index,
                         java.lang.String name)
                  throws java.io.IOException
Generate open start tag. This allows attributes to be added to the start tag, but must be followed by a closeStartTag() call.

Parameters:
index - namespace URI index number
name - unqualified element name
Throws:
java.io.IOException - on error writing to document

startTagNamespaces

public void startTagNamespaces(int index,
                               java.lang.String name,
                               int[] nums,
                               java.lang.String[] prefs)
                        throws java.io.IOException
Generate 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.

Parameters:
index - namespace URI index number
name - element name
nums - 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 (no null values, use "" for default namespace declaration)
Throws:
java.io.IOException - on error writing to document

addAttribute

public void addAttribute(int index,
                         java.lang.String name,
                         java.lang.String value)
                  throws java.io.IOException
Add attribute to current open start tag. This is only valid after a call to startTagOpen(int, java.lang.String) or startTagNamespaces(int, java.lang.String, int[], java.lang.String[]) and before the corresponding call to closeStartTag().

Parameters:
index - namespace URI index number
name - unqualified attribute name
value - text value for attribute
Throws:
java.io.IOException - on error writing to document

closeStartTag

public void closeStartTag()
                   throws java.io.IOException
Close the current open start tag. This is only valid after a call to startTagOpen(int, java.lang.String).

Throws:
java.io.IOException - on error writing to document

closeEmptyTag

public void closeEmptyTag()
                   throws java.io.IOException
Close the current open start tag as an empty element. This is only valid after a call to startTagOpen(int, java.lang.String).

Throws:
java.io.IOException - on error writing to document

startTagClosed

public void startTagClosed(int index,
                           java.lang.String name)
                    throws java.io.IOException
Generate closed start tag. No attributes or namespaces can be added to a start tag written using this call.

Parameters:
index - namespace URI index number
name - unqualified element name
Throws:
java.io.IOException - on error writing to document

endTag

public void endTag(int index,
                   java.lang.String name)
            throws java.io.IOException
Generate end tag.

Parameters:
index - namespace URI index number
name - unqualified element name
Throws:
java.io.IOException - on error writing to document

writeComment

public void writeComment(java.lang.String text)
                  throws java.io.IOException
Write comment to document.

Parameters:
text - comment text
Throws:
java.io.IOException - on error writing to document

writeEntityRef

public void writeEntityRef(java.lang.String name)
                    throws java.io.IOException
Write entity reference to document.

Parameters:
name - entity name
Throws:
java.io.IOException - on error writing to document

writeDocType

public void writeDocType(java.lang.String name,
                         java.lang.String sys,
                         java.lang.String pub,
                         java.lang.String subset)
                  throws java.io.IOException
Write DOCTYPE declaration to document.

Parameters:
name - root element name
sys - system ID (null if none, must be non-null for public ID to be used)
pub - public ID (null if none)
subset - internal subset (null if none)
Throws:
java.io.IOException - on error writing to document

writePI

public void writePI(java.lang.String target,
                    java.lang.String data)
             throws java.io.IOException
Write processing instruction to document.

Parameters:
target - processing instruction target name
data - processing instruction data
Throws:
java.io.IOException - on error writing to document

flush

public abstract void flush()
                    throws java.io.IOException
Flush document output. Forces out all output generated to this point.

Throws:
java.io.IOException - on error writing to document

close

public abstract void close()
                    throws java.io.IOException
Close document output. Completes writing of document output, including closing the output medium.

Throws:
java.io.IOException - on error writing to document

reset

public void reset()
Reset to initial state for reuse. The writer is serially reusable, as long as this method is called to clear any retained state information between uses. It is automatically called when output is set.

Specified by:
reset in interface IXMLWriter
Overrides:
reset in class XMLWriterNamespaceBase

createChildWriter

public abstract IXMLWriter createChildWriter(java.lang.String[] uris)
Create a child writer instance to be used for a separate binding. The child writer inherits the stream and encoding from this writer, while using the supplied namespace URIs.

Parameters:
uris - ordered array of URIs for namespaces used in document (see XMLWriterBase(String[]))
Returns:
child writer


Project Web Site