com.izforge.izpack.adaptator.impl
Class XMLElementImpl

java.lang.Object
  extended by com.izforge.izpack.adaptator.impl.XMLElementImpl
All Implemented Interfaces:
IXMLElement, java.io.Serializable

public class XMLElementImpl
extends java.lang.Object
implements IXMLElement

Implementation of the adaptator between nanoXml and javax

Author:
Anthonin Bonnefoy, David Duponchel
See Also:
Serialized Form

Field Summary
private  java.util.Vector<IXMLElement> childrenVector
          Vector of the children elements.
private  org.w3c.dom.Element element
          The dom element embedded by the XMLElement
private  boolean hasChanged
          A flag to notice any changement made to the element.
 
Fields inherited from interface com.izforge.izpack.adaptator.IXMLElement
NO_LINE
 
Constructor Summary
XMLElementImpl(org.w3c.dom.Node node)
          Constructor saving the passed node
XMLElementImpl(java.lang.String name)
          Create a new root element in a new document.
XMLElementImpl(java.lang.String name, org.w3c.dom.Document inDocument)
          Constructor which create a root element in the given document
XMLElementImpl(java.lang.String name, IXMLElement elementReference)
          Create a element in the same document of the given element
 
Method Summary
 void addChild(IXMLElement child)
          Adds a child element.
 java.util.Enumeration enumerateAttributeNames()
          Returns an enumeration of all attribute names.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of an attribute.
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Returns the value of an attribute.
 java.util.Properties getAttributes()
          Returns all attributes as a Properties object.
 IXMLElement getChildAtIndex(int index)
          Returns the child at a specific index.
 java.util.Vector<IXMLElement> getChildren()
          Returns a vector containing all the child elements.
 int getChildrenCount()
          Returns the number of children.
 java.util.Vector<IXMLElement> getChildrenNamed(java.lang.String name)
          Returns a vector of all child elements named name.
 java.lang.String getContent()
          Return the #PCDATA content of the element.
 org.w3c.dom.Node getElement()
          Get the embeded node of the XmlElement
 IXMLElement getFirstChildNamed(java.lang.String name)
          Searches a child element.
 int getLineNr()
          Returns the line number in the data where the element started.
 java.lang.String getName()
          Returns the name of the element.
 boolean hasAttribute(java.lang.String name)
          Returns whether an attribute exists.
 boolean hasChildren()
          Returns whether the element has children.
private  void initChildrenVector()
           
 void removeAttribute(java.lang.String name)
          Removes an attribute.
 void removeChild(IXMLElement child)
          Removes a child element.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets an attribute.
 void setContent(java.lang.String content)
          Sets the #PCDATA content.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

element

private org.w3c.dom.Element element
The dom element embedded by the XMLElement


hasChanged

private boolean hasChanged
A flag to notice any changement made to the element. It is used to generate the childrenVector.


childrenVector

private java.util.Vector<IXMLElement> childrenVector
Vector of the children elements. It is generated as it is called.

Constructor Detail

XMLElementImpl

public XMLElementImpl(java.lang.String name)
Create a new root element in a new document.

Parameters:
name - Name of the root element

XMLElementImpl

public XMLElementImpl(java.lang.String name,
                      org.w3c.dom.Document inDocument)
Constructor which create a root element in the given document

Parameters:
name - Name of the root element
inDocument - The document in which to create the xml

XMLElementImpl

public XMLElementImpl(java.lang.String name,
                      IXMLElement elementReference)
Create a element in the same document of the given element

Parameters:
name - Name of the element
elementReference - Reference of an existing xml. It is used to generate an xmlElement on the same document.

XMLElementImpl

public XMLElementImpl(org.w3c.dom.Node node)
Constructor saving the passed node

Parameters:
node - Node to save inside the XMLElement
Method Detail

getName

public java.lang.String getName()
Description copied from interface: IXMLElement
Returns the name of the element.

Specified by:
getName in interface IXMLElement
Returns:
the name, or null if the element only contains #PCDATA.

addChild

public void addChild(IXMLElement child)
Description copied from interface: IXMLElement
Adds a child element.

Specified by:
addChild in interface IXMLElement
Parameters:
child - the non-null child to add.

removeChild

public void removeChild(IXMLElement child)
Description copied from interface: IXMLElement
Removes a child element.

Specified by:
removeChild in interface IXMLElement
Parameters:
child - the non-null child to remove.

hasChildren

public boolean hasChildren()
Description copied from interface: IXMLElement
Returns whether the element has children.

Specified by:
hasChildren in interface IXMLElement
Returns:
true if the element has children.

initChildrenVector

private void initChildrenVector()

getChildrenCount

public int getChildrenCount()
Description copied from interface: IXMLElement
Returns the number of children.

Specified by:
getChildrenCount in interface IXMLElement
Returns:
the count.

getChildren

public java.util.Vector<IXMLElement> getChildren()
Description copied from interface: IXMLElement
Returns a vector containing all the child elements.

Specified by:
getChildren in interface IXMLElement
Returns:
the vector.

getChildAtIndex

public IXMLElement getChildAtIndex(int index)
Description copied from interface: IXMLElement
Returns the child at a specific index.

Specified by:
getChildAtIndex in interface IXMLElement
Parameters:
index - Index of the child
Returns:
the non-null child

getFirstChildNamed

public IXMLElement getFirstChildNamed(java.lang.String name)
Description copied from interface: IXMLElement
Searches a child element.

Specified by:
getFirstChildNamed in interface IXMLElement
Parameters:
name - the name of the child to search for.
Returns:
the child element, or null if no such child was found.

getChildrenNamed

public java.util.Vector<IXMLElement> getChildrenNamed(java.lang.String name)
Description copied from interface: IXMLElement
Returns a vector of all child elements named name.

Specified by:
getChildrenNamed in interface IXMLElement
Parameters:
name - the name of the children to search for.
Returns:
the non-null vector of child elements.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Description copied from interface: IXMLElement
Returns the value of an attribute.

Specified by:
getAttribute in interface IXMLElement
Parameters:
name - the non-null name of the attribute.
Returns:
the value, or null if the attribute does not exist.

getAttribute

public java.lang.String getAttribute(java.lang.String name,
                                     java.lang.String defaultValue)
Description copied from interface: IXMLElement
Returns the value of an attribute.

Specified by:
getAttribute in interface IXMLElement
Parameters:
name - the non-null name of the attribute.
defaultValue - the default value of the attribute.
Returns:
the value, or defaultValue if the attribute does not exist.

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Description copied from interface: IXMLElement
Sets an attribute.

Specified by:
setAttribute in interface IXMLElement
Parameters:
name - the non-null name of the attribute.
value - the non-null value of the attribute.

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: IXMLElement
Removes an attribute.

Specified by:
removeAttribute in interface IXMLElement
Parameters:
name - the non-null name of the attribute.

enumerateAttributeNames

public java.util.Enumeration enumerateAttributeNames()
Description copied from interface: IXMLElement
Returns an enumeration of all attribute names.

Specified by:
enumerateAttributeNames in interface IXMLElement
Returns:
the non-null enumeration.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Description copied from interface: IXMLElement
Returns whether an attribute exists.

Specified by:
hasAttribute in interface IXMLElement
Parameters:
name - The name of the attribute
Returns:
true if the attribute exists.

getAttributes

public java.util.Properties getAttributes()
Description copied from interface: IXMLElement
Returns all attributes as a Properties object.

Specified by:
getAttributes in interface IXMLElement
Returns:
the non-null set.

getLineNr

public int getLineNr()
Description copied from interface: IXMLElement
Returns the line number in the data where the element started.

Specified by:
getLineNr in interface IXMLElement
Returns:
the line number, or NO_LINE if unknown.
See Also:
IXMLElement.NO_LINE

getContent

public java.lang.String getContent()
Description copied from interface: IXMLElement
Return the #PCDATA content of the element. If the element has a combination of #PCDATA content and child elements, the #PCDATA sections can be retrieved as unnamed child objects. In this case, this method returns null.

Specified by:
getContent in interface IXMLElement
Returns:
the content.

setContent

public void setContent(java.lang.String content)
Description copied from interface: IXMLElement
Sets the #PCDATA content. It is an error to call this method with a non-null value if there are child objects.

Specified by:
setContent in interface IXMLElement
Parameters:
content - the (possibly null) content.

getElement

public org.w3c.dom.Node getElement()
Description copied from interface: IXMLElement
Get the embeded node of the XmlElement

Specified by:
getElement in interface IXMLElement
Returns:
Embedded node

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object