org.xins.common.xml
Class ElementBuilder

java.lang.Object
  extended byorg.xins.common.xml.ElementBuilder

public class ElementBuilder
extends Object

Builder for Element instances.

This class is not thread-safe; it should not be used from different threads at the same time.

Since:
XINS 1.1.0
Version:
$Revision: 1.16 $ $Date: 2006/08/28 09:12:35 $
Author:
Anthony Goubard

Constructor Summary
ElementBuilder()
          Creates a new ElementBuilder.
ElementBuilder(String localName)
          Creates a new ElementBuilder.
ElementBuilder(String namespaceURI, String localName)
          Creates a new ElementBuilder.
 
Method Summary
 void addChild(Element child)
          Adds a new child element.
 void addXMLChild(String xmlChild)
          Adds a new child element.
 Element createElement()
          Creates the Element.
 void setAttribute(String localName, String value)
          Sets the specified attribute.
 void setAttribute(String namespaceURI, String localName, String value)
          Sets the specified attribute.
 void setText(String text)
          Sets the character content.
 void startElement(String localName)
          Starts to create a new Element with the given local name.
 void startElement(String namespaceURI, String localName)
          Starts to create a new Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementBuilder

public ElementBuilder()
Creates a new ElementBuilder.


ElementBuilder

public ElementBuilder(String localName)
               throws IllegalArgumentException
Creates a new ElementBuilder.

Parameters:
localName - the local name of the element, cannot be null.
Throws:
IllegalArgumentException - if localName == null.

ElementBuilder

public ElementBuilder(String namespaceURI,
                      String localName)
               throws IllegalArgumentException
Creates a new ElementBuilder.

Parameters:
namespaceURI - the namespace URI for the element, can be null; an empty string is equivalent to null.
localName - the local name of the element, cannot be null.
Throws:
IllegalArgumentException - if localName == null.
Method Detail

setAttribute

public void setAttribute(String localName,
                         String value)
                  throws IllegalArgumentException
Sets the specified attribute. If the value for the specified attribute is already set, then the previous value is replaced.

Parameters:
localName - the local name for the attribute, cannot be null.
value - the value for the attribute, can be null.
Throws:
IllegalArgumentException - if localName == null.

setAttribute

public void setAttribute(String namespaceURI,
                         String localName,
                         String value)
                  throws IllegalArgumentException
Sets the specified attribute. If the value for the specified attribute is already set, then the previous value is replaced.

Parameters:
namespaceURI - the namespace URI for the attribute, can be null; an empty string is equivalent to null.
localName - the local name for the attribute, cannot be null.
value - the value for the attribute, can be null.
Throws:
IllegalArgumentException - if localName == null.

addChild

public void addChild(Element child)
              throws IllegalArgumentException
Adds a new child element.

Parameters:
child - the new child to add to this element, cannot be null.
Throws:
IllegalArgumentException - if child == null || child == this.

addXMLChild

public void addXMLChild(String xmlChild)
                 throws ParseException,
                        IllegalArgumentException
Adds a new child element.

Parameters:
xmlChild - the character string that contains the XML that defines the new child to add to this element, cannot be null.
Throws:
ParseException - if the String passed as argument cannot be parsed.
IllegalArgumentException - if child == null.
Since:
XINS 1.3.0

setText

public void setText(String text)
Sets the character content. The existing character content, if any, is replaced

Parameters:
text - the character content for this element, or null.

startElement

public void startElement(String localName)
                  throws IllegalArgumentException
Starts to create a new Element with the given local name.

Parameters:
localName - the local name of the element, cannot be null.
Throws:
IllegalArgumentException - if localName == null.

startElement

public void startElement(String namespaceURI,
                         String localName)
                  throws IllegalArgumentException
Starts to create a new Element.

Parameters:
namespaceURI - the namespace URI for the element, can be null; an empty string is equivalent to null.
localName - the local name of the element, cannot be null.
Throws:
IllegalArgumentException - if localName == null.

createElement

public Element createElement()
Creates the Element. If you want to reuse this ElementBuilder you will need to call the startElement(String) or startElement(String,String) method.

Returns:
the constructed Element, never null.


See http://www.xins.org/.