com.dyuproject.util.xml
Class SimpleNode

java.lang.Object
  extended by com.dyuproject.util.xml.SimpleNode
All Implemented Interfaces:
Node

public class SimpleNode
extends Object
implements Node

Simple node that persists the attributes in a Map, text content in a StringBuilder and child nodes in a List.

Author:
David Yu
Date created:
Sep 18, 2008

Constructor Summary
SimpleNode(String name)
           
SimpleNode(String name, Node parent)
           
SimpleNode(String name, Node parent, String namespace)
           
SimpleNode(String name, String namespace)
           
 
Method Summary
 void addNode(Node node)
          Adds a child node.
 void addText(char[] buf, int start, int length)
          Adds text content as char array.
 void addText(String text)
          Adds text content as String.
 void addText(StringBuffer text)
          Adds text content as StringBuffer.
 void addText(StringBuilder text)
          Adds text content as StringBuilder.
 String getAttribute(String name)
          Gets an attribute mapped with the given name.
 Node getFirstNode()
          Gets the first child node.
 Node getLastNode()
          Gets the last child node.
 String getName()
          Gets the name.
 String getNamespace()
          Gets the namespace.
 Node getNode(int index)
          Gets a child node from the given index.
 Node getNode(String name)
          Gets the first child node with the given name.
 Node getNode(String name, int startingIndex)
          Gets the first child node with the given name, starting at startingIndex.
 Node getNodeFromLast(String name)
          Gets the first child node with the given name, starting from the last.
 Node getNodeFromLast(String name, int startingIndex)
          Gets the first child node with the given name, starting from the last with the specified startingIndex.
 List<Node> getNodes()
          Gets the list of child nodes.
 List<Node> getNodes(String name)
          Gets the list of child nodes with the given name (filtered).
 Node getParent()
          Gets the parent.
 StringBuilder getText()
          Gets the text content as StringBuilder.
 boolean hasAttribute(String name)
          Checks whether the attribute name is present.
 int indexOf(String name)
          Gets the index of the child node with the given name.
 int indexOf(String name, int startingIndex)
          Gets the index of the child node with the given name, starting at startingIndex.
 boolean isRoot()
          Checks whether this node is root.
 int lastIndexOf(String name)
          Gets the index of the child node with the given name, starting from the last.
 int lastIndexOf(String name, int startingIndex)
          Gets the index of the child node with the given name, starting from last with the specified startingIndex.
 String removeAttribute(String name)
          Removes an attribute mapped with the given name.
 Node removeNode(int index)
          Removes a child node from the given index.
 boolean removeNode(Node node)
          Removes a child node.
 void setAttribute(String name, String value)
          Sets an attribute with the given name and value.
static void setDefaultBufferSize(int size)
          Sets the default buffer size for the text content.
 void setName(String name)
          Sets the name.
 void setNamespace(String namespace)
          Sets the namespace.
 void setParent(Node parent)
          Sets the parent.
 int size()
          Gets the number of child elements of this node.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleNode

public SimpleNode(String name)

SimpleNode

public SimpleNode(String name,
                  String namespace)

SimpleNode

public SimpleNode(String name,
                  Node parent)

SimpleNode

public SimpleNode(String name,
                  Node parent,
                  String namespace)
Method Detail

setDefaultBufferSize

public static void setDefaultBufferSize(int size)
Sets the default buffer size for the text content.


setParent

public void setParent(Node parent)
Description copied from interface: Node
Sets the parent.

Specified by:
setParent in interface Node

getParent

public Node getParent()
Description copied from interface: Node
Gets the parent.

Specified by:
getParent in interface Node

isRoot

public boolean isRoot()
Description copied from interface: Node
Checks whether this node is root.

Specified by:
isRoot in interface Node

size

public int size()
Description copied from interface: Node
Gets the number of child elements of this node.

Specified by:
size in interface Node

hasAttribute

public boolean hasAttribute(String name)
Description copied from interface: Node
Checks whether the attribute name is present.

Specified by:
hasAttribute in interface Node

setAttribute

public void setAttribute(String name,
                         String value)
Description copied from interface: Node
Sets an attribute with the given name and value.

Specified by:
setAttribute in interface Node

getAttribute

