Package com.ctc.wstx.sw
Class OutputElementBase
- java.lang.Object
-
- com.ctc.wstx.sw.OutputElementBase
-
- All Implemented Interfaces:
NamespaceContext
- Direct Known Subclasses:
DOMOutputElement,SimpleOutputElement
public abstract class OutputElementBase extends Object implements NamespaceContext
Class that encapsulates information about a specific element in virtual output stack for namespace-aware writers. It provides support for URI-to-prefix mappings as well as namespace mapping generation.One noteworthy feature of the class is that it is designed to allow "short-term recycling", ie. instances can be reused within context of a simple document output. While reuse/recycling of such lightweight object is often useless or even counter productive, here it may be worth using, due to simplicity of the scheme (basically using a very simple free-elements linked list).
-
-
Field Summary
Fields Modifier and Type Field Description protected StringmDefaultNsURIprotected BijectiveNsMapmNsMappingMapping of namespace prefixes to URIs and back.protected booleanmNsMapSharedTrue, ifmNsMappingis a shared copy from the parent; false if a local copy was created (which happens when namespaces get bound etc).protected NamespaceContextmRootNsContextNamespace context end application may have supplied, and that (if given) should be used to augment explicitly defined bindings.static intPREFIX_MISBOUNDstatic intPREFIX_OKstatic intPREFIX_UNBOUND
-
Constructor Summary
Constructors Modifier Constructor Description protectedOutputElementBase()Constructor for the virtual root elementprotectedOutputElementBase(OutputElementBase parent, BijectiveNsMap ns)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPrefix(String prefix, String uri)StringgenerateMapping(String prefixBase, String uri, int[] seqArr)StringgetDefaultNsUri()StringgetExplicitPrefix(String uri)Method similar togetPrefix(java.lang.String), but one that will not accept the default namespace, only an explicit one.abstract StringgetNameDesc()StringgetNamespaceURI(String prefix)StringgetPrefix(String uri)Iterator<String>getPrefixes(String uri)intisPrefixValid(String prefix, String nsURI, boolean isElement)Method that verifies that passed-in prefix indeed maps to the specified namespace URI; and depending on how it goes returns a status for caller.abstract booleanisRoot()protected voidrelink(OutputElementBase parent)Method called to reuse a pooled instance.abstract voidsetDefaultNsUri(String uri)protected abstract voidsetRootNsContext(NamespaceContext ctxt)protected voidthrowOutputError(String msg)
-
-
-
Field Detail
-
PREFIX_UNBOUND
public static final int PREFIX_UNBOUND
- See Also:
- Constant Field Values
-
PREFIX_OK
public static final int PREFIX_OK
- See Also:
- Constant Field Values
-
PREFIX_MISBOUND
public static final int PREFIX_MISBOUND
- See Also:
- Constant Field Values
-
mRootNsContext
protected NamespaceContext mRootNsContext
Namespace context end application may have supplied, and that (if given) should be used to augment explicitly defined bindings.
-
mDefaultNsURI
protected String mDefaultNsURI
-
mNsMapping
protected BijectiveNsMap mNsMapping
Mapping of namespace prefixes to URIs and back.
-
mNsMapShared
protected boolean mNsMapShared
True, ifmNsMappingis a shared copy from the parent; false if a local copy was created (which happens when namespaces get bound etc).
-
-
Constructor Detail
-
OutputElementBase
protected OutputElementBase()
Constructor for the virtual root element
-
OutputElementBase
protected OutputElementBase(OutputElementBase parent, BijectiveNsMap ns)
-
-
Method Detail
-
relink
protected void relink(OutputElementBase parent)
Method called to reuse a pooled instance.
-
setRootNsContext
protected abstract void setRootNsContext(NamespaceContext ctxt)
-
isRoot
public abstract boolean isRoot()
-
getNameDesc
public abstract String getNameDesc()
- Returns:
- String presentation of the fully-qualified name, in "prefix:localName" format (no URI). Useful for error and debugging messages.
-
getDefaultNsUri
public final String getDefaultNsUri()
-
getExplicitPrefix
public final String getExplicitPrefix(String uri)
Method similar togetPrefix(java.lang.String), but one that will not accept the default namespace, only an explicit one. Usually used when trying to find a prefix for attributes.
-
isPrefixValid
public final int isPrefixValid(String prefix, String nsURI, boolean isElement) throws XMLStreamException
Method that verifies that passed-in prefix indeed maps to the specified namespace URI; and depending on how it goes returns a status for caller.- Parameters:
isElement- If true, rules for the default NS are those of elements (ie. empty prefix can map to non-default namespace); if false, rules are those of attributes (only non-default prefix can map to a non-default namespace).- Returns:
- PREFIX_OK, if passed-in prefix matches matched-in namespace URI in current scope; PREFIX_UNBOUND if it's not bound to anything, and PREFIX_MISBOUND if it's bound to another URI.
- Throws:
XMLStreamException- True if default (no) prefix is allowed to match a non-default URI (elements); false if not (attributes)
-
setDefaultNsUri
public abstract void setDefaultNsUri(String uri)
-
getNamespaceURI
public final String getNamespaceURI(String prefix)
- Specified by:
getNamespaceURIin interfaceNamespaceContext
-
getPrefix
public final String getPrefix(String uri)
- Specified by:
getPrefixin interfaceNamespaceContext
-
getPrefixes
public final Iterator<String> getPrefixes(String uri)
- Specified by:
getPrefixesin interfaceNamespaceContext
-
throwOutputError
protected final void throwOutputError(String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
-