|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectxtom.parser.Element
Description:Each xml tag is an element. An element can be a parent and can
have children elements, and it might also have attributes. Only one element can be a root
element.
LinkedLists are used to hold children Elements and a HashMap to hold Attributes.
Field Summary | |
private java.util.HashMap |
attributes
Attributes of this element |
private boolean |
caseSensitive
Used to specify whether the names of elements are case sensitive |
private java.util.LinkedList |
children
Children of this Element |
private java.lang.String |
name
name of this element |
private Element |
parent
Parent element - used by the parser |
private java.lang.String |
value
value of this element, null if the element is a parent |
Constructor Summary | |
private |
Element()
|
|
Element(java.lang.String name,
java.lang.String value)
Creates a new Element object. BY DEFAULT - ELEMENT NAMES ARE CASE SENSITIVE The case sensitivity can be turned of by XMLTree. |
Method Summary | |
void |
addAttribute(Attribute a)
adds an attribute to this element. |
void |
addChildElement(Element e)
adds a child element to this element. |
private Element[] |
findChildElements(java.lang.String name)
Searches the list of the children of this element to find the correct one specified by the name. |
Attribute |
getAttribute(java.lang.String name)
Gets an attribute specified by a name. |
java.util.HashMap |
getAttributes()
|
Element[] |
getChildren()
|
Element |
getElementByPath(java.lang.String path)
This method gets the element according to the path specidied. |
protected Element[] |
getElements(java.lang.String path)
This method is one the does the searching of the Element specified in the path. |
Element[] |
getElementsByPath(java.lang.String path)
This method gets all instances of specified element according to the path specidied. |
java.lang.String |
getName()
|
protected Element |
getParentElement()
Returns the parent Element. |
java.lang.String |
getValue()
|
boolean |
getValueAsBoolean()
Returns value parsed as a boolean. |
byte |
getValueAsByte()
Returns value parsed as a byte. |
char |
getValueAsCharacter()
Returns value parsed as a char. |
double |
getValueAsDouble()
Returns value parsed as a double. |
float |
getValueAsFloat()
Returns value parsed as a float. |
int |
getValueAsInt()
Returns value parsed as an int. |
long |
getValueAsLong()
Returns value parsed as a float. |
short |
getValueAsShort()
Returns value parsed as a short. |
boolean |
hasAttribute(java.lang.String name)
Checks if the attribute exists. |
boolean |
hasAttributes()
|
boolean |
hasChildren()
|
boolean |
isCaseSensitive()
|
private boolean |
isNameTheSame(java.lang.String eName,
java.lang.String tName)
This method check if the two string Names are the same, it Check to see if case sensitive is set, and if it is, it converts both names toLowercase. |
protected void |
setCaseSensitive(boolean caseSensitive)
Sets the case sensitivity to all of the children Elements of this element. |
protected void |
setParentElement(Element parent)
Sets the parent for this element, only used by the parser |
protected void |
setValue(java.lang.String value)
This is called by the Parser class, to set the value. |
java.lang.String |
toString()
Outputs the Name and value of the method, and attributes |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private boolean caseSensitive
private Element parent
private java.lang.String name
private java.lang.String value
private java.util.LinkedList children
private java.util.HashMap attributes
Constructor Detail |
private Element()
public Element(java.lang.String name, java.lang.String value)
name
- the name of this element, as it appears between tags, case sensitive.value
- the value.
java.lang.IllegalArgumentException
- if name is nullMethod Detail |
protected void setParentElement(Element parent)
parent
- protected Element getParentElement()
public void addChildElement(Element e)
e
- Element. must not be null and the name must not be null.public void addAttribute(Attribute a)
a
- Attribute. must not be null and the name must not be null.public Element[] getChildren()
public java.util.HashMap getAttributes()
public java.lang.String getName()
public java.lang.String getValue()
protected void setValue(java.lang.String value)
value
- public boolean hasChildren()
public boolean hasAttributes()
public java.lang.String toString()
Object.toString()
public Element getElementByPath(java.lang.String path) throws MultipleElementInstancesException
path
- The path to the element in search for.
MultipleElementInstancesException
- if there are more then one instance of the element that was requested by the path. This usually means that developer should use getElements method instead.
java.lang.IllegalArgumentException
- The path argument was null.
UnknownElementException
- if it can not find an element under the name specified.public Element[] getElementsByPath(java.lang.String path) throws MultipleElementInstancesException
path
- The path to the element in search for.
UnknownElementException
- if it can not find an element under the name specified.
java.lang.IllegalArgumentException
- The path argument was null.
MultipleElementInstancesException
protected Element[] getElements(java.lang.String path)
path
- The path.
private Element[] findChildElements(java.lang.String name)
name
- The name of the element we are looking for.
private boolean isNameTheSame(java.lang.String eName, java.lang.String tName)
eName
- tName
-
public boolean isCaseSensitive()
protected void setCaseSensitive(boolean caseSensitive)
caseSensitive
- The caseSensitive to set.public int getValueAsInt()
java.lang.NumberFormatException
- is it can not parse the value.public float getValueAsFloat()
java.lang.NumberFormatException
- is it can not parse the value.public double getValueAsDouble()
java.lang.NumberFormatException
- is it can not parse the value.public short getValueAsShort()
java.lang.NumberFormatException
- is it can not parse the value.public long getValueAsLong()
java.lang.NumberFormatException
- is it can not parse the value.public byte getValueAsByte()
java.lang.NumberFormatException
- is it can not parse the value.public boolean getValueAsBoolean()
java.lang.NumberFormatException
- is it can not parse the value.Boolean.valueOf(java.lang.String)
public char getValueAsCharacter()
java.lang.NumberFormatException
- is it can not parse the value.public Attribute getAttribute(java.lang.String name)
name
- The name of the attribute
UnknownAttributeException
- if name is null or there is no such attribute.public boolean hasAttribute(java.lang.String name)
name
- The name of the attribute.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |