Package org.jibx.runtime.impl
Class XMLWriterNamespaceBase
- java.lang.Object
-
- org.jibx.runtime.impl.XMLWriterNamespaceBase
-
- All Implemented Interfaces:
IXMLWriter
- Direct Known Subclasses:
StAXWriter,XMLWriterBase
public abstract class XMLWriterNamespaceBase extends Object implements IXMLWriter
Base implementation of XML writer interface namespace handling. This tracks only the namespace declarations and the element nesting depth. It can be used as a base class for all forms of output.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description protected String[]m_prefixesPrefixes currently defined for namespaces.protected String[]m_urisURIs for namespaces.
-
Constructor Summary
Constructors Constructor Description XMLWriterNamespaceBase(String[] uris)Constructor.XMLWriterNamespaceBase(XMLWriterNamespaceBase base, String[] uris)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voiddecrementNesting()Decrement the current nesting depth.protected abstract voiddefineNamespace(int index, String prefix)Report to subclass that namespace has been defined.String[][]getExtensionNamespaces()Get extension namespace URIs added to those in mapping.intgetNamespaceCount()Get the number of namespaces currently defined.StringgetNamespacePrefix(int index)Get current prefix defined for namespace.String[]getNamespaces()Get namespace URIs for mapping.StringgetNamespaceUri(int index)Get URI for namespace.intgetNestingDepth()Get the current element nesting depth.intgetPrefixIndex(String prefix)Get index of namespace mapped to prefix.protected static String[][]growArray(String[][] base, String[] items)Grow array of array of strings.protected voidincrementNesting()Increment the current nesting depth.protected StringinternalNamespacePrefix(int index)Get current prefix defined for translated namespace index.protected StringinternalNamespaceUri(int index)Get URI for translated namespace index.protected voidinternalSetUris(String[] uris)Set namespace URIs.int[]openNamespaces(int[] nums, String[] prefs)Open the specified namespaces.voidpopExtensionNamespaces()Remove extension namespace URIs.voidpopTranslationTable()Pop a translation table used for converting namespace index numbers to values matching the internal lookup.voidpushExtensionNamespaces(String[] uris)Append extension namespace URIs to those in mapping.voidpushTranslationTable(int[] table)Push a translation table to be used for converting namespace index numbers passed as arguments to values used for internal lookup.voidreset()Reset to initial state for reuse.protected static String[][]shrinkArray(String[][] base)Shrink array of array of strings.inttranslateNamespace(int index)Translate a namespace index number to match internal tables.protected abstract voidundefineNamespace(int index)Report to subclass that namespace has been undefined.-
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
addAttribute, close, closeEmptyTag, closeStartTag, endTag, flush, indent, init, setIndentSpaces, startTagClosed, startTagNamespaces, startTagOpen, writeCData, writeComment, writeDocType, writeEntityRef, writePI, writeTextContent, writeXMLDecl
-
-
-
-
Constructor Detail
-
XMLWriterNamespaceBase
public XMLWriterNamespaceBase(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")
-
XMLWriterNamespaceBase
public XMLWriterNamespaceBase(XMLWriterNamespaceBase base, String[] uris)
Copy constructor. This initializes the extension namespace information from an existing instance.- Parameters:
base- existing instanceuris- ordered array of URIs for namespaces used in document
-
-
Method Detail
-
defineNamespace
protected abstract void defineNamespace(int index, String prefix) throws IOExceptionReport to subclass that namespace has been defined.- Parameters:
index- post-translation namespace URI index numberprefix- prefix used for namespace- Throws:
IOException- if error writing to document
-
undefineNamespace
protected abstract void undefineNamespace(int index)
Report to subclass that namespace has been undefined.- Parameters:
index- post-translation namespace URI index number
-
internalSetUris
protected void internalSetUris(String[] uris)
Set namespace URIs. It is provided so that subclasses can implement easy reuse.- Parameters:
uris- ordered array of URIs for namespaces used in document
-
openNamespaces
public int[] openNamespaces(int[] nums, String[] prefs) throws IOExceptionOpen the specified namespaces. Previously active namespace declarations are not duplicated.- Specified by:
openNamespacesin interfaceIXMLWriter- Parameters:
nums- array of namespace indexes defined by this element (reference kept until namespaces are closed, values may be modified by this method)prefs- array of namespace prefixes mapped by this element (nonullvalues, use "" for default namespace declaration)- Returns:
- array of translated indexes for namespaces not previously active (the ones actually needing to be declared, in the case of text output)
- Throws:
IOException- on error writing to document
-
getNestingDepth
public final int getNestingDepth()
Get the current element nesting depth. Elements are only counted in the depth returned when they're officially open - after the start tag has been output and before the end tag has been output.- Specified by:
getNestingDepthin interfaceIXMLWriter- Returns:
- number of nested elements at current point in output
-
getNamespaceCount
public final int getNamespaceCount()
Get the number of namespaces currently defined. This is equivalent to the index of the next extension namespace added.- Specified by:
getNamespaceCountin interfaceIXMLWriter- Returns:
- namespace count
-
incrementNesting
protected void incrementNesting()
Increment the current nesting depth. Subclasses need to call this method whenever an element start tag is written.
-
decrementNesting
protected void decrementNesting()
Decrement the current nesting depth. Subclasses need to call this method whenever an element end tag is written.
-
reset
public void reset()
Reset to initial state for reuse. Subclasses overriding this method need to call this base class implementation during their processing.- Specified by:
resetin interfaceIXMLWriter
-
getNamespaces
public final String[] getNamespaces()
Get namespace URIs for mapping. This gets the full ordered array of namespaces known in the binding used for this marshalling, where the index number of each namespace URI is the namespace index used to lookup the prefix when marshalling a name in that namespace. The returned array must not be modified.- Specified by:
getNamespacesin interfaceIXMLWriter- Returns:
- array of namespaces
-
internalNamespaceUri
protected final String internalNamespaceUri(int index)
Get URI for translated namespace index.- Parameters:
index- namespace URI index number (post-translation)- Returns:
- namespace URI text, or
nullif the namespace index is invalid
-
getNamespaceUri
public final String getNamespaceUri(int index)
Get URI for namespace.- Specified by:
getNamespaceUriin interfaceIXMLWriter- Parameters:
index- namespace URI index number- Returns:
- namespace URI text, or
nullif the namespace index is invalid
-
internalNamespacePrefix
protected final String internalNamespacePrefix(int index)
Get current prefix defined for translated namespace index.- Parameters:
index- namespace URI index number (post-translation)- Returns:
- current prefix text, or
nullif the namespace is not currently mapped
-
getNamespacePrefix
public final String getNamespacePrefix(int index)
Get current prefix defined for namespace.- Specified by:
getNamespacePrefixin interfaceIXMLWriter- Parameters:
index- namespace URI index number- Returns:
- current prefix text, or
nullif the namespace is not currently mapped
-
getPrefixIndex
public final int getPrefixIndex(String prefix)
Get index of namespace mapped to prefix. If namespace translation is in use, the returned index will be the value prior to translation. This can be an expensive operation (regardless of whether translation is used or not) with time proportional to the number of namespaces defined, so it should be used with care.- Specified by:
getPrefixIndexin interfaceIXMLWriter- Parameters:
prefix- text to match (non-null, use "" for default prefix)- Returns:
- index namespace URI index number mapped to prefix
-
growArray
protected static String[][] growArray(String[][] base, String[] items)
Grow array of array of strings.- Parameters:
base- array to be grown (nullis treated as zero length)items- array of strings to be added at end of base array- Returns:
- array with added array of items
-
shrinkArray
protected static String[][] shrinkArray(String[][] base)
Shrink array of array of strings.- Parameters:
base- array to be shrunk- Returns:
- array with last set of items eliminated (
nullif empty)
-
pushExtensionNamespaces
public void pushExtensionNamespaces(String[] uris)
Append extension namespace URIs to those in mapping.- Specified by:
pushExtensionNamespacesin interfaceIXMLWriter- Parameters:
uris- namespace URIs to extend those in mapping
-
popExtensionNamespaces
public void popExtensionNamespaces()
Remove extension namespace URIs. This removes the last set of extension namespaces pushed usingpushExtensionNamespaces(java.lang.String[]).- Specified by:
popExtensionNamespacesin interfaceIXMLWriter
-
getExtensionNamespaces
public final String[][] getExtensionNamespaces()
Get extension namespace URIs added to those in mapping. This gets the current set of extension definitions. The returned arrays must not be modified.- Specified by:
getExtensionNamespacesin interfaceIXMLWriter- Returns:
- array of arrays of extension namespaces (
nullif none)
-
translateNamespace
public int translateNamespace(int index)
Translate a namespace index number to match internal tables.- Parameters:
index- raw namespace index- Returns:
- namespace index number for internal tables
-
pushTranslationTable
public void pushTranslationTable(int[] table)
Push a translation table to be used for converting namespace index numbers passed as arguments to values used for internal lookup. This allows a layer of indirection between the client code and the namespace definitions, designed for use in supporting precompiled bindings. The translated values must match the internal tables.- Specified by:
pushTranslationTablein interfaceIXMLWriter- Parameters:
table- translation table to be used (nullif no change)
-
popTranslationTable
public void popTranslationTable()
Pop a translation table used for converting namespace index numbers to values matching the internal lookup.- Specified by:
popTranslationTablein interfaceIXMLWriter
-
-