org.dartra.standard.dao.ser
Class SerDataSource

java.lang.Object
  extended byorg.dartra.standard.dao.ser.SerDataSource
All Implemented Interfaces:
org.dartra.framework.dao.DataSource
Direct Known Subclasses:
XStreamDataSource

public class SerDataSource
extends java.lang.Object
implements org.dartra.framework.dao.DataSource

Data source implementation that accesses DarTra game data in serialized data files.

Subclasses can redefine the readData() and writeData() methods to change the serialisation mechanism.

Note: to avoid double loading issues you should make sure that you never unintentionally clear and reload a data source. Otherwise you could have 2 objects representing the same thing in memory!

Author:
Erwin Vervaet

Constructor Summary
SerDataSource(java.lang.String fileName)
          Create a new serialisation data source for named data file.
 
Method Summary
 boolean exists()
          Checks if the data file used by this data source exists on disk.
 org.dartra.framework.dao.Connection getConnection()
           
protected  DataContainer getDataContainer()
          Returns the container that holds all data accessible via this data source.
 java.lang.String getFileName()
          Returns the name of the data file accessed by this data source.
 void load()
          Load data from the data file.
protected  DataContainer readData()
          Helper to read data from the data file.
 void reset()
          Reset the data source: write an empty data file.
 java.lang.String toString()
           
 void write()
          Write the data contained by this data source to the data file.
protected  void writeData(DataContainer data)
          Helper to write data to the data file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SerDataSource

public SerDataSource(java.lang.String fileName)

Create a new serialisation data source for named data file.

Method Detail

getFileName

public java.lang.String getFileName()

Returns the name of the data file accessed by this data source.


getConnection

public org.dartra.framework.dao.Connection getConnection()
                                                  throws org.dartra.framework.dao.DataAccessException
Specified by:
getConnection in interface org.dartra.framework.dao.DataSource
Throws:
org.dartra.framework.dao.DataAccessException

getDataContainer

protected DataContainer getDataContainer()
                                  throws org.dartra.framework.dao.DataAccessException

Returns the container that holds all data accessible via this data source.

Throws:
org.dartra.framework.dao.DataAccessException

exists

public boolean exists()

Checks if the data file used by this data source exists on disk.


load

public void load()
          throws org.dartra.framework.dao.DataAccessException

Load data from the data file.

Throws:
org.dartra.framework.dao.DataAccessException

readData

protected DataContainer readData()
                          throws org.dartra.framework.dao.DataAccessException

Helper to read data from the data file.

Subclasses can redefine this method if they want to change the serialisation mechanism.

Throws:
org.dartra.framework.dao.DataAccessException

reset

public void reset()
           throws org.dartra.framework.dao.DataAccessException

Reset the data source: write an empty data file.

Throws:
org.dartra.framework.dao.DataAccessException

write

public void write()
           throws org.dartra.framework.dao.DataAccessException

Write the data contained by this data source to the data file.

Throws:
org.dartra.framework.dao.DataAccessException

writeData

protected void writeData(DataContainer data)
                  throws org.dartra.framework.dao.DataAccessException

Helper to write data to the data file.

Subclasses can redefine this method if they want to change the serialisation mechanism.

Throws:
org.dartra.framework.dao.DataAccessException

toString

public java.lang.String toString()