|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jlf.dataMap.DataMapper | +--org.jlf.dataMap.xmlMap.XMLDataMapper
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 |
protected org.w3c.dom.Document document
protected java.io.InputStream inputStream
protected java.io.OutputStream outputStream
protected static final java.lang.String ELEMENT_ALIAS_PROPERTY_SUFFIX
protected static final java.lang.String IS_XML_ATTRIBUTE_PROPERTY_QUALIFIER
protected static final boolean IS_XML_ATTRIBUTE_PROPERTY_DEFAULT
Constructor Detail |
public XMLDataMapper()
public XMLDataMapper(DataLocation dataLocation)
DataLocation
who created it.
Method Detail |
public java.io.InputStream getInputStream()
public void setInputStream(java.io.InputStream inputStream)
public java.io.OutputStream getOutputStream()
public void setOutputStream(java.io.OutputStream outputStream)
public org.w3c.dom.Document getDocument()
public void setDocument(org.w3c.dom.Document document)
public org.w3c.dom.Element getDocumentElement()
public org.w3c.dom.Element createDocumentElement(java.lang.String elementName)
public java.util.Vector findBySearchCriteria(DataMappedObject dmo, java.lang.String criteriaKey)
findBySearchCriteria
in class DataMapper
protected java.lang.String elementNameForObject(DataMappedObject dmo, Relationship relationship)
protected org.w3c.dom.Element newElementForObject(DataMappedObject dmo, Relationship relationship)
protected boolean isObjectAttributeAnXMLAttribute(DataMappedObject dmo, java.lang.String attributeName, Relationship relationship)
protected void cascadeWrite(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
protected void cascadeAnyWrites(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
protected void writeObjectToElement(DataMappedObject dmo, Relationship relationship, org.w3c.dom.Element dmoElement)
public void write(DataMappedObject dmo, Relationship relationship)
write
in class DataMapper
public void commitWrites()
commitWrites
in class DataMapper
public void close()
close
in class DataMapper
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |