org.jlf.dataMap.xmlMap
Class XMLDataMapper

java.lang.Object
  |
  +--org.jlf.dataMap.DataMapper
        |
        +--org.jlf.dataMap.xmlMap.XMLDataMapper

public class XMLDataMapper
extends DataMapper

This class is used to map data-mapped objects from/to XML files. The current implementation uses SAX for read and DOM for write.

NOTE: Reading from an XML stream (via SAX) is NOT YET supported!!!

This data mapper has the following additional properties you can set in your data map:

 (className).elementAlias=(elementAlias)
     Instead of using the last dot-name of a class as the element
     name for the class, uses the alias value.  For example,
     org.jlf.demo.Customer would use an element name Customer
     by default, but could be overridden to be whatever you want.

 (className).relationship.(relationshipName).elementAlias=(elementAlias)
     Same as above, but works for cascading a relationship write
     and overrides specific only to that relationship

 (className).XMLattribute.(attributeName)=true
     Provides an override on a data mapped object's named attribute
     to say that instead of generating it as an XML element, generate
     it as an XML attribute in the context of the parent element.

 (className).relationship.(relationshipName).XMLattribute.(attributeName)=true
     Same as above, but works for cascading a relationship write
     and overrides specific only to that relationship

 


Field Summary
protected  org.w3c.dom.Document document
          Holds the XML Document.
protected static java.lang.String ELEMENT_ALIAS_PROPERTY_SUFFIX
          Property key suffix for element aliases
protected  java.io.InputStream inputStream
          Holds the input stream to parse.
protected static boolean IS_XML_ATTRIBUTE_PROPERTY_DEFAULT
           
protected static java.lang.String IS_XML_ATTRIBUTE_PROPERTY_QUALIFIER
           
protected  java.io.OutputStream outputStream
          Holds the output stream to serialize to.
 
Fields inherited from class org.jlf.dataMap.DataMapper
dataArray, dataLocation
 
Constructor Summary
XMLDataMapper()
          Allow the default constructor, please use a parameterized constructor!
XMLDataMapper(DataLocation dataLocation)
          Constructs a new data mapper which references back to the DataLocation who created it.
 
