net.sf.exorcist.midgard
Class DOMBuilder

java.lang.Object
  extended by net.sf.exorcist.midgard.DOMBuilder

public final class DOMBuilder
extends java.lang.Object

Document builder class. This class provides an intuitive interface for incrementally building DOM documents.


Constructor Summary
DOMBuilder(java.lang.String name, java.lang.String namespace, java.lang.String prefix)
          Creates a builder for a new DOM document.
 
Method Summary
 void addContent(java.lang.String content)
          Adds the given string as text content to the current element.
 void addContentElement(java.lang.String name, java.lang.String content)
          Adds a new child element with the given name and text content.
 void endElement()
          Makes the parent element current.
 void setAttribute(java.lang.String name, boolean value)
          Sets the named boolean attribute of the current element.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets the named attribute of the current element.
 void startElement(java.lang.String name)
          Creates a new element with the given name as the child of the current element and makes the created element current.
 void write(java.io.OutputStream xml)
          Writes the document built by this builder into the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMBuilder

public DOMBuilder(java.lang.String name,
                  java.lang.String namespace,
                  java.lang.String prefix)
           throws javax.xml.parsers.ParserConfigurationException
Creates a builder for a new DOM document. A new DOM document is instantiated and initialized to contain a root element with the given name. The root element is set as the current element of this builder.

Parameters:
name - name of the root element
Throws:
javax.xml.parsers.ParserConfigurationException - if a document cannot be created
Method Detail

write

public void write(java.io.OutputStream xml)
           throws java.io.IOException
Writes the document built by this builder into the given output stream. This method is normally invoked only when the document is fully built.

Parameters:
xml - XML output stream
Throws:
java.io.IOException - if the document could not be written

startElement

public void startElement(java.lang.String name)
Creates a new element with the given name as the child of the current element and makes the created element current. The endElement method needs to be called to return back to the original element.

Parameters:
name - name of the new element

endElement

public void endElement()
Makes the parent element current. This method should be invoked after a child element created with the startElement method has been fully built.


setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Sets the named attribute of the current element.

Parameters:
name - attribute name
value - attribute value

setAttribute

public void setAttribute(java.lang.String name,
                         boolean value)
Sets the named boolean attribute of the current element.

Parameters:
name - attribute name
value - boolean attribute value

addContent

public void addContent(java.lang.String content)
Adds the given string as text content to the current element.

Parameters:
content - text content

addContentElement

public void addContentElement(java.lang.String name,
                              java.lang.String content)
Adds a new child element with the given name and text content. The created element will contain no attributes and no child elements of its own.

Parameters:
name - child element name
content - child element content


Copyright © 2005 The Exorcist Team @ SourceForge. All Rights Reserved.