org.apache.pivot.xml
Class Element

java.lang.Object
  extended by org.apache.pivot.xml.Node
      extended by org.apache.pivot.xml.Element
All Implemented Interfaces:
Iterable<Node>, Collection<Node>, List<Node>, Sequence<Node>

public class Element
extends Node
implements List<Node>

Node class representing an XML element.


Nested Class Summary
static class Element.Attribute
          Class representing an XML attribute.
 class Element.AttributeSequence
          Sequence representing the attributes declared by this element.
 class Element.ElementDictionary
          Dictionary representing the attributes declared by this element.
 class Element.NamespaceDictionary
          Dictionary representing the namespaces declared by this element.
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.List
List.ItemIterator<T>, List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree<T>
 
Constructor Summary
Element(String localName)
           
Element(String namespacePrefix, String localName)
           
 
Method Summary
 int add(Node node)
          Adds a node to this element.
 void clear()
          Removes all nodes from this element.
 Node get(int index)
          Returns the node at the given index.
 Element.AttributeSequence getAttributes()
          Returns the element's attribute dictionary.
 Comparator<Node> getComparator()
          Returns the collection's sort order.
 String getDefaultNamespaceURI()
          Returns the element's default namespace URI.
 Element.ElementDictionary getElementDictionary()
          Returns the element's element dictionary.
 ListenerList<ElementListener> getElementListeners()
          Returns the element listener list.
 List<Element> getElements(String name)
          Returns the sub-elements of of this element whose tag names match the given name.
 int getLength()
          Returns the number of nodes contained by this element.
 ListenerList<ListListener<Node>> getListListeners()
          Returns the element's listener list.
 String getLocalName()
          Returns the element's local name.
 String getName()
          Returns the fully-qualified name of the element.
 String getNamespacePrefix()
          Returns the element's namespace prefix.
 Element.NamespaceDictionary getNamespaces()
          Returns the element's namespace dictionary.
 String getNamespaceURI(String prefix)
          Determines the namespace URI corresponding to the given prefix by traversing the element's ancestry.
 String getText()
          Returns the text content of this element.
 int indexOf(Node node)
          Determines the index of the given node within this element.
 void insert(Node node, int index)
          Inserts a node at a specific location within this element.
 boolean isEmpty()
          Determines if this element defines any attributes.
 Iterator<Node> iterator()
          Returns an iterator over this elements child nodes.
 Sequence<Node> remove(int index, int count)
          Removes a range of nodes from this element.
 int remove(Node node)
          Removes a node from this element.
 void setComparator(Comparator<Node> comparator)
          Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
 void setDefaultNamespaceURI(String defaultNamespaceURI)
          Sets the element's default namespace URI.
 String toString()
           
 Node update(int index, Node node)
          Updates the item at the given index.
 
Methods inherited from class org.apache.pivot.xml.Node
getNodeListeners, getParent, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

public Element(String localName)

Element

public Element(String namespacePrefix,
               String localName)
Method Detail

getNamespacePrefix

public String getNamespacePrefix()
Returns the element's namespace prefix.

Returns:
The element's namespace prefix, or null if the element belongs to the default namespace.

getLocalName

public String getLocalName()
Returns the element's local name.


getName

public String getName()
Returns the fully-qualified name of the element.


getDefaultNamespaceURI

public String getDefaultNamespaceURI()
Returns the element's default namespace URI.

Returns:
The default namespace URI declared by this element, or null if this element does not declare a default namespace.

setDefaultNamespaceURI

public void setDefaultNamespaceURI(String defaultNamespaceURI)
Sets the element's default namespace URI.

Parameters:
defaultNamespaceURI - The default namespace URI declared by this element, or null if this element does not declare a default namespace.

getNamespaces

public Element.NamespaceDictionary getNamespaces()
Returns the element's namespace dictionary.


getNamespaceURI

public String getNamespaceURI(String prefix)
Determines the namespace URI corresponding to the given prefix by traversing the element's ancestry.

Parameters:
prefix - The namespace prefix to look up, or null to determine the default namespace for this element.
Returns:
The namespace URI corresponding to the given prefix, or null if a URI could not be found.

getElementDictionary

public Element.ElementDictionary getElementDictionary()
Returns the element's element dictionary.


