## javanet.staxutils.helpers
Class ElementContext

    java.lang.Object
      javanet.staxutils.SimpleNamespaceContext
          javanet.staxutils.helpers.ElementContext

All Implemented Interfaces:
  ExtendedNamespaceContext, StaticNamespaceContext, NamespaceContext

    public class ElementContext

extends SimpleNamespaceContext

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
`ElementContext(QName name)` Constructs a new `ElementContext` with the provided name and no enclosing context.
`ElementContext(QName name, boolean isEmpty)` Constructs a new `ElementContext` with the provided name and empty value, and no enclosing context.
`ElementContext(QName name, ElementContext parent)` Constructs a new `ElementContext` with the provided name and enclosing context.
`ElementContext(QName name, ElementContext parent, boolean isEmpty)` Constructs a new `ElementContext` with the provided name and enclosing context.
`ElementContext(QName name, NamespaceContext context)` Constructs a new `ElementContext` with the provided name and namespace context.

Method Summary
`StringBuffer` `appendPath(StringBuffer buffer)` Appends the current context path to a `StringBuffer`.
`int` `attributeCount()` Returns the number of attributes defined in this context.
`boolean` `attributeExists(QName name)` Determines if an attribute with the specified name exists in this context.
`Iterator` `attributeNames()` Returns an `Iterator` over the names of all attributes defined in this context.
`String` `getAttribute(int idx)` Returns the value of the `idx`th attribute defined on the context.
`String` `getAttribute(QName name)` Returns the value of a named attribute.
`QName` `getAttributeName(int idx)` Returns the name of the `idx`th attribute defined on the context.
`int` `getDepth()` Determines the number of enclosing contexts.
`QName` `getName()` Returns the qualified name associated with the context.
`String` `getNamespacePrefix(int idx)` Returns the prefix of the `idx`th namespace declaration defined in this context.
`String` `getNamespaceURI(int idx)` Returns the URI of the `idx`th namespace declaration defined in this context.
`ElementContext` `getParentContext()` Returns a reference to the enclosing `ElementContext`.
`String` `getPath()` Returns the current context path.
`boolean` `isEmpty()` Whether this context represents an emtpy element.
`boolean` `isReadOnly()` Whether this context may be edited or not.
`boolean` `isRoot()` Determines if this context has an enclosing context or not.
`int` `namespaceCount()` Determines the number of namespaces declared in this context.
`ElementContext` `newSubContext(QName name)` Constructs a new child `ElementContext` with the specified name.
`ElementContext` `newSubContext(QName name, boolean isEmpty)` Constructs a new child `ElementContext` with the specified name and empty value.
`void` `putAttribute(QName name, String value)` Adds an attribute to the context with the specified name and value.
`void` `putNamespace(String prefix, String nsURI)` Adds a namespace declaration to this context with the specified prefix and namespace uri.
`void` `setReadOnly()` Prevents any further additions to this context.
`String` `toString()`

Methods inherited from class javanet.staxutils.SimpleNamespaceContext
`getDeclaredPrefixCount, getDeclaredPrefixes, getNamespaceURI, getParent, getPrefix, getPrefixes, getPrefixes, isPrefixDeclared, isRootContext, setDefaultNamespace, setParent, setPrefix`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ElementContext

    public ElementContext(QName name)

  Constructs a new `ElementContext` with the provided name and no enclosing context.

  Parameters:
    `name` - The element name.

### ElementContext

    public ElementContext(QName name,
                          boolean isEmpty)

  Constructs a new `ElementContext` with 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

    public ElementContext(QName name,
                          NamespaceContext context)

  Constructs a new `ElementContext` with the provided name and namespace context.

  Parameters:
    `name` - The element name.
    `context` - The enclosing namespace context.

### ElementContext

    public ElementContext(QName name,
                          ElementContext parent)

  Constructs a new `ElementContext` with the provided name and enclosing context.

  Parameters:
    `name` - The element name.
    `parent` - The enclosing element context.

### ElementContext

    public ElementContext(QName name,
                          ElementContext parent,
                          boolean isEmpty)

  Constructs a new `ElementContext` with 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 Detail

### getParentContext

    public ElementContext getParentContext()

  Returns a reference to the enclosing `ElementContext`.

  Returns:
    The enclosing context, or `null`.

### isRoot

    public boolean isRoot()

  Determines if this context has an enclosing context or not.

  Returns:
    `true` if this context is the root context and has no enclosing context, `false` otherwise.

### getName

    public QName getName()

  Returns the qualified name associated with the context.

  Returns:
    The qualified name of the context.

### getPath

    public String getPath()

  Returns the current context path.

  Returns:
    A string representing the context path.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`
  See Also:
    `getPath()`

### appendPath

    public StringBuffer appendPath(StringBuffer buffer)

  Appends the current context path to a `StringBuffer`.

  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

    public ElementContext newSubContext(QName name)

  Constructs a new child `ElementContext` with 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

    public ElementContext newSubContext(QName name,
                                        boolean isEmpty)

  Constructs a new child `ElementContext` with 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

    public void putAttribute(QName name,
                             String value)

  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

    public void putNamespace(String prefix,
                             String nsURI)

  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

    public String getAttribute(int idx)

  Returns the value of the `idx`th attribute defined on the context.

  Parameters:
    `idx` - The zero-based index of the attribute value to retrieve.
  Returns:
    The value of the `idx`th attribute defined on the context.
  Throws:
    `IndexOutOfBoundsException` - If the index is out of bounds.

### getAttributeName

    public QName getAttributeName(int idx)

  Returns the name of the `idx`th attribute defined on the context.

  Parameters:
    `idx` - The zero-based index of the attribute name to retrieve.
  Returns:
    The name of the `idx`th attribute defined on the context.
  Throws:
    `IndexOutOfBoundsException` - If the index is out of bounds.

### getAttribute

    public String getAttribute(QName name)

  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

    public boolean attributeExists(QName name)

  Determines if an attribute with the specified name exists in this context.

  Parameters:
    `name` - The name of the attribute.
  Returns:
    `true` if an attribute with the specified name has been defined in this context, `false` otherwise.

### attributeNames

    public Iterator attributeNames()

  Returns an `Iterator` over the names of all attributes defined in this context. The returned iterator will not support the `Iterator.remove()` operation.

  Returns:
    An `Iterator` over 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

    public String getNamespaceURI(int idx)

  Returns the URI of the `idx`th namespace declaration defined in this context.

  Parameters:
    `idx` - The index of the namespace URI to return.
  Returns:
    The URI of the `idx`th namespace declaration defined in this context.
  Throws:
    `IndexOutOfBoundsException` - If the index is out of bounds.

### getNamespacePrefix

    public String getNamespacePrefix(int idx)

  Returns the prefix of the `idx`th namespace declaration defined in this context.

  Parameters:
    `idx` - The index of the namespace prefix to return.
  Returns:
    The prefix of the `idx`th 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:
    `true` if no additional modifications may be made to this context, `false` otherwise.

### 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:
    `true` if this context represents an emtpy element, `false` otherwise.