bibliothek.util.xml
Class XElement

java.lang.Object
  extended by bibliothek.util.xml.XContainer
      extended by bibliothek.util.xml.XElement
All Implemented Interfaces:
Iterable<XElement>

public class XElement
extends XContainer
implements Iterable<XElement>

A XElement is an entry in a xml-file. It has a name, can have children and attributes, and might have a value.

Author:
Benjamin Sigg

Constructor Summary
XElement(String name)
          Creates a new entry with given name.
 
Method Summary
 XElement addAttribute(XAttribute attribute)
          Adds a new attribute to this entry.
 XElement addBoolean(String name, boolean value)
          Adds a new attribute to this entry.
 XElement addByte(String name, byte value)
          Adds a new attribute to this entry.
 XElement addByteArray(String name, byte[] value)
          Adds a new attribute to this entry.
 XElement addChar(String name, char value)
          Adds a new attribute to this entry.
 XElement addDouble(String name, double value)
          Adds a new attribute to this entry.
 XElement addElement(String name)
          Creates and adds a new element.
 void addElement(XElement element)
          Adds a new element to this element.
 XElement addFloat(String name, float value)
          Adds a new attribute to this entry.
 XElement addInt(String name, int value)
          Adds a new attribute to this entry.
 XElement addLong(String name, long value)
          Adds a new attribute to this entry.
 XElement addShort(String name, short value)
          Adds a new attribute to this entry.
 XElement addString(String name, String value)
          Adds a new attribute to this entry.
 boolean attributeExists(String name)
          Tells whether the attribute name exists.
 XAttribute[] attributes()
          Gets all attributes of this entry.
 XElement[] children()
          Gets all children of this entry.
 XElement copy()
          Creates an independent copy of this container.
 void copy(XElement original)
          Makes a copy of all the elements of original and stores them in this container.
 XAttribute getAttribute(String name)
          Searches an attribute with the given name.
 boolean getBoolean(String name)
          Gets the value of an attribute.
 byte getByte(String name)
          Gets the value of an attribute.
 byte[] getByteArray(String name)
          Gets the value of an attribute.
 char getChar(String name)
          Gets the value of an attribute.
 double getDouble(String name)
          Gets the value of an attribute.
 XElement getElement(int index)
          Gets the index'th child of this element.
 XElement getElement(String name)
          Gets the first element with the given name.
 int getElementCount()
          Gets the number of children this element has.
 XElement[] getElements(String... names)
          Searches all children which have one of the name names.
 XElement[] getElements(String name)
          Gets all children with a given name.
 float getFloat(String name)
          Gets the value of an attribute.
 int getInt(String name)
          Gets the value of an attribute.
 long getLong(String name)
          Gets the value of an attribute.
 String getName()
          Gets the name of this attribute.
 short getShort(String name)
          Gets the value of an attribute.
 String getString()
          Gets the value of this container as string.
 String getString(String name)
          Gets the value of an attribute.
 Iterator<XElement> iterator()
           
 XAttribute removeAttribute(String name)
          Removes the attribute with name name from this XElement.
 boolean removeAttribute(XAttribute attribute)
          Removes the attribute attribute from this XElement.
 boolean removeElement(XElement element)
          Removes the child element from this XElement.
 void setName(String name)
          Sets the name of this attribute.
 void setString(String s)
          Sets the value of this container.
 String toString()
           
 
Methods inherited from class bibliothek.util.xml.XContainer
copy, getBoolean, getByte, getByteArray, getChar, getDouble, getFloat, getInt, getLong, getShort, getValue, setBoolean, setByte, setByteArray, setChar, setDouble, setFloat, setInt, setLong, setShort, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XElement

public XElement(String name)
Creates a new entry with given name.

Parameters:
name - the name of this entry
Method Detail

copy

public XElement copy()
Description copied from class: XContainer
Creates an independent copy of this container.

Overrides:
copy in class XContainer
Returns:
the new copy

