Package org.jibx.runtime.impl
Class XMLWriterNamespaceBase
java.lang.Object
org.jibx.runtime.impl.XMLWriterNamespaceBase
- All Implemented Interfaces:
IXMLWriter
- Direct Known Subclasses:
JDOMWriter
,StAXWriter
,XMLWriterBase
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Namespace declaration tracking information. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
Empty array for default return.private String[][]
Extension namespace prefixes (null
if not in use).private String[][]
Extension namespace URIs (null
if not in use).private int
Depth of top namespace declaration level.private Stack
Stack of information for namespace declarations.private int
Depth of nested tags.protected String[]
Prefixes currently defined for namespaces.private int[]
Current namespace translation table (null
if none).private Stack
Stack of namespace translation tables in use.protected String[]
URIs for namespaces. -
Constructor Summary
ConstructorsConstructorDescriptionXMLWriterNamespaceBase
(String[] uris) Constructor.XMLWriterNamespaceBase
(XMLWriterNamespaceBase base, String[] uris) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Ends the current innermost set of nested namespace definitions.protected void
Decrement the current nesting depth.protected abstract void
defineNamespace
(int index, String prefix) Report to subclass that namespace has been defined.final String[][]
Get extension namespace URIs added to those in mapping.final int
Get the number of namespaces currently defined.final String
getNamespacePrefix
(int index) Get current prefix defined for namespace.final String[]
Get namespace URIs for mapping.final String
getNamespaceUri
(int index) Get URI for namespace.final int
Get the current element nesting depth.final int
getPrefixIndex
(String prefix) Get index of namespace mapped to prefix.protected static String[][]
Grow array of array of strings.protected void
Increment the current nesting depth.protected final String
internalNamespacePrefix
(int index) Get current prefix defined for translated namespace index.protected final String
internalNamespaceUri
(int index) Get URI for translated namespace index.protected void
internalSetUris
(String[] uris) Set namespace URIs.int[]
openNamespaces
(int[] nums, String[] prefs) Open the specified namespaces.void
Remove extension namespace URIs.void
Pop a translation table used for converting namespace index numbers to values matching the internal lookup.void
pushExtensionNamespaces
(String[] uris) Append extension namespace URIs to those in mapping.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.void
reset()
Reset to initial state for reuse.private void
setNamespacePrefix
(int index, String prefix) Set prefix for namespace.protected static String[][]
shrinkArray
(String[][] base) Shrink array of array of strings.int
translateNamespace
(int index) Translate a namespace index number to match internal tables.protected abstract void
undefineNamespace
(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
-
Field Details
-
EMPTY_INT_ARRAY
private static final int[] EMPTY_INT_ARRAYEmpty array for default return. -
m_uris
URIs for namespaces. -
m_prefixes
Prefixes currently defined for namespaces. -
m_nestingDepth
private int m_nestingDepthDepth of nested tags. -
m_namespaceStack
Stack of information for namespace declarations. -
m_namespaceDepth
private int m_namespaceDepthDepth of top namespace declaration level. -
m_extensionUris
Extension namespace URIs (null
if not in use). -
m_extensionPrefixes
Extension namespace prefixes (null
if not in use). -
m_translateTable
private int[] m_translateTableCurrent namespace translation table (null
if none). -
m_translateTableStack
Stack of namespace translation tables in use.
-
-
Constructor Details
-
XMLWriterNamespaceBase
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
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 Details
-
defineNamespace
Report 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
Set namespace URIs. It is provided so that subclasses can implement easy reuse.- Parameters:
uris
- ordered array of URIs for namespaces used in document
-
setNamespacePrefix
Set prefix for namespace.- Parameters:
index
- post-translation namespace URI index numberprefix
-
-
openNamespaces
Open the specified namespaces. Previously active namespace declarations are not duplicated.- Specified by:
openNamespaces
in 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 (nonull
values, 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
-
closeNamespaces
private void closeNamespaces()Ends the current innermost set of nested namespace definitions. Reverts the namespaces involved to their previously-declared prefixes, and sets up for ending the new innermost set. -
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:
getNestingDepth
in 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:
getNamespaceCount
in 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:
reset
in interfaceIXMLWriter
-
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:
getNamespaces
in interfaceIXMLWriter
- Returns:
- array of namespaces
-
internalNamespaceUri
Get URI for translated namespace index.- Parameters:
index
- namespace URI index number (post-translation)- Returns:
- namespace URI text, or
null
if the namespace index is invalid
-
getNamespaceUri
Get URI for namespace.- Specified by:
getNamespaceUri
in interfaceIXMLWriter
- Parameters:
index
- namespace URI index number- Returns:
- namespace URI text, or
null
if the namespace index is invalid
-
internalNamespacePrefix
Get current prefix defined for translated namespace index.- Parameters:
index
- namespace URI index number (post-translation)- Returns:
- current prefix text, or
null
if the namespace is not currently mapped
-
getNamespacePrefix
Get current prefix defined for namespace.- Specified by:
getNamespacePrefix
in interfaceIXMLWriter
- Parameters:
index
- namespace URI index number- Returns:
- current prefix text, or
null
if the namespace is not currently mapped
-
getPrefixIndex
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:
getPrefixIndex
in interfaceIXMLWriter
- Parameters:
prefix
- text to match (non-null
, use "" for default prefix)- Returns:
- index namespace URI index number mapped to prefix
-
growArray
Grow array of array of strings.- Parameters:
base
- array to be grown (null
is treated as zero length)items
- array of strings to be added at end of base array- Returns:
- array with added array of items
-
shrinkArray
Shrink array of array of strings.- Parameters:
base
- array to be shrunk- Returns:
- array with last set of items eliminated (
null
if empty)
-
pushExtensionNamespaces
Append extension namespace URIs to those in mapping.- Specified by:
pushExtensionNamespaces
in 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:
popExtensionNamespaces
in interfaceIXMLWriter
-
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:
getExtensionNamespaces
in interfaceIXMLWriter
- Returns:
- array of arrays of extension namespaces (
null
if 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:
pushTranslationTable
in interfaceIXMLWriter
- Parameters:
table
- translation table to be used (null
if no change)
-
popTranslationTable
public void popTranslationTable()Pop a translation table used for converting namespace index numbers to values matching the internal lookup.- Specified by:
popTranslationTable
in interfaceIXMLWriter
-