Top Description Fields Constructors Methods
com.ctc.wstx.sw

public abstract Class OutputElementBase

extends Object
implements NamespaceContext
Class Inheritance
All Implemented Interfaces
javax.xml.namespace.NamespaceContext
Known Direct Subclasses
com.ctc.wstx.sw.SimpleOutputElement, com.ctc.wstx.dom.DOMOutputElement
Imports
java.util.*, javax.xml.XMLConstants, javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLStreamException, com.ctc.wstx.util.BijectiveNsMap, .DataUtil

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

Modifier and TypeField and Description
protected static final BijectiveNsMap
protected String
protected BijectiveNsMap
mNsMapping

Mapping of namespace prefixes to URIs and back.

protected boolean
mNsMapShared

True, if mNsMapping is a shared copy from the parent; false if a local copy was created (which happens when namespaces get bound etc).

protected NamespaceContext
mRootNsContext

Namespace context end application may have supplied, and that (if given) should be used to augment explicitly defined bindings.

public static final int
public static final int
public static final int
protected static final String
protected static final String

Constructor Summary

AccessConstructor and Description
protected
OutputElementBase()

Constructor for the virtual root element

protected

Method Summary

Modifier and TypeMethod and Description
public final void
addPrefix(String prefix, String uri)

public final String
generateMapping(String prefixBase, String uri, int[] seqArr)

public final String
public final String
getExplicitPrefix(String uri)

Method similar to getPrefix, but one that will not accept the default namespace, only an explicit one.

public abstract String

Returns:

String presentation of the fully-qualified name, in "prefix:localName" format (no URI). Useful for error and debugging messages.
getNameDesc
()

public final String
getNamespaceURI(String
prefix to look up
prefix
)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Get Namespace URI bound to a prefix in the current scope.

public final String
getPrefix(String
URI of Namespace to lookup
uri
)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Get prefix bound to Namespace URI in the current scope.

public final Iterator<String>
getPrefixes(String
URI of Namespace to lookup
uri
)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

public final int

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.
isPrefixValid
(String prefix, String nsURI, boolean
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).
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.

public abstract boolean
public abstract void
protected abstract void
protected final void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_XML_BINDINGSback to summary
protected static final BijectiveNsMap DEFAULT_XML_BINDINGS
mDefaultNsURIback to summary
protected String mDefaultNsURI
mNsMappingback to summary
protected BijectiveNsMap mNsMapping

Mapping of namespace prefixes to URIs and back.

mNsMapSharedback to summary
protected boolean mNsMapShared

True, if mNsMapping is a shared copy from the parent; false if a local copy was created (which happens when namespaces get bound etc).

mRootNsContextback to summary
protected NamespaceContext mRootNsContext

Namespace context end application may have supplied, and that (if given) should be used to augment explicitly defined bindings.

PREFIX_MISBOUNDback to summary
public static final int PREFIX_MISBOUND
PREFIX_OKback to summary
public static final int PREFIX_OK
PREFIX_UNBOUNDback to summary
public static final int PREFIX_UNBOUND
sXmlNsPrefixback to summary
protected static final String sXmlNsPrefix
sXmlNsURIback to summary
protected static final String sXmlNsURI

Constructor Detail

OutputElementBaseback to summary
protected OutputElementBase()

Constructor for the virtual root element

OutputElementBaseback to summary
protected OutputElementBase(OutputElementBase parent, BijectiveNsMap ns)

Method Detail

addPrefixback to summary
public final void addPrefix(String prefix, String uri)
generateMappingback to summary
public final String generateMapping(String prefixBase, String uri, int[] seqArr)
getDefaultNsUriback to summary
public final String getDefaultNsUri()
getExplicitPrefixback to summary
public final String getExplicitPrefix(String uri)

Method similar to getPrefix, but one that will not accept the default namespace, only an explicit one. Usually used when trying to find a prefix for attributes.

getNameDescback to summary
public abstract String getNameDesc()
Returns:String

String presentation of the fully-qualified name, in "prefix:localName" format (no URI). Useful for error and debugging messages.

getNamespaceURIback to summary
public final String getNamespaceURI(String prefix)

Implements javax.xml.namespace.NamespaceContext.getNamespaceURI.

Doc from javax.xml.namespace.NamespaceContext.getNamespaceURI.

Get Namespace URI bound to a prefix in the current scope.

When requesting a Namespace URI by prefix, the following table describes the returned Namespace URI value for all possible prefix values:

Return value for specified prefixes
prefix parameter Namespace URI return value
DEFAULT_NS_PREFIX ("") default Namespace URI in the current scope or XMLConstants.NULL_NS_URI("") when there is no default Namespace URI in the current scope
bound prefix Namespace URI bound to prefix in current scope
unbound prefix XMLConstants.NULL_NS_URI("")
XMLConstants.XML_NS_PREFIX ("xml") XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace")
XMLConstants.XMLNS_ATTRIBUTE ("xmlns") XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/")
null IllegalArgumentException is thrown
Parameters
prefix:String

prefix to look up

Returns:String

Namespace URI bound to prefix in the current scope

Annotations
@Override
getPrefixback to summary
public final String getPrefix(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Doc from javax.xml.namespace.NamespaceContext.getPrefix.

Get prefix bound to Namespace URI in the current scope.

To get all prefixes bound to a Namespace URI in the current scope, use getPrefixes(String namespaceURI).

When requesting a prefix by Namespace URI, the following table describes the returned prefix value for all Namespace URI values:

Return value for specified Namespace URIs
Namespace URI parameter prefix value returned
<default Namespace URI> XMLConstants.DEFAULT_NS_PREFIX ("")
bound Namespace URI prefix bound to Namespace URI in the current scope, if multiple prefixes are bound to the Namespace URI in the current scope, a single arbitrary prefix, whose choice is implementation dependent, is returned
unbound Namespace URI null
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Parameters
uri:String

URI of Namespace to lookup

Returns:String

prefix bound to Namespace URI in current context

Annotations
@Override
getPrefixesback to summary
public final Iterator<String> getPrefixes(String uri)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Doc from javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

An Iterator over String elements is returned in an arbitrary, implementation dependent, order.

The Iterator is not modifiable. e.g. the remove() method will throw UnsupportedOperationException.

When requesting prefixes by Namespace URI, the following table describes the returned prefixes value for all Namespace URI values:

Return value for specified Namespace URIs
Namespace URI parameter prefixes value returned
bound Namespace URI, including the <default Namespace URI> Iterator over prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order
unbound Namespace URI empty Iterator
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") Iterator with one element set to XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") Iterator with one element set to XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Parameters
uri:String

URI of Namespace to lookup

Returns:Iterator<String>

Iterator for all prefixes bound to the Namespace URI in the current scope

Annotations
@Override
isPrefixValidback to summary
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:boolean

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:int

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.

Exceptions
XMLStreamException:
True if default (no) prefix is allowed to match a non-default URI (elements); false if not (attributes)
isRootback to summary
public abstract boolean isRoot()
setDefaultNsUriback to summary
public abstract void setDefaultNsUri(String uri)
setRootNsContextback to summary
protected abstract void setRootNsContext(NamespaceContext ctxt)
throwOutputErrorback to summary
protected final void throwOutputError(String msg) throws XMLStreamException