com.ctc.wstx.sw
Class SimpleOutputElement

java.lang.Object
  extended by com.ctc.wstx.sw.SimpleOutputElement
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

public final class SimpleOutputElement
extends java.lang.Object
implements javax.xml.namespace.NamespaceContext

Class that encapsulates information about a specific element in virtual output stack, for writers that do support namespaces, but do NOT do "repairing", that is, expect caller to provide full namespace mapping and writing guidance. It does, however, provide rudimentary URI-to-prefix mappings, for those StAX methods that only take local name and URI arguments.

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
static int PREFIX_MISBOUND
           
static int PREFIX_OK
           
static int PREFIX_UNBOUND
           
 
Method Summary
 void addPrefix(java.lang.String prefix, java.lang.String uri)
           
protected  void addToPool(SimpleOutputElement poolHead)
          Method called to temporarily link this instance to a pool, to allow reusing of instances with the same reader.
 void checkAttrWrite(java.lang.String nsURI, java.lang.String localName, java.lang.String value)
           
protected  SimpleOutputElement createChild(java.lang.String localName)
          Simplest factory method, which gets called when a 1-argument element output method is called.
protected  SimpleOutputElement createChild(java.lang.String prefix, java.lang.String localName, java.lang.String uri)
          Full factory method, used for 'normal' namespace qualified output methods.
static SimpleOutputElement createRoot()
           
 java.lang.String generateMapping(java.lang.String prefixBase, java.lang.String uri, int[] seqArr)
           
 java.lang.String getDefaultNsUri()
           
 java.lang.String getExplicitPrefix(java.lang.String uri)
          Method similar to getPrefix(), but one that will not accept the default namespace, only an explicit one.
 java.lang.String getLocalName()
           
 javax.xml.namespace.QName getName()
           
 java.lang.String getNameDesc()
           
 java.lang.String getNamespaceURI()
           
 java.lang.String getNamespaceURI(java.lang.String prefix)
           
 SimpleOutputElement getParent()
           
 java.lang.String getPrefix()
           
 java.lang.String getPrefix(java.lang.String uri)
           
 java.util.Iterator getPrefixes(java.lang.String uri)
           
 int isPrefixValid(java.lang.String prefix, java.lang.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.
 boolean isRoot()
           
protected  SimpleOutputElement reuseAsChild(SimpleOutputElement parent, java.lang.String localName)
           
protected  SimpleOutputElement reuseAsChild(SimpleOutputElement parent, java.lang.String prefix, java.lang.String localName, java.lang.String uri)
           
 void setDefaultNsUri(java.lang.String uri)
           
 void setPrefix(java.lang.String prefix)
           
protected  void setRootNsContext(javax.xml.namespace.NamespaceContext ctxt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Method Detail

createRoot

public static SimpleOutputElement createRoot()

createChild

protected SimpleOutputElement createChild(java.lang.String localName)
Simplest factory method, which gets called when a 1-argument element output method is called. It is, then, assumed to use the default namespce.


reuseAsChild

protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent,
                                           java.lang.String localName)
Returns:
New head of the recycle pool

reuseAsChild

protected SimpleOutputElement reuseAsChild(SimpleOutputElement parent,
                                           java.lang.String prefix,
                                           java.lang.String localName,
                                           java.lang.String uri)

createChild

protected SimpleOutputElement createChild(java.lang.String prefix,
                                          java.lang.String localName,
                                          java.lang.String uri)
Full factory method, used for 'normal' namespace qualified output methods.


setRootNsContext

protected void setRootNsContext(javax.xml.namespace.NamespaceContext ctxt)

addToPool

protected void addToPool(SimpleOutputElement poolHead)
Method called to temporarily link this instance to a pool, to allow reusing of instances with the same reader.


getParent

public SimpleOutputElement getParent()

isRoot

public boolean isRoot()

getNameDesc

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

getPrefix

public java.lang.String getPrefix()

getLocalName

public java.lang.String getLocalName()

getNamespaceURI

public java.lang.String getNamespaceURI()

getDefaultNsUri

public java.lang.String getDefaultNsUri()

getName

public javax.xml.namespace.QName getName()

getExplicitPrefix

public java.lang.String getExplicitPrefix(java.lang.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.


isPrefixValid

public int isPrefixValid(java.lang.String prefix,
                         java.lang.String nsURI,
                         boolean isElement)
                  throws javax.xml.stream.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:
javax.xml.stream.XMLStreamException - True if default (no) prefix is allowed to match a non-default URI (elements); false if not (attributes)

checkAttrWrite

public void checkAttrWrite(java.lang.String nsURI,
                           java.lang.String localName,
                           java.lang.String value)
                    throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

setDefaultNsUri

public void setDefaultNsUri(java.lang.String uri)

setPrefix

public void setPrefix(java.lang.String prefix)

generateMapping

public java.lang.String generateMapping(java.lang.String prefixBase,
                                        java.lang.String uri,
                                        int[] seqArr)

addPrefix

public void addPrefix(java.lang.String prefix,
                      java.lang.String uri)

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
Specified by:
getNamespaceURI in interface javax.xml.namespace.NamespaceContext

getPrefix

public java.lang.String getPrefix(java.lang.String uri)
Specified by:
getPrefix in interface javax.xml.namespace.NamespaceContext

getPrefixes

public java.util.Iterator getPrefixes(java.lang.String uri)
Specified by:
getPrefixes in interface javax.xml.namespace.NamespaceContext