getAttributes

public Element.AttributeSequence getAttributes()
Returns the element's attribute dictionary.


add

public int add(Node node)
Adds a node to this element.

Specified by:
add in interface List<Node>
Specified by:
add in interface Sequence<Node>
Parameters:
node -
Returns:
The index at which the node was added.
See Also:
ListListener.itemInserted(List, int)

insert

public void insert(Node node,
                   int index)
Inserts a node at a specific location within this element.

Specified by:
insert in interface List<Node>
Specified by:
insert in interface Sequence<Node>
Parameters:
node -
index -
See Also:
ListListener.itemInserted(List, int)

update

public Node update(int index,
                   Node node)
Description copied from interface: List
Updates the item at the given index.

Specified by:
update in interface List<Node>
Specified by:
update in interface Sequence<Node>
Parameters:
index - The index of the item to update.
node - The item that will replace any existing value at the given index.
Returns:
The item that was previously stored at the given index.
Throws:
UnsupportedOperationException - This method is not supported.
See Also:
ListListener.itemUpdated(List, int, Object)

remove

public int remove(Node node)
Removes a node from this element.

Specified by:
remove in interface Sequence<Node>
Parameters:
node -
Returns:
The index of the item that was removed, or -1 if the item could not be found.
See Also:
Sequence.remove(int, int)

remove

public Sequence<Node> remove(int index,
                             int count)
Removes a range of nodes from this element.

Specified by:
remove in interface List<Node>
Specified by:
remove in interface Sequence<Node>
Parameters:
index -
count -
Returns:
The removed nodes.
See Also:
ListListener.itemsRemoved(List, int, Sequence)

clear

public void clear()
Removes all nodes from this element.

Specified by:
clear in interface Collection<Node>
Specified by:
clear in interface List<Node>
See Also:
ListListener.itemsRemoved(List, int, Sequence)

get

public Node get(int index)
Returns the node at the given index.

Specified by:
get in interface Sequence<Node>
Parameters:
index -

indexOf

public int indexOf(Node node)
Determines the index of the given node within this element.

Specified by:
indexOf in interface Sequence<Node>
Parameters:
node - The item to locate.
Returns:
The index of the node, or -1 if the node does not exist in this element.

getLength

public int getLength()
Returns the number of nodes contained by this element.

Specified by:
getLength in interface List<Node>
Specified by:
getLength in interface Sequence<Node>
Returns:
The number of items in the list, or -1 if the list's length is not known. In this case, the iterator must be used to retrieve the contents of the list.

getComparator

public Comparator<Node> getComparator()
Description copied from interface: Collection
Returns the collection's sort order.

Specified by:
getComparator in interface Collection<Node>
Returns:
null; elements cannot be sorted.
See Also:
Collection.setComparator(Comparator)

setComparator

public void setComparator(Comparator<Node> comparator)
Description copied from interface: Collection
Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

Calling this method more than once with the same comparator will re-sort the collection.

Specified by:
setComparator in interface Collection<Node>
Specified by:
setComparator in interface List<Node>
Parameters:
comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
Throws:
UnsupportedOperationException - Elements cannot be sorted.
See Also:
ListListener.comparatorChanged(List, Comparator)

iterator

public Iterator<Node> iterator()
Returns an iterator over this elements child nodes.

Specified by:
iterator in interface Iterable<Node>

isEmpty

public boolean isEmpty()
Determines if this element defines any attributes.

Specified by:
isEmpty in interface Collection<Node>
Returns:
true if this element does not define any attributes; false, otherwise.

getElements

public List<Element> getElements(String name)
Returns the sub-elements of of this element whose tag names match the given name.

Parameters:
name - The tag name to match.
Returns:
A list containing the matching elements. The list will be empty if no elements matched the given tag name.

getText

public String getText()
Returns the text content of this element. An element is defined to contain text when it contains a single child that is an instance of TextNode.

Returns:
The text content of the element, or null if this element does not contain text.

getListListeners

public ListenerList<ListListener<Node>> getListListeners()
Returns the element's listener list.

Specified by:
getListListeners in interface List<Node>

getElementListeners

public ListenerList<ElementListener> getElementListeners()
Returns the element listener list.


toString

public String toString()
Overrides:
toString in class Object