com.wutka.jox
Class JOXBeanDOM

java.lang.Object
  |
  +--com.wutka.jox.JOXBeanOutput
        |
        +--com.wutka.jox.JOXBeanDOM

public class JOXBeanDOM
extends com.wutka.jox.JOXBeanOutput

Converts a Java Bean into an XML Document. If you don't supply a Document object, this class uses the DocumentBuilder to create a new document. For some tools like the Xalan XSL processor, you must use a specific Document implementation (the Xerces implementation). If you need to use Xalan, create your own Document using the Xerces API and pass it to one of the JOXBeanDOM constructors.


Field Summary
protected static java.util.Hashtable beanCache
           
protected  org.w3c.dom.Document document
           
 
Fields inherited from class com.wutka.jox.JOXBeanOutput
attrTranslation, beanCache, childTranslation, dateFormat, dtd, getParams, nameTranslation, outputStream, WRITE_AS_ATTRIBUTE, WRITE_AS_ELEMENT, WRITE_AS_INDEXED_ELEMENT, writeAttributes
 
Constructor Summary
JOXBeanDOM()
          Creates a JOXBeanDOM that stores simple properties as attributes
JOXBeanDOM(boolean writeAttributesFlag)
          Creates a JOXBeanDOM that doesn't use a DTD
JOXBeanDOM(org.w3c.dom.Document aDocument)
          Creates a JOXBeanDOM that stores simple properties as attributes
JOXBeanDOM(org.w3c.dom.Document aDocument, boolean writeAttributesFlag)
          Creates a JOXBeanDOM that doesn't use a DTD
JOXBeanDOM(org.w3c.dom.Document aDocument, com.wutka.dtd.DTD aDTD)
          Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
JOXBeanDOM(org.w3c.dom.Document aDocument, java.lang.String dtdURL)
          Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
JOXBeanDOM(com.wutka.dtd.DTD aDTD)
          Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
JOXBeanDOM(java.lang.String dtdURL)
          Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
 
Method Summary
 org.w3c.dom.Document beanToDocument(java.lang.String rootName, java.lang.Object ob)
          Stores a Java bean in an XML document (this is the main method for JOXBeanDOM).
protected  void createDocument()
          Creates a new Document using a DocumentBuilder
 void storeBasicType(java.lang.String xmlTagName, java.lang.String propName, java.lang.Object propValue, int writeType, org.w3c.dom.Element parentElement)
          Writes out a basic type including the opening and closing tags.
 void storeDate(java.lang.String xmlTagName, java.lang.String propName, java.lang.Object propValue, int writeType, org.w3c.dom.Element parentElement)
          Writes out a date including the opening and closing tags
 void storeIndexedProperty(java.lang.String xmlTagName, java.lang.Object ob, java.beans.IndexedPropertyDescriptor prop, org.w3c.dom.Element parentElement)
          Stores an indexed property (an array of properties)
 org.w3c.dom.Element storeObject(java.lang.String rootName, java.lang.Object ob)
          Stores a bean in an XML element and returns the element
 void storeObjectFields(java.lang.String xmlTagName, java.lang.Object ob, int writeType, org.w3c.dom.Element parentElement)
          Stores the properties of a bean as DOM Elements
 void storeProperty(java.lang.String xmlTagName, java.lang.Object ob, java.beans.PropertyDescriptor prop, int writeType, org.w3c.dom.Element parentElement)
          Stores a non-indexed property
 void storePropertyValue(java.lang.String xmlTagName, java.lang.Object propValue, java.beans.PropertyDescriptor prop, int writeType, org.w3c.dom.Element parentElement)
          Stores a property value based on the property type
 void storePropertyValueByType(java.lang.String xmlTagName, java.lang.Object propValue, java.beans.PropertyDescriptor prop, int writeType, org.w3c.dom.Element parentElement, java.lang.Class type)
           
 void storeString(java.lang.String xmlTagName, java.lang.String propName, java.lang.Object propValue, int writeType, org.w3c.dom.Element parentElement)
          Writes out a string, using CDATA if the string contains < or &
 
Methods inherited from class com.wutka.jox.JOXBeanOutput
expandChildElements, getTranslatedChildName, getTranslatedEntityName, readDTD, setupNameTranslation, stripName, writeAsAttribute, writeBasicType, writeDate, writeIndexedProperty, writeObject, writeObjectFields, writeProperty, writePropertyValue, writePropertyValueByType, writeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

document

protected org.w3c.dom.Document document

beanCache

protected static java.util.Hashtable beanCache
Constructor Detail

JOXBeanDOM

public JOXBeanDOM()
           throws java.io.IOException
Creates a JOXBeanDOM that stores simple properties as attributes

JOXBeanDOM

public JOXBeanDOM(org.w3c.dom.Document aDocument)
           throws java.io.IOException
Creates a JOXBeanDOM that stores simple properties as attributes
Parameters:
aDocument - The document to store the bean into

JOXBeanDOM

public JOXBeanDOM(java.lang.String dtdURL)
           throws java.io.IOException
Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
Parameters:
dtdURL - The URL of the DTD

JOXBeanDOM

public JOXBeanDOM(com.wutka.dtd.DTD aDTD)
           throws java.io.IOException
Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
Parameters:
dtdURL - The URL of the DTD

JOXBeanDOM

public JOXBeanDOM(org.w3c.dom.Document aDocument,
                  java.lang.String dtdURL)
           throws java.io.IOException
Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
Parameters:
dtdURL - The URL of the DTD
aDocument - The XML document the bean will be stored in

JOXBeanDOM