Method Summary
protected  void cascadeAnyWrites(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
          Helper method to cascade relationship writes.
protected  void cascadeWrite(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
          Helper method to one particular relationship write.
 void close()
          Close the data mapper so it can clean up any resources it may have allocated.
 void commitWrites()
          Writes the XML document out to the output stream.
 org.w3c.dom.Element createDocumentElement(java.lang.String elementName)
          If the XML Document root element is not already created, create one with the element name given and return it.
protected  java.lang.String elementNameForObject(DataMappedObject dmo, Relationship relationship)
          Helper method to find an element name/alias for the given data mapped object and potentially nested relationship if not null.
 java.util.Vector findBySearchCriteria(DataMappedObject dmo, java.lang.String criteriaKey)
          This method is an abstract method for the purpose of using the current data location mapper to read any number of objects according to the DataMappedObject's type and search criteria.
 org.w3c.dom.Document getDocument()
          Retrieves the XML Document the data mapper will write to when asked to write a data mapped object.
 org.w3c.dom.Element getDocumentElement()
          Gets the XML Document root element.
 java.io.InputStream getInputStream()
          Retrieves the input stream the XML parser will parse on a read request.
 java.io.OutputStream getOutputStream()
          Retrieves the output stream the data mapper will serialize to when called to write the document.
protected  boolean isObjectAttributeAnXMLAttribute(DataMappedObject dmo, java.lang.String attributeName, Relationship relationship)
          Helper method to obtain a property file setting to see if we are supposed to generate an object attribute as an XML Element or an XML Attribute.
protected  org.w3c.dom.Element newElementForObject(DataMappedObject dmo, Relationship relationship)
          Helper method to create a new XML Element at the root level of the XML document, given the class of data mapped object.
 void setDocument(org.w3c.dom.Document document)
          Sets the XML Document the data mapper will write to when asked to write a data mapped object.
 void setInputStream(java.io.InputStream inputStream)
          Sets the input stream the XML parser will parse on a read request.
 void setOutputStream(java.io.OutputStream outputStream)
          Sets the output stream the data mapper will serialize to when called to write the document.
 void write(DataMappedObject dmo, Relationship relationship)
          Writes the data mapped object, in the context of the relationship, to the end of the XML document.
protected  void writeObjectToElement(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
          Helper method to write a data mapped object to an XML element according to mappings in the property file.
 
Methods inherited from class org.jlf.dataMap.DataMapper
findDataAttributeForReplacementString, getCascadedRelationships, getDataLocation, replaceAttributeParameters, rollbackWrites, setDataLocation, stringForDataAttributeReplacement
 
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
Holds the XML Document.


inputStream

protected java.io.InputStream inputStream
Holds the input stream to parse.


outputStream

protected java.io.OutputStream outputStream
Holds the output stream to serialize to.


ELEMENT_ALIAS_PROPERTY_SUFFIX

protected static final java.lang.String ELEMENT_ALIAS_PROPERTY_SUFFIX
Property key suffix for element aliases

See Also:
Constant Field Values

IS_XML_ATTRIBUTE_PROPERTY_QUALIFIER

protected static final java.lang.String IS_XML_ATTRIBUTE_PROPERTY_QUALIFIER
See Also:
Constant Field Values

IS_XML_ATTRIBUTE_PROPERTY_DEFAULT

protected static final boolean IS_XML_ATTRIBUTE_PROPERTY_DEFAULT
See Also:
Constant Field Values
Constructor Detail

XMLDataMapper

public XMLDataMapper()
Allow the default constructor, please use a parameterized constructor!


XMLDataMapper

public XMLDataMapper(DataLocation dataLocation)
Constructs a new data mapper which references back to the DataLocation who created it.

Method Detail

getInputStream

public java.io.InputStream getInputStream()
Retrieves the input stream the XML parser will parse on a read request.


setInputStream

public void setInputStream(java.io.InputStream inputStream)
Sets the input stream the XML parser will parse on a read request.


getOutputStream

public java.io.OutputStream getOutputStream()
Retrieves the output stream the data mapper will serialize to when called to write the document.


setOutputStream

public void setOutputStream(java.io.OutputStream outputStream)
Sets the output stream the data mapper will serialize to when called to write the document.


getDocument

public org.w3c.dom.Document getDocument()
Retrieves the XML Document the data mapper will write to when asked to write a data mapped object.


setDocument

public void setDocument(org.w3c.dom.Document document)
Sets the XML Document the data mapper will write to when asked to write a data mapped object.


getDocumentElement

public org.w3c.dom.Element getDocumentElement()
Gets the XML Document root element. Passthrough to the Document method with same name.


createDocumentElement

public org.w3c.dom.Element createDocumentElement(java.lang.String elementName)
If the XML Document root element is not already created, create one with the element name given and return it. Otherwise return the already created top level element.


findBySearchCriteria

public java.util.Vector findBySearchCriteria(DataMappedObject dmo,
                                             java.lang.String criteriaKey)
This method is an abstract method for the purpose of using the current data location mapper to read any number of objects according to the DataMappedObject's type and search criteria.

Specified by:
findBySearchCriteria in class DataMapper

elementNameForObject

protected java.lang.String elementNameForObject(DataMappedObject dmo,
                                                Relationship relationship)
Helper method to find an element name/alias for the given data mapped object and potentially nested relationship if not null.


newElementForObject

protected org.w3c.dom.Element newElementForObject(DataMappedObject dmo,
                                                  Relationship relationship)
Helper method to create a new XML Element at the root level of the XML document, given the class of data mapped object. All data mapped object attributes can then be written to that element. If a root level element has already been created, this method creates a new element as a child of that root level element.


isObjectAttributeAnXMLAttribute

protected boolean isObjectAttributeAnXMLAttribute(DataMappedObject dmo,
                                                  java.lang.String attributeName,
                                                  Relationship relationship)
Helper method to obtain a property file setting to see if we are supposed to generate an object attribute as an XML Element or an XML Attribute.


cascadeWrite

protected void cascadeWrite(DataMappedObject dmo,
                            Relationship relationship,
                            org.w3c.dom.Element dmoElement)
Helper method to one particular relationship write.


cascadeAnyWrites

protected void cascadeAnyWrites(DataMappedObject dmo,
                                Relationship relationship,
                                org.w3c.dom.Element dmoElement)
Helper method to cascade relationship writes.


writeObjectToElement

protected void writeObjectToElement(DataMappedObject dmo,
                                    Relationship relationship,
                                    org.w3c.dom.Element dmoElement)
Helper method to write a data mapped object to an XML element according to mappings in the property file.


write

public void write(DataMappedObject dmo,
                  Relationship relationship)
Writes the data mapped object, in the context of the relationship, to the end of the XML document.

Specified by:
write in class DataMapper

commitWrites

public void commitWrites()
Writes the XML document out to the output stream.

Specified by:
commitWrites in class DataMapper

close

public void close()
Close the data mapper so it can clean up any resources it may have allocated.

Specified by:
close in class DataMapper