Package javanet.staxutils.helpers
Class ElementContext
java.lang.Object
javanet.staxutils.SimpleNamespaceContext
javanet.staxutils.helpers.ElementContext
- All Implemented Interfaces:
ExtendedNamespaceContext,StaticNamespaceContext,NamespaceContext
Encapsulates access to contextual element information, such as the element name,
attributes, and namespaces. This class is useful for recording element information
in a stack to keep track of the current element c[position in a document.
- Version:
- $Revision: 1.1 $
- Author:
- Christian Niles
-
Field Summary
Fields inherited from class javanet.staxutils.SimpleNamespaceContext
namespaces -
Constructor Summary
ConstructorsConstructorDescriptionElementContext(QName name) Constructs a newElementContextwith the provided name and no enclosing context.ElementContext(QName name, boolean isEmpty) Constructs a newElementContextwith the provided name and empty value, and no enclosing context.ElementContext(QName name, ElementContext parent) Constructs a newElementContextwith the provided name and enclosing context.ElementContext(QName name, ElementContext parent, boolean isEmpty) Constructs a newElementContextwith the provided name and enclosing context.ElementContext(QName name, NamespaceContext context) Constructs a newElementContextwith the provided name and namespace context. -
Method Summary
Modifier and TypeMethodDescriptionappendPath(StringBuffer buffer) Appends the current context path to aStringBuffer.intReturns the number of attributes defined in this context.booleanattributeExists(QName name) Determines if an attribute with the specified name exists in this context.Returns anIteratorover the names of all attributes defined in this context.getAttribute(int idx) Returns the value of theidxth attribute defined on the context.getAttribute(QName name) Returns the value of a named attribute.getAttributeName(int idx) Returns the name of theidxth attribute defined on the context.intgetDepth()Determines the number of enclosing contexts.getName()Returns the qualified name associated with the context.getNamespacePrefix(int idx) Returns the prefix of theidxth namespace declaration defined in this context.getNamespaceURI(int idx) Returns the URI of theidxth namespace declaration defined in this context.Returns a reference to the enclosingElementContext.getPath()Returns the current context path.booleanisEmpty()Whether this context represents an emtpy element.booleanWhether this context may be edited or not.booleanisRoot()Determines if this context has an enclosing context or not.intDetermines the number of namespaces declared in this context.newSubContext(QName name) Constructs a new childElementContextwith the specified name.newSubContext(QName name, boolean isEmpty) Constructs a new childElementContextwith the specified name and empty value.voidputAttribute(QName name, String value) Adds an attribute to the context with the specified name and value.voidputNamespace(String prefix, String nsURI) Adds a namespace declaration to this context with the specified prefix and namespace uri.voidPrevents any further additions to this context.toString()Methods inherited from class javanet.staxutils.SimpleNamespaceContext
getDeclaredPrefixCount, getDeclaredPrefixes, getNamespaceURI, getParent, getPrefix, getPrefixes, getPrefixes, isPrefixDeclared, isRootContext, setDefaultNamespace, setParent, setPrefix
-
Constructor Details
-
ElementContext
Constructs a newElementContextwith the provided name and no enclosing context.- Parameters:
name- The element name.
-
ElementContext
Constructs a newElementContextwith the provided name and empty value, and no enclosing context.- Parameters:
name- The element name.isEmpty- Whether the element is an empty element or not.
-
ElementContext
Constructs a newElementContextwith the provided name and namespace context.- Parameters:
name- The element name.context- The enclosing namespace context.
-
ElementContext
Constructs a newElementContextwith the provided name and enclosing context.- Parameters:
name- The element name.parent- The enclosing element context.
-
ElementContext
Constructs a newElementContextwith the provided name and enclosing context.- Parameters:
name- The element name.parent- The enclosing element context.isEmpty- Whether the element is an empty element or not.
-
-
Method Details
-
getParentContext
Returns a reference to the enclosingElementContext.- Returns:
- The enclosing context, or
null.
-
isRoot
public boolean isRoot()Determines if this context has an enclosing context or not.- Returns:
trueif this context is the root context and has no enclosing context,falseotherwise.
-
getName
Returns the qualified name associated with the context.- Returns:
- The qualified name of the context.
-
getPath
Returns the current context path.- Returns:
- A string representing the context path.
-
toString
-
appendPath
Appends the current context path to aStringBuffer.- Parameters:
buffer- The buffer to which to append the context path.- Returns:
- The provided buffer.
-
getDepth
public int getDepth()Determines the number of enclosing contexts.- Returns:
- The number of enclosing contexts.
-
newSubContext
Constructs a new childElementContextwith the specified name.- Parameters:
name- The name associated with the child context.- Returns:
- The newly constructed child context.
- Throws:
IllegalStateException- If this context is empty.
-
newSubContext
Constructs a new childElementContextwith the specified name and empty value.- Parameters:
name- The name associated with the child context.isEmpty- Whether the child context represents an empty element.- Returns:
- The newly constructed child context.
- Throws:
IllegalStateException- If this context is empty.
-
putAttribute
Adds an attribute to the context with the specified name and value.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalStateException- If the context is read-only.
-
putNamespace
Adds a namespace declaration to this context with the specified prefix and namespace uri.- Parameters:
prefix- The namespace prefix.nsURI- The namespace uri.
-
attributeCount
public int attributeCount()Returns the number of attributes defined in this context.- Returns:
- The number of attributes defined in the context.
-
getAttribute
Returns the value of theidxth attribute defined on the context.- Parameters:
idx- The zero-based index of the attribute value to retrieve.- Returns:
- The value of the
idxth attribute defined on the context. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getAttributeName
Returns the name of theidxth attribute defined on the context.- Parameters:
idx- The zero-based index of the attribute name to retrieve.- Returns:
- The name of the
idxth attribute defined on the context. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getAttribute
Returns the value of a named attribute.- Parameters:
name- The name of the attribute value to retrieve.- Returns:
- The value of the named attribute, or
null.
-
attributeExists
Determines if an attribute with the specified name exists in this context.- Parameters:
name- The name of the attribute.- Returns:
trueif an attribute with the specified name has been defined in this context,falseotherwise.
-
attributeNames
Returns anIteratorover the names of all attributes defined in this context. The returned iterator will not support theIterator.remove()operation.- Returns:
- An
Iteratorover the names of all attributes defined in this context.
-
namespaceCount
public int namespaceCount()Determines the number of namespaces declared in this context.- Returns:
- The number of namespaces declared in this context.
-
getNamespaceURI
Returns the URI of theidxth namespace declaration defined in this context.- Parameters:
idx- The index of the namespace URI to return.- Returns:
- The URI of the
idxth namespace declaration defined in this context. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getNamespacePrefix
Returns the prefix of theidxth namespace declaration defined in this context.- Parameters:
idx- The index of the namespace prefix to return.- Returns:
- The prefix of the
idxth namespace declaration defined in this context. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
isReadOnly
public boolean isReadOnly()Whether this context may be edited or not.- Returns:
trueif no additional modifications may be made to this context,falseotherwise.
-
setReadOnly
public void setReadOnly()Prevents any further additions to this context. -
isEmpty
public boolean isEmpty()Whether this context represents an emtpy element. Empty contexts may not enclose any other contexts.- Returns:
trueif this context represents an emtpy element,falseotherwise.
-