com.extentech.ExtenBean
Class XMLDataObjectFactory

java.lang.Object
  extended by com.extentech.ExtenBean.XMLDataObjectFactory
All Implemented Interfaces:
PersistenceEngine

public class XMLDataObjectFactory
extends Object
implements PersistenceEngine

XMLDataObjectFactory is a PersistenceEngine used to initialize XMLDataObjects from XML Data Source. This class can load XML data from Files, databases and arbitrary InputStreams. Since not all input methods allow for saving back, only File and DataBase backed XMLDataObjects

Version:
1.1
Author:
Nicholas Rab -- Copyright ©2010 Extentech Inc.
See Also:
PersistenceEngine, ExtenBeanFactory, DataObject, colinfo

Constructor Summary
XMLDataObjectFactory()
           
 
Method Summary
 void createDom()
          ParseXML creates the DOM based off of an xml file passed to it
 void createDom(InputSource in)
          create Dom Document from an InputSource object 20061005 KSC
 void createDom(InputStream in)
          ParseXML creates the DOM based off of an xml file passed to it
 DataObject createNewDataObject(DataObject d)
          creates a new Data Object
 void finalize()
          perform cleanup
 byte[] getBytes()
          output the DOM to file
 org.jdom.Document getDocument()
          return the underlying XML document
 String getfPersisted()
          return the previous persisted filename
 String getXMLFile()
          returns the string path of the XML file
 DataObject initDataObject(DataObject dobj)
          initDataObject handles parsing an XML file and creating a data object off of it.
static void listChildren(org.jdom.Element current, int depth)
          useful debugging method
 boolean persist()
          persist the XML tree to its source
 boolean persist(String fName)
           
 boolean removeDataObject(DataObject o)
          removes the dataobject from the DOM and re-persists to the underlying datasource if possible.
 void setConnection(Connection c)
          Set the database connection for this factory.
 void setDocType(String tn, String schema)
          set the doc type for the underlying document
 void setXMLFile(String s)
          sets the XML file to use as underlying XML document automatically updates the DOM after setting
 void setXMLFile(String s, boolean update)
          sets the XML file to use as underlying XML document does NOT automatically updates the DOM after setting
 void setXMLFile(URL u)
          sets the underlying XML document based upon a URL which is then loaded as an InputStream
 void setXMLStream(InputSource in)
          Create Document from InputSource object automatically updates the DOM after setting
 void setXMLStream(InputStream in)
          sets the XML file to use as underlying XML document InputStream automatically updates the DOM after setting
 boolean storeDataObject(DataObject o)
          stores the dataobject to the underlying datasource if possible.
 String toString()
          returns the path to the input aka: delegates to getXMLFile
 boolean updateDataObject(DataObject o)
          udpates the values of a given node and its children and writes to the underlying data source if possible.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLDataObjectFactory

public XMLDataObjectFactory()
Method Detail

setDocType

public void setDocType(String tn,
                       String schema)
set the doc type for the underlying document

Parameters:
tn -
schema -

setConnection

public void setConnection(Connection c)
Set the database connection for this factory.

Specified by:
setConnection in interface PersistenceEngine

setXMLFile

public void setXMLFile(URL u)
sets the underlying XML document based upon a URL which is then loaded as an InputStream

Parameters:
u -

setXMLFile

public void setXMLFile(String s)
sets the XML file to use as underlying XML document automatically updates the DOM after setting

Parameters:
s -

setXMLFile

public void setXMLFile(String s,
                       boolean update)
sets the XML file to use as underlying XML document does NOT automatically updates the DOM after setting

Parameters:
s -
update - - option to update the DOM after setting

setXMLStream

public void setXMLStream(InputStream in)
sets the XML file to use as underlying XML document InputStream automatically updates the DOM after setting

Parameters:
in - - inputstream containing XML doc bytes

setXMLStream

public void setXMLStream(InputSource in)
Create Document from InputSource object automatically updates the DOM after setting

Parameters:
inputstream - document source.

getDocument

public org.jdom.Document getDocument()
return the underlying XML document

Returns:
Document

getXMLFile

public String getXMLFile()
returns the string path of the XML file

Returns:

toString

public String toString()
returns the path to the input aka: delegates to getXMLFile

Overrides:
toString in class Object

createDom

public void createDom(InputStream in)
ParseXML creates the DOM based off of an xml file passed to it


createDom

public void createDom(InputSource in)
create Dom Document from an InputSource object 20061005 KSC

Parameters:
in -

createDom

public void createDom()
ParseXML creates the DOM based off of an xml file passed to it


createNewDataObject

public DataObject createNewDataObject(DataObject d)
creates a new Data Object

Specified by:
createNewDataObject in interface PersistenceEngine
Returns:
a new dataobject
See Also:
PersistenceEngine.createNewDataObject(com.extentech.ExtenBean.DataObject)

finalize

public void finalize()
perform cleanup

Overrides:
finalize in class Object
See Also:
Object.finalize()

initDataObject

public DataObject initDataObject(DataObject dobj)
initDataObject handles parsing an XML file and creating a data object off of it.

Specified by:
initDataObject in interface PersistenceEngine
Parameters:
dobj - The DataObject for which you are requesting data.
Returns:
The DataObject populated with data.

removeDataObject

public boolean removeDataObject(DataObject o)
removes the dataobject from the DOM and re-persists to the underlying datasource if possible.

Specified by:
removeDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.
See Also:
PersistenceEngine.removeDataObject(com.extentech.ExtenBean.DataObject)

storeDataObject

public boolean storeDataObject(DataObject o)
stores the dataobject to the underlying datasource if possible.

Specified by:
storeDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.
See Also:
PersistenceEngine.storeDataObject(com.extentech.ExtenBean.DataObject)

persist

public boolean persist()
                throws Exception
persist the XML tree to its source

Returns:
Throws:
Exception

persist

public boolean persist(String fName)
                throws Exception
Throws:
Exception

getfPersisted

public String getfPersisted()
return the previous persisted filename

Returns:
String persisted filename
See Also:
persist(String)

getBytes

public byte[] getBytes()
output the DOM to file


updateDataObject

public boolean updateDataObject(DataObject o)
udpates the values of a given node and its children and writes to the underlying data source if possible.

Specified by:
updateDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.
See Also:
PersistenceEngine.updateDataObject(com.extentech.ExtenBean.DataObject)

listChildren

public static void listChildren(org.jdom.Element current,
                                int depth)
useful debugging method



Copyright © 2010 Extentech Inc. All Rights Reserved.