public JOXBeanDOM(org.w3c.dom.Document aDocument,
                  com.wutka.dtd.DTD aDTD)
Creates a JOXBeanDOM that uses a DTD to determine which attributes to store and what the format of the names should be.
Parameters:
dtdURL - The URL of the DTD
aDocument - The XML document the bean will be stored in

JOXBeanDOM

public JOXBeanDOM(boolean writeAttributesFlag)
           throws java.io.IOException
Creates a JOXBeanDOM that doesn't use a DTD
Parameters:
writeAttributesFlag - True if simple properties should be stored as attributes

JOXBeanDOM

public JOXBeanDOM(org.w3c.dom.Document aDocument,
                  boolean writeAttributesFlag)
           throws java.io.IOException
Creates a JOXBeanDOM that doesn't use a DTD
Parameters:
aDocument - The XML document the bean will be stored in
writeAttributesFlag - True if simple properties should be stored as attributes
Method Detail

createDocument

protected void createDocument()
                       throws java.io.IOException
Creates a new Document using a DocumentBuilder

beanToDocument

public org.w3c.dom.Document beanToDocument(java.lang.String rootName,
                                           java.lang.Object ob)
                                    throws java.io.IOException
Stores a Java bean in an XML document (this is the main method for JOXBeanDOM).
Parameters:
rootName - The name of the document's root tag
ob - The bean to store in the document

storeObject

public org.w3c.dom.Element storeObject(java.lang.String rootName,
                                       java.lang.Object ob)
                                throws java.io.IOException
Stores a bean in an XML element and returns the element
Parameters:
rootName - The name of the element's tag
ob - The bean to store in the element

storeObjectFields

public void storeObjectFields(java.lang.String xmlTagName,
                              java.lang.Object ob,
                              int writeType,
                              org.w3c.dom.Element parentElement)
                       throws java.io.IOException
Stores the properties of a bean as DOM Elements
Parameters:
xmlTagName - The XML tag name of the bean being written
ob - The bean whose properties will be written
writeType - The kind of fields being written (attribute or element)
Throws:
java.io.IOException - If there is an error writing the object

storeProperty

public void storeProperty(java.lang.String xmlTagName,
                          java.lang.Object ob,
                          java.beans.PropertyDescriptor prop,
                          int writeType,
                          org.w3c.dom.Element parentElement)
                   throws java.io.IOException
Stores a non-indexed property
Parameters:
xmlTagName - The XML tag name of the bean being written
ob - The object containing the property
prop - The property descriptor of the property
writeType - Should we try to write this property as an attribute? If not, don't write the object if writeAttributes is true and this object can be written as an attribute
Throws:
java.io.IOException - If there is an error writing out the property

storeIndexedProperty

public void storeIndexedProperty(java.lang.String xmlTagName,
                                 java.lang.Object ob,
                                 java.beans.IndexedPropertyDescriptor prop,
                                 org.w3c.dom.Element parentElement)
                          throws java.io.IOException
Stores an indexed property (an array of properties)
Parameters:
xmlTagName - The XML tag name of the bean being written
ob - The object containing the property
prop - The descriptor for the property as an attribute? If not, don't write the object if writeAttributes is true and this object can be written as an attribute
Throws:
java.io.IOException - If there is an error writing the properties

storePropertyValue

public void storePropertyValue(java.lang.String xmlTagName,
                               java.lang.Object propValue,
                               java.beans.PropertyDescriptor prop,
                               int writeType,
                               org.w3c.dom.Element parentElement)
                        throws java.io.IOException
Stores a property value based on the property type
Parameters:
xmlTagName - The XML tag name of the bean being written
propValue - The value to write
prop - The property descriptor of the property
writeType - Should we try to write this property as an attribute? If not, don't write the object if writeAttributes is true and this object can be written as an attribute
Throws:
java.io.IOException - If there is an error while writing the property

storePropertyValueByType

public void storePropertyValueByType(java.lang.String xmlTagName,
                                     java.lang.Object propValue,
                                     java.beans.PropertyDescriptor prop,
                                     int writeType,
                                     org.w3c.dom.Element parentElement,
                                     java.lang.Class type)
                              throws java.io.IOException

storeBasicType

public void storeBasicType(java.lang.String xmlTagName,
                           java.lang.String propName,
                           java.lang.Object propValue,
                           int writeType,
                           org.w3c.dom.Element parentElement)
                    throws java.io.IOException
Writes out a basic type including the opening and closing tags.
Parameters:
xmlTagName - The XML tag name of the bean being written
propName - The name of the property to write
propValue - The value of the property
Throws:
java.io.IOException - If there is an error while writing the property

storeString

public void storeString(java.lang.String xmlTagName,
                        java.lang.String propName,
                        java.lang.Object propValue,
                        int writeType,
                        org.w3c.dom.Element parentElement)
                 throws java.io.IOException
Writes out a string, using CDATA if the string contains < or &
Parameters:
xmlTagName - The XML tag name of the bean being written
propName - The name of the property to write
propValue - The value of the property
outputStream - The output stream or writer where the value is to be written
Throws:
java.io.IOException - If there is an error while writing the property

storeDate

public void storeDate(java.lang.String xmlTagName,
                      java.lang.String propName,
                      java.lang.Object propValue,
                      int writeType,
                      org.w3c.dom.Element parentElement)
               throws java.io.IOException
Writes out a date including the opening and closing tags
Parameters:
xmlTagName - The XML tag name of the bean being written
propName - The name of the property to write
propValue - The value of the property
outputStream - The output stream or writer where the value is to be written
Throws:
java.io.IOException - If there is an error while writing the property