copy

public void copy(XElement original)
Makes a copy of all the elements of original and stores them in this container.

Parameters:
original - the element to copy

setName

public void setName(String name)
Sets the name of this attribute.

Parameters:
name - the new name

getName

public String getName()
Gets the name of this attribute.

Returns:
the name

iterator

public Iterator<XElement> iterator()
Specified by:
iterator in interface Iterable<XElement>

attributes

public XAttribute[] attributes()
Gets all attributes of this entry.

Returns:
the attributes

children

public XElement[] children()
Gets all children of this entry.

Returns:
the children

addAttribute

public XElement addAttribute(XAttribute attribute)
Adds a new attribute to this entry.

Parameters:
attribute - the new attribute
Returns:
this

removeAttribute

public XAttribute removeAttribute(String name)
Removes the attribute with name name from this XElement.

Parameters:
name - the name of the attribute to remove
Returns:
the attribute that was removed, or null if not found

removeAttribute

public boolean removeAttribute(XAttribute attribute)
Removes the attribute attribute from this XElement.

Parameters:
attribute - the attribute to remove
Returns:
true if attribute was removed

addByte

public XElement addByte(String name,
                        byte value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addShort

public XElement addShort(String name,
                         short value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addInt

public XElement addInt(String name,
                       int value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addLong

public XElement addLong(String name,
                        long value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addFloat

public XElement addFloat(String name,
                         float value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addDouble

public XElement addDouble(String name,
                          double value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addChar

public XElement addChar(String name,
                        char value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addString

public XElement addString(String name,
                          String value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addBoolean

public XElement addBoolean(String name,
                           boolean value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

addByteArray

public XElement addByteArray(String name,
                             byte[] value)
Adds a new attribute to this entry.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this

attributeExists

public boolean attributeExists(String name)
Tells whether the attribute name exists.

Parameters:
name - the name to search
Returns:
true if such an attribute exists

getAttribute

public XAttribute getAttribute(String name)
Searches an attribute with the given name.

Parameters:
name - the name of the attribute
Returns:
the attribute

getByte

public byte getByte(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getShort

public short getShort(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getInt

public int getInt(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getLong

public long getLong(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getFloat

public float getFloat(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getDouble

public double getDouble(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getChar

public char getChar(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getString

public String getString(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getBoolean

public boolean getBoolean(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

getByteArray

public byte[] getByteArray(String name)
Gets the value of an attribute.

Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
XException - if the attribute does not exist or if the value is in the wrong format
See Also:
getAttribute(String)

removeElement

public boolean removeElement(XElement element)
Removes the child element from this XElement.

Parameters:
element - the element to remove
Returns:
true if element was removed, false otherwise

addElement

public void addElement(XElement element)
Adds a new element to this element.

Parameters:
element - the new child

addElement

public XElement addElement(String name)
Creates and adds a new element.

Parameters:
name - the name of the new element
Returns:
the new element

getElement

public XElement getElement(String name)
Gets the first element with the given name.

Parameters:
name - the name of the element
Returns:
the element or null

getElementCount

public int getElementCount()
Gets the number of children this element has.

Returns:
the number of children

getElement

public XElement getElement(int index)
Gets the index'th child of this element.

Parameters:
index - the index of the child
Returns:
the child

getElements

public XElement[] getElements(String name)
Gets all children with a given name.

Parameters:
name - the name each child must have
Returns:
the array of children, might be empty

getElements

public XElement[] getElements(String... names)
Searches all children which have one of the name names.

Parameters:
names - the names to search
Returns:
the array of children, ordered by their occurence within this element, might be empty

setString

public void setString(String s)
Description copied from class: XContainer
Sets the value of this container.

Overrides:
setString in class XContainer
Parameters:
s - the value

getString

public String getString()
Description copied from class: XContainer
Gets the value of this container as string.

Overrides:
getString in class XContainer
Returns:
the value

toString

public String toString()
Overrides:
toString in class Object