GXPARSE hosted by SourceForge.net Logo

ca.gorman.xml.parse.toolkit
Class AbstractElement

java.lang.Object
  extended by ca.gorman.xml.parse.toolkit.AbstractElement
All Implemented Interfaces:
Element
Direct Known Subclasses:
CoroutineElement, MutableElement

public abstract class AbstractElement
extends Object
implements Element

Abstract realization of Element.

This is a common base class for the parser's internal view of Element objects and the application programmer's external view of Element objects. Elements are presented to the application programmer as immutable objects, but are treated as mutable objects inside the parser. The mutable version is created by subclassing to expose the setters.


Constructor Summary
protected AbstractElement()
           Create an uninitialized AbstractElement.
protected AbstractElement(Element element)
           Create an initialized AbstractElement.
protected AbstractElement(QName qName)
           Create a named AbstractElement with empty attribute list.
protected AbstractElement(QName qName, Attribute[] attributes)
           Create an initialized AbstractElement.
 
Method Summary
 boolean equals(Object obj)
           Define Element equality as identity of instances.
 Attribute getAttribute(QName qName)
           Get a single attribute.
 Attribute[] getAttributes()
           Get element attributes
 int getChildCount()
           Get the number of Elements entered as children of this Element.
 Element getParent()
           Get parent element.
 QName getQName()
           Get QName.
 int getRepeatCount()
           Get the number of previous occurrences of this Element at the same level, when this Element is one of a repeating sequence with the same name.
 int getSiblingCount()
           Get the number of previous siblings at the same level as this Element.
 boolean hasAncestor(QName qName)
           Indicate whether the element has a named element as ancestor.
 int hashCode()
           Returns Object.hashCode.
 boolean hasParent(QName qName)
           Indicate whether the element has a named element as parent.
 AbstractElement newInstance(QName qName, Attribute[] attributes)
           Create an immutable AbstractElement.
protected  void setAttribute(Attribute attribute)
           Set or replace a single Attribute
protected  void setAttributes(Attribute[] attribute)
           Set or replace the entire list of attributes.
protected  void setParent(AbstractElement parent)
           Set or replace the parent element.
protected  void setQName(QName qName)
           Set element name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractElement

protected AbstractElement(QName qName,
                          Attribute[] attributes)

Create an initialized AbstractElement.


AbstractElement

protected AbstractElement(Element element)

Create an initialized AbstractElement.


AbstractElement

protected AbstractElement(QName qName)

Create a named AbstractElement with empty attribute list.


AbstractElement

protected AbstractElement()

Create an uninitialized AbstractElement.

Method Detail

newInstance

public AbstractElement newInstance(QName qName,
                                   Attribute[] attributes)

Create an immutable AbstractElement.


getQName

public final QName getQName()
Description copied from interface: Element

Get QName.

This identifies the Attribute by namespace and local name.

Specified by:
getQName in interface Element
Returns:
QName.

getAttribute

public final Attribute getAttribute(QName qName)
Description copied from interface: Element

Get a single attribute.

Specified by:
getAttribute in interface Element

getAttributes

public final Attribute[] getAttributes()
Description copied from interface: Element

Get element attributes

Specified by:
getAttributes in interface Element

getParent

public final Element getParent()
Description copied from interface: Element

Get parent element.

Specified by:
getParent in interface Element
Returns:
Parent element, or null when there is no parent.

hasParent

public final boolean hasParent(QName qName)
Description copied from interface: Element

Indicate whether the element has a named element as parent.

Specified by:
hasParent in interface Element

hasAncestor

public final boolean hasAncestor(QName qName)
Description copied from interface: Element

Indicate whether the element has a named element as ancestor.

Specified by:
hasAncestor in interface Element

getChildCount

public final int getChildCount()
Description copied from interface: Element

Get the number of Elements entered as children of this Element.

Includes the most recent child when invoked while in a descendent of the Element.

Specified by:
getChildCount in interface Element
Returns:
zero at the beginning of an Element, the number of children at the end of an Element, or an intermediate value when invoked while in a descendant of the Element.

getSiblingCount

public final int getSiblingCount()
Description copied from interface: Element

Get the number of previous siblings at the same level as this Element.

The current Element is not included in the count.

Specified by:
getSiblingCount in interface Element
Returns:
number of siblings, or zero when this is the first element in the level

getRepeatCount

public final int getRepeatCount()
Description copied from interface: Element

Get the number of previous occurrences of this Element at the same level, when this Element is one of a repeating sequence with the same name.

The current Element is not included in the count.

The count begins again after each change of name, unless the implementation documentation specifies otherwise.

Specified by:
getRepeatCount in interface Element
Returns:
number of previous repetitions

equals

public final boolean equals(Object obj)
Description copied from interface: Element

Define Element equality as identity of instances.

Specified by:
equals in interface Element
Overrides:
equals in class Object

hashCode

public final int hashCode()
Description copied from interface: Element

Returns Object.hashCode.

Specified by:
hashCode in interface Element
Overrides:
hashCode in class Object

setQName

protected void setQName(QName qName)

Set element name.

Throws:
NullPointerException - if qName is null

setAttribute

protected void setAttribute(Attribute attribute)

Set or replace a single Attribute

Throws:
NullPointerException - if attribute is null

setAttributes

protected void setAttributes(Attribute[] attribute)

Set or replace the entire list of attributes.

Throws:
NullPointerException - if attribute is null

setParent

protected void setParent(AbstractElement parent)

Set or replace the parent element.


GXPARSE download

GXPARSE Generic XML Stream Parser API and supporting tools.   Release $Name: gxparse-sf-alpha-2_0 $
Copyright 2003-2004 Ian E. Gorman
Released under GNU Lesser General Public License