public String getAttribute(String name)
Description copied from interface: Node
Gets an attribute mapped with the given name.

Specified by:
getAttribute in interface Node

setName

public void setName(String name)
Description copied from interface: Node
Sets the name.

Specified by:
setName in interface Node

getName

public String getName()
Description copied from interface: Node
Gets the name.

Specified by:
getName in interface Node

setNamespace

public void setNamespace(String namespace)
Description copied from interface: Node
Sets the namespace.

Specified by:
setNamespace in interface Node

getNamespace

public String getNamespace()
Description copied from interface: Node
Gets the namespace.

Specified by:
getNamespace in interface Node

getNodes

public List<Node> getNodes()
Description copied from interface: Node
Gets the list of child nodes.

Specified by:
getNodes in interface Node

getNodes

public List<Node> getNodes(String name)
Description copied from interface: Node
Gets the list of child nodes with the given name (filtered).

Specified by:
getNodes in interface Node

addNode

public void addNode(Node node)
Description copied from interface: Node
Adds a child node.

Specified by:
addNode in interface Node

getNode

public Node getNode(int index)
Description copied from interface: Node
Gets a child node from the given index.

Specified by:
getNode in interface Node

getLastNode

public Node getLastNode()
Description copied from interface: Node
Gets the last child node.

Specified by:
getLastNode in interface Node

getFirstNode

public Node getFirstNode()
Description copied from interface: Node
Gets the first child node.

Specified by:
getFirstNode in interface Node

addText

public void addText(char[] buf,
                    int start,
                    int length)
Description copied from interface: Node
Adds text content as char array.

Specified by:
addText in interface Node

addText

public void addText(String text)
Description copied from interface: Node
Adds text content as String.

Specified by:
addText in interface Node

addText

public void addText(StringBuilder text)
Description copied from interface: Node
Adds text content as StringBuilder.

Specified by:
addText in interface Node

addText

public void addText(StringBuffer text)
Description copied from interface: Node
Adds text content as StringBuffer.

Specified by:
addText in interface Node

getText

public StringBuilder getText()
Description copied from interface: Node
Gets the text content as StringBuilder.

Specified by:
getText in interface Node

toString

public String toString()
Overrides:
toString in class Object

getNode

public Node getNode(String name)
Description copied from interface: Node
Gets the first child node with the given name.

Specified by:
getNode in interface Node

getNode

public Node getNode(String name,
                    int startingIndex)
Description copied from interface: Node
Gets the first child node with the given name, starting at startingIndex.

Specified by:
getNode in interface Node

getNodeFromLast

public Node getNodeFromLast(String name)
Description copied from interface: Node
Gets the first child node with the given name, starting from the last.

Specified by:
getNodeFromLast in interface Node

getNodeFromLast

public Node getNodeFromLast(String name,
                            int startingIndex)
Description copied from interface: Node
Gets the first child node with the given name, starting from the last with the specified startingIndex.

Specified by:
getNodeFromLast in interface Node

indexOf

public int indexOf(String name)
Description copied from interface: Node
Gets the index of the child node with the given name.

Specified by:
indexOf in interface Node

indexOf

public int indexOf(String name,
                   int startingIndex)
Description copied from interface: Node
Gets the index of the child node with the given name, starting at startingIndex.

Specified by:
indexOf in interface Node

lastIndexOf

public int lastIndexOf(String name)
Description copied from interface: Node
Gets the index of the child node with the given name, starting from the last.

Specified by:
lastIndexOf in interface Node

lastIndexOf

public int lastIndexOf(String name,
                       int startingIndex)
Description copied from interface: Node
Gets the index of the child node with the given name, starting from last with the specified startingIndex.

Specified by:
lastIndexOf in interface Node

removeAttribute

public String removeAttribute(String name)
Description copied from interface: Node
Removes an attribute mapped with the given name.

Specified by:
removeAttribute in interface Node

removeNode

public Node removeNode(int index)
Description copied from interface: Node
Removes a child node from the given index.

Specified by:
removeNode in interface Node

removeNode

public boolean removeNode(Node node)
Description copied from interface: Node
Removes a child node.

Specified by:
removeNode in interface Node


Copyright © 2008-2013. All Rights Reserved.