org.jhotdraw.xml
Class JavaxDOMInput

java.lang.Object
  extended by org.jhotdraw.xml.JavaxDOMInput
All Implemented Interfaces:
DOMInput

public class JavaxDOMInput
extends java.lang.Object
implements DOMInput

DOMInput.

Design pattern:
Name: Adapter.
Role: Adapter.
Partners: Document as Adaptee.

Version:
$Id: JavaxDOMInput.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer

Field Summary
private  org.w3c.dom.Node current
          The current node used for input.
private  org.w3c.dom.Document document
          The document used for input.
protected static javax.xml.parsers.DocumentBuilder documentBuilder
           
private  DOMFactory factory
          The factory used to create objects from XML tag names.
private  java.util.HashMap<java.lang.String,java.lang.Object> idobjects
          This map is used to unmarshall references to objects to the XML DOM.
 
Constructor Summary
JavaxDOMInput(DOMFactory factory, java.io.InputStream in)
           
JavaxDOMInput(DOMFactory factory, java.io.Reader in)
           
 
Method Summary
 void closeElement()
          Closes the current element of the DOM Document.
 boolean getAttribute(java.lang.String name, boolean defaultValue)
          Gets an attribute of the current element of the DOM Document.
 double getAttribute(java.lang.String name, double defaultValue)
          Gets an attribute of the current element of the DOM Document.
 int getAttribute(java.lang.String name, int defaultValue)
          Gets an attribute of the current element of the DOM Document.
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Gets an attribute of the current element of the DOM Document.
protected static javax.xml.parsers.DocumentBuilder getBuilder()
          Lazily create the document builder and keep a reference to it for performance improvement.
 int getElementCount()
          Returns the number of child elements of the current element.
 int getElementCount(java.lang.String tagName)
          Returns the number of child elements with the specified tag name of the current element.
 java.util.List<java.lang.String> getInheritedAttribute(java.lang.String name)
          Gets an attribute of the current element of the DOM Document and of all parent DOM elements.
 java.lang.String getTagName()
          Returns the tag name of the current element.
 java.lang.String getText()
          Gets the text of the current element of the DOM Document.
private static void getText(org.w3c.dom.Node n, java.lang.StringBuilder buf)
           
 java.lang.String getText(java.lang.String defaultValue)
          Gets the text of the current element of the DOM Document.
 void openElement(int index)
          Opens the element with the specified index and makes it the current node.
 void openElement(java.lang.String tagName)
          Opens the last element with the specified name and makes it the current node.
 void openElement(java.lang.String tagName, int index)
          Opens the element with the specified name and index and makes it the current node.
 java.lang.Object readObject()
          Reads an object from the current element.
 java.lang.Object readObject(int index)
          Reads an object from the current element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idobjects

private java.util.HashMap<java.lang.String,java.lang.Object> idobjects
This map is used to unmarshall references to objects to the XML DOM. A key in this map is a String representing a marshalled reference. A value in this map is an unmarshalled Object.


document

private org.w3c.dom.Document document
The document used for input.


current

private org.w3c.dom.Node current
The current node used for input.


factory

private DOMFactory factory
The factory used to create objects from XML tag names.


documentBuilder

protected static javax.xml.parsers.DocumentBuilder documentBuilder
Constructor Detail

JavaxDOMInput

public JavaxDOMInput(DOMFactory factory,
                     java.io.InputStream in)
              throws java.io.IOException
Throws:
java.io.IOException

JavaxDOMInput

public JavaxDOMInput(DOMFactory factory,
                     java.io.Reader in)
              throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getBuilder

protected static javax.xml.parsers.DocumentBuilder getBuilder()
                                                       throws java.io.IOException
Lazily create the document builder and keep a reference to it for performance improvement.

Throws:
java.io.IOException

getTagName

public java.lang.String getTagName()
Returns the tag name of the current element.

Specified by:
getTagName in interface DOMInput

getAttribute

public java.lang.String getAttribute(java.lang.String name,
                                     java.lang.String defaultValue)
Gets an attribute of the current element of the DOM Document.

Specified by:
getAttribute in interface DOMInput

getText

public java.lang.String getText()
Gets the text of the current element of the DOM Document.

Specified by:
getText in interface DOMInput

getText

public java.lang.String getText(java.lang.String defaultValue)
Gets the text of the current element of the DOM Document.

Specified by:
getText in interface DOMInput

getText

private static void getText(org.w3c.dom.Node n,
                            java.lang.StringBuilder buf)

getInheritedAttribute

public java.util.List<java.lang.String> getInheritedAttribute(java.lang.String name)
Gets an attribute of the current element of the DOM Document and of all parent DOM elements.

Specified by:
getInheritedAttribute in interface DOMInput

getAttribute

public int getAttribute(java.lang.String name,
                        int defaultValue)
Gets an attribute of the current element of the DOM Document.

Specified by:
getAttribute in interface DOMInput

getAttribute

public double getAttribute(java.lang.String name,
                           double defaultValue)
Gets an attribute of the current element of the DOM Document.

Specified by:
getAttribute in interface DOMInput

getAttribute

public boolean getAttribute(java.lang.String name,
                            boolean defaultValue)
Gets an attribute of the current element of the DOM Document.

Specified by:
getAttribute in interface DOMInput

getElementCount

public int getElementCount()
Returns the number of child elements of the current element.

Specified by:
getElementCount in interface DOMInput

getElementCount

public int getElementCount(java.lang.String tagName)
Returns the number of child elements with the specified tag name of the current element.

Specified by:
getElementCount in interface DOMInput

openElement

public void openElement(int index)
Opens the element with the specified index and makes it the current node.

Specified by:
openElement in interface DOMInput

openElement

public void openElement(java.lang.String tagName)
Opens the last element with the specified name and makes it the current node.

Specified by:
openElement in interface DOMInput

openElement

public void openElement(java.lang.String tagName,
                        int index)
Opens the element with the specified name and index and makes it the current node.

Specified by:
openElement in interface DOMInput

closeElement

public void closeElement()
Closes the current element of the DOM Document. The parent of the current element becomes the current element.

Specified by:
closeElement in interface DOMInput
Throws:
java.lang.IllegalArgumentException - if the provided tagName does not match the tag name of the element.

readObject

public java.lang.Object readObject()
                            throws java.io.IOException
Reads an object from the current element.

Specified by:
readObject in interface DOMInput
Throws:
java.io.IOException

readObject

public java.lang.Object readObject(int index)
                            throws java.io.IOException
Reads an object from the current element.

Specified by:
readObject in interface DOMInput
Throws:
java.io.IOException