org.yawlfoundation.yawl.util
Class XNode

java.lang.Object
  extended by org.yawlfoundation.yawl.util.XNode
All Implemented Interfaces:
Comparable<XNode>

public class XNode
extends Object
implements Comparable<XNode>

A utility for building xml strings. Handles elements, attributes, comments, text and CDATA (and that's all - no edge cases). NOTE: To keep things simple, while this class allows a node to have both child nodes and text, where both have values set the child nodes have precedence (ie. the text is ignored). Author: Michael Adams Creation Date: 19/03/2010


Nested Class Summary
static class XNode.ContentType
           
 
Constructor Summary
XNode(String name)
           
XNode(String name, String text)
           
 
Method Summary
 void addAttribute(String key, boolean value)
           
 void addAttribute(String key, byte value)
           
 void addAttribute(String key, double value)
           
 void addAttribute(String key, float value)
           
 void addAttribute(String key, int value)
           
 void addAttribute(String key, long value)
           
 void addAttribute(String key, Object o)
           
 void addAttribute(String key, short value)
           
 void addAttribute(String key, String value)
           
 void addAttribute(String key, String value, boolean escape)
           
 void addAttributes(Map<String,String> map)
           
 XNode addCDATA(String cdata)
           
 XNode addChild(String name)
           
 XNode addChild(String name, boolean b)
           
 XNode addChild(String name, byte b)
           
 XNode addChild(String name, double d)
           
 XNode addChild(String name, float f)
           
 XNode addChild(String name, int i)
           
 XNode addChild(String name, long l)
           
 XNode addChild(String name, Object o)
           
 XNode addChild(String name, short s)
           
 XNode addChild(String name, String text)
           
 XNode addChild(String name, String text, boolean escape)
           
 XNode addChild(XNode child)
           
 void addChildren(Collection<XNode> children)
           
 void addChildren(Map<String,String> children)
           
 void addClosingComment(String comment)
           
<E extends XNodeIO>
void
addCollection(Collection<E> list)
          Adds a child node to this node for each object in a list
 XNode addComment(String comment)
           
 void addContent(String content)
           
 void addOpeningComment(String comment)
           
 int compareTo(XNode other)
           
 int getAttributeCount()
           
 Map<String,String> getAttributes()
           
 String getAttributeValue(String key)
           
 XNode getChild()
           
 XNode getChild(String name)
           
 int getChildCount()
           
 List<XNode> getChildren()
           
 List<XNode> getChildren(String name)
           
 List<XNode> getChildren(XNode.ContentType cType)
           
 String getChildText(String name)
           
 String getChildText(String name, boolean escape)
           
 int getDepth()
           
 String getName()
           
 XNode getOrAddChild(String name)
           
 XNode getParent()
           
 String getText()
           
 String getText(boolean escape)
           
 int getTextLength()
           
 boolean hasAttribute(String key)
           
 boolean hasChild(String name)
           
 boolean hasChildren()
           
 boolean hasChildren(String name)
           
 XNode insertChild(int index, XNode child)
           
 XNode insertComment(int index, String comment)
           
 boolean isCDATA()
           
 boolean isComment()
           
 int length()
           
<E extends XNodeIO>
void
populateCollection(Collection<E> list, E instance)
          Creates and adds an object of type E to a list for each child node.
 int posChildWithAttribute(String key, String value)
           
 int posChildWithName(String name)
           
 boolean removeChild(XNode child)
           
 void setAttributes(Map<String,String> attributes)
           
 void setDepth(int depth)
           
 void setName(String name)
           
 void setParent(XNode parent)
           
 void setText(boolean value)
           
 void setText(byte value)
           
 void setText(double value)
           
 void setText(float value)
           
 void setText(int value)
           
 void setText(long value)
           
 void setText(short value)
           
 void setText(String text)
           
 void sort()
           
 void sort(Comparator<XNode> comparator)
           
 org.jdom.Document toDocument()
           
 org.jdom.Element toElement()
           
 String toPrettyString()
           
 String toPrettyString(boolean header)
           
 String toPrettyString(boolean header, int tabSize)
           
 String toPrettyString(int tabSize)
           
 String toString()
           
 String toString(boolean header)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XNode

public XNode(String name)

XNode

public XNode(String name,
             String text)
Method Detail

compareTo

public int compareTo(XNode other)
Specified by:
compareTo in interface Comparable<XNode>

addAttribute

public void addAttribute(String key,
                         String value)

addAttribute

public void addAttribute(String key,
                         String value,
                         boolean escape)

addAttribute

public void addAttribute(String key,
                         boolean value)

addAttribute

public void addAttribute(String key,
                         byte value)

addAttribute

public void addAttribute(String key,
                         short value)

addAttribute

public void addAttribute(String key,
                         int value)

addAttribute

public void addAttribute(String key,
                         long value)

addAttribute

public void addAttribute(String key,
                         double value)

addAttribute

public void addAttribute(String key,
                         float value)

addAttribute

public void addAttribute(String key,
                         Object o)

addAttributes

public void addAttributes(Map<String,String> map)

insertChild

public XNode insertChild(int index,
                         XNode child)

addChild

public XNode addChild(XNode child)

addChild

public XNode addChild(String name)

addChild

public XNode addChild(String name,
                      String text)

addChild

public XNode addChild(String name,
                      boolean b)

addChild

public XNode addChild(String name,
                      long l)

addChild

public XNode addChild(String name,
                      int i)

addChild

public XNode addChild(String name,
                      byte b)

addChild

public XNode addChild(String name,
                      short s)

addChild

public XNode addChild(String name,
                      double d)

addChild

public XNode addChild(String name,
                      float f)

addChild

public XNode addChild(String name,
                      Object o)

addChild

public XNode addChild(String name,
                      String text,
                      boolean escape)

addChildren

public void addChildren(Collection<XNode> children)

addChildren

public void addChildren(Map<String,String> children)

removeChild

public boolean removeChild(XNode child)

addContent

public void addContent(String content)

addCollection

public <E extends XNodeIO> void addCollection(Collection<E> list)
Adds a child node to this node for each object in a list

Type Parameters:
E - a type extending the XNodeIO interface
Parameters:
list - the list of objects to create child nodes from

populateCollection

public <E extends XNodeIO> void populateCollection(Collection<E> list,
                                                   E instance)
Creates and adds an object of type E to a list for each child node. It is assumed that each child of this node represents an object of type E.

Type Parameters:
E - a type extending the XNodeIO interface
Parameters:
list - the list of objects to populate
instance - an instance of an E type object

addComment

public XNode addComment(String comment)

insertComment

public XNode insertComment(int index,
                           String comment)

isComment

public boolean isComment()

addOpeningComment

public void addOpeningComment(String comment)

addClosingComment

public void addClosingComment(String comment)

addCDATA

public XNode addCDATA(String cdata)

isCDATA

public boolean isCDATA()

setText

public void setText(String text)

setText

public void setText(boolean value)

setText

public void setText(byte value)

setText

public void setText(short value)

setText

public void setText(int value)

setText

public void setText(long value)

setText

public void setText(double value)

setText

public void setText(float value)

getChild

public XNode getChild(String name)

getOrAddChild

public XNode getOrAddChild(String name)

getChild

public XNode getChild()

getChildren

public List<XNode> getChildren()

getChildren

public List<XNode> getChildren(XNode.ContentType cType)

getChildren

public List<XNode> getChildren(String name)

getChildText

public String getChildText(String name)

getChildText

public String getChildText(String name,
                           boolean escape)

posChildWithName

public int posChildWithName(String name)

posChildWithAttribute

public int posChildWithAttribute(String key,
                                 String value)

getText

public String getText()

getText

public String getText(boolean escape)

getAttributeValue

public String getAttributeValue(String key)

getAttributes

public Map<String,String> getAttributes()

hasAttribute

public boolean hasAttribute(String key)

setAttributes

public void setAttributes(Map<String,String> attributes)

getName

public String getName()

setName

public void setName(String name)

setParent

public void setParent(XNode parent)

getParent

public XNode getParent()

getDepth

public int getDepth()

setDepth

public void setDepth(int depth)

hasChildren

public boolean hasChildren()

hasChildren

public boolean hasChildren(String name)

hasChild

public boolean hasChild(String name)

getAttributeCount

public int getAttributeCount()

getChildCount

public int getChildCount()

getTextLength

public int getTextLength()

length

public int length()

sort

public void sort()

sort

public void sort(Comparator<XNode> comparator)

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(boolean header)

toPrettyString

public String toPrettyString()

toPrettyString

public String toPrettyString(boolean header)

toPrettyString

public String toPrettyString(int tabSize)

toPrettyString

public String toPrettyString(boolean header,
                             int tabSize)

toElement

public org.jdom.Element toElement()

toDocument

public org.jdom.Document toDocument()


Copyright © 2004-2012 The YAWL Foundation.