marf.Storage
Class StorageManager

java.lang.Object
  |
  +--marf.Storage.StorageManager
All Implemented Interfaces:
IStorageManager, java.io.Serializable
Direct Known Subclasses:
Classification, Database, FeatureExtraction, GrammarCompiler, Preprocessing, ProbabilisticParser, Spectrogram, StatisticalEstimator, TrainingSet, WaveGrapher

public abstract class StorageManager
extends java.lang.Object
implements IStorageManager

Class StorageManager.

Almost every concrete module must inherit from this class. If that's not possible, implement IStorageManager interface.

$Id: StorageManager.java,v 1.23 2005/06/20 21:45:15 mokhov Exp $

Since:
0.0.1
Version:
$Revision: 1.23 $
Author:
Serguei Mokhov
See Also:
Serialized Form

Field Summary
protected  boolean bDumpOnNotFound
          If set to true (the default), causes restoreBinary() or restoreGzipBinary() to create a file if it does not exist.
protected  int iCurrentDumpMode
          Indicates in which format dump training data.
protected  java.lang.Object oObjectToSerialize
          Actual object to be serialized (primarily for GZIP and BINARY modes.
protected  java.lang.String strFilename
          Filename of the file to be dumped/restored.
 
Fields inherited from interface marf.Storage.IStorageManager
DUMP_BINARY, DUMP_CSV_TEXT, DUMP_GZIP_BINARY, DUMP_HTML, DUMP_SQL, DUMP_XML, MARF_INTERFACE_CODE_REVISION, STORAGE_FILE_EXTENSIONS
 
Constructor Summary
StorageManager()
          Default constructor equivalent to StorageManager(null, getClass().getName()).
StorageManager(java.lang.Object poObjectToSerialize)
          General constructor with serializable object parameter.
StorageManager(java.lang.Object poObjectToSerialize, boolean pbDumpOnNotFound)
          General constructor with serializable object parameter.
StorageManager(java.lang.Object poObjectToSerialize, java.lang.String pstrFilename)
          General constructor with filename and serializable object parameters.
StorageManager(java.lang.Object poObjectToSerialize, java.lang.String pstrFilename, boolean pbDumpOnNotFound)
          General constructor with filename and serializable object parameters.
StorageManager(java.lang.String pstrFilename)
          Constructor with filename parameter equivalent to StorageManager(null, pstrFilename).
StorageManager(java.lang.String pstrFilename, boolean pbDumpOnNotFound)
          Constructor with filename parameter equivalent to StorageManager(null, pstrFilename).
 
Method Summary
 void backSynchronizeObject()
          Must to be overridden by the modules that use object serialization with the generic implementation of restore().
 void dump()
          An object must know how dump itself or its data structures to a file.
 void dumpBinary()
          Implements object dump in plain binary form without compression.
 void dumpCSV()
          If derivatives use the generic implementation of dump() with the CSV dump mode, they must override this method.
 void dumpGzipBinary()
          Implements object dump in GZIP-compressed form.
 void dumpHTML()
          If derivatives use the generic implementation of dump() with the HTML dump mode, they must override this method.
 void dumpSQL()
          If derivatives use the generic implementation of dump() with the SQL dump mode, they must override this method.
 void dumpXML()
          If derivatives use the generic implementation of dump() with the XML dump mode, they must override this method.
 boolean enableDumpOnNotFound(boolean pbEnable)
          Enables or disables creation of a file if it does not exist.
 java.lang.String getDefaultExtension()
          Retrieves default filename extension of this storage manager.
static java.lang.String getDefaultExtension(int piDumpMode)
          Retrieves default filename extension depending on dump type.
 int getDumpMode()
          Retrieves current dump mode.
 java.lang.String getFilename()
          Retrieves inner filename reference.
static java.lang.String getMARFSourceCodeRevision()
          Returns source code revision information.
 void restore()
          An object must know how restore itself or its data structures from a file.
 void restoreBinary()
          Implements object loading from plain binary form without compression.
 void restoreCSV()
          If derivatives use the generic implementation of restore() with the CSV dump mode, they must override this method.
 void restoreGzipBinary()
          Implements object loading from GZIP-compressed binary form.
 void restoreHTML()
          If derivatives use the generic implementation of restore() with the HTML dump mode, they must override this method.
 void restoreSQL()
          If derivatives use the generic implementation of restore() with the SQL dump mode, they must override this method.
 void restoreXML()
          If derivatives use the generic implementation of restore() with the XML dump mode, they must override this method.
 void setDumpMode(int piCurrentDumpMode)
          Sets the dump mode.
 void setFilename(java.lang.String pstrFilename)
          Allows to alter inner filename reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iCurrentDumpMode

protected transient int iCurrentDumpMode
Indicates in which format dump training data.

Can either be one of the DUMP_ flags, with the DUMP_GZIP_BINARY being the default.

Since:
0.2.0

strFilename

protected transient java.lang.String strFilename
Filename of the file to be dumped/restored.

Since:
0.3.0

oObjectToSerialize

protected java.lang.Object oObjectToSerialize
Actual object to be serialized (primarily for GZIP and BINARY modes. Has to be back-synchronized.

Since:
0.3.0
See Also:
backSynchronizeObject()

bDumpOnNotFound

protected transient boolean bDumpOnNotFound
If set to true (the default), causes restoreBinary() or restoreGzipBinary() to create a file if it does not exist. If set to false, an exception is thrown.

Since:
0.3.0
See Also:
restoreBinary(), restoreGzipBinary()
Constructor Detail

StorageManager

public StorageManager()
Default constructor equivalent to StorageManager(null, getClass().getName()). Sets internal filename to the class name of the derivative.

Since:
0.3.0
See Also:
StorageManager(Object, String), strFilename

StorageManager

public StorageManager(java.lang.String pstrFilename)
Constructor with filename parameter equivalent to StorageManager(null, pstrFilename).

Parameters:
pstrFilename - customized filename
Since:
0.3.0
See Also:
StorageManager(Object, String), strFilename

StorageManager

public StorageManager(java.lang.Object poObjectToSerialize)
General constructor with serializable object parameter. Sets internal filename to the class name of the parameter.

Parameters:
poObjectToSerialize - reference to object to be dumped to a file
Since:
0.3.0
See Also:
oObjectToSerialize, bDumpOnNotFound

StorageManager

public StorageManager(java.lang.Object poObjectToSerialize,
                      java.lang.String pstrFilename)
General constructor with filename and serializable object parameters.

Parameters:
poObjectToSerialize - reference to object to be dumped to a file
pstrFilename - customized filename
Since:
0.3.0
See Also:
oObjectToSerialize, strFilename, bDumpOnNotFound

StorageManager

public StorageManager(java.lang.String pstrFilename,
                      boolean pbDumpOnNotFound)
Constructor with filename parameter equivalent to StorageManager(null, pstrFilename).

Parameters:
pstrFilename - customized filename
pbDumpOnNotFound - if true, a dump file will be created if it does not exist; if false, an exception will be thrown
Since:
0.3.0
See Also:
StorageManager(Object, String), strFilename

StorageManager

public StorageManager(java.lang.Object poObjectToSerialize,
                      boolean pbDumpOnNotFound)
General constructor with serializable object parameter. Sets internal filename to the class name of the parameter.

Parameters:
poObjectToSerialize - reference to object to be dumped to a file
pbDumpOnNotFound - if true, a dump file will be created if it does not exist; if false, an exception will be thrown
Since:
0.3.0
See Also:
oObjectToSerialize, bDumpOnNotFound

StorageManager

public StorageManager(java.lang.Object poObjectToSerialize,
                      java.lang.String pstrFilename,
                      boolean pbDumpOnNotFound)
General constructor with filename and serializable object parameters.

Parameters:
poObjectToSerialize - reference to object to be dumped to a file
pstrFilename - customized filename
pbDumpOnNotFound - if true, a dump file will be created if it does not exist; if false, an exception will be thrown
Since:
0.3.0
See Also:
oObjectToSerialize, strFilename
Method Detail

dump

public void dump()
          throws StorageException
An object must know how dump itself or its data structures to a file. Options are: Object serialization, XML, CSV, HTML, SQL. Internally, the method calls all the dump*() methods based on the current dump mode. If the derivatives use only DUMP_GZIP_BINARY or DUMP_BINARY modes, the need not do anything except implementing backSynchronizeObject(). For the rest of modes they only have to override a corresponding dump*() method.

Specified by:
dump in interface IStorageManager
Throws:
StorageException - if saving to a file for some reason fails or the dump mode set to an unsupported value
See Also:
IStorageManager.DUMP_GZIP_BINARY, IStorageManager.DUMP_BINARY, dumpGzipBinary(), dumpCSV(), dumpBinary(), dumpXML(), dumpHTML(), dumpSQL(), backSynchronizeObject(), iCurrentDumpMode

dumpGzipBinary

public void dumpGzipBinary()
                    throws StorageException
Implements object dump in GZIP-compressed form. Attempts to save internal object reference to the generater/specified filename

Specified by:
dumpGzipBinary in interface IStorageManager
Throws:
StorageException - in case of I/O or otherwise error during object dump
Since:
0.3.0
See Also:
oObjectToSerialize, strFilename

dumpBinary

public void dumpBinary()
                throws StorageException
Implements object dump in plain binary form without compression. Attempts to save internal object reference to the generater/specified filename

Specified by:
dumpBinary in interface IStorageManager
Throws:
StorageException - in case of I/O or otherwise error during object dump
Since:
0.3.0
See Also:
oObjectToSerialize, strFilename

dumpCSV

public void dumpCSV()
             throws StorageException
If derivatives use the generic implementation of dump() with the CSV dump mode, they must override this method.

Specified by:
dumpCSV in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
dump()

dumpXML

public void dumpXML()
             throws StorageException
If derivatives use the generic implementation of dump() with the XML dump mode, they must override this method.

Specified by:
dumpXML in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
dump()

dumpHTML

public void dumpHTML()
              throws StorageException
If derivatives use the generic implementation of dump() with the HTML dump mode, they must override this method.

Specified by:
dumpHTML in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
dump()

dumpSQL

public void dumpSQL()
             throws StorageException
If derivatives use the generic implementation of dump() with the SQL dump mode, they must override this method.

Specified by:
dumpSQL in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
dump()

restore

public void restore()
             throws StorageException
An object must know how restore itself or its data structures from a file. Options are: Object serialization, XML, CSV, HTML, SQL. Internally, the method calls all the restore*() methods based on the current dump mode. If the derivatives use only DUMP_GZIP_BINARY or DUMP_BINARY modes, the need not do anything except implementing backSynchronizeObject(). For the rest of modes they only have to override a corresponding restore*() method.

Specified by:
restore in interface IStorageManager
Throws:
StorageException - if loading from a file for some reason fails or the dump mode set to an unsupported value
See Also:
IStorageManager.DUMP_GZIP_BINARY, IStorageManager.DUMP_BINARY, dumpGzipBinary(), dumpCSV(), dumpBinary(), dumpXML(), dumpHTML(), dumpSQL(), backSynchronizeObject(), iCurrentDumpMode

restoreBinary

public void restoreBinary()
                   throws StorageException
Implements object loading from plain binary form without compression. Attempts to load internal object reference with the generater/specified filename. After, calls backSynchronizeObject() so the actual mode can reset back references in its own data structures. If the file that we attempt to load did not exist, it will be created.

Specified by:
restoreBinary in interface IStorageManager
Throws:
StorageException - in case of I/O or otherwise error during object retoration
Since:
0.3.0
See Also:
backSynchronizeObject(), strFilename

restoreGzipBinary

public void restoreGzipBinary()
                       throws StorageException
Implements object loading from GZIP-compressed binary form. Attempts to load internal object reference with the generater/specified filename. After, calls backSynchronizeObject() so the actual mode can reset back references in its own data structures. If the file that we attempt to load did not exist, it will be created.

Specified by:
restoreGzipBinary in interface IStorageManager
Throws:
StorageException - in case of I/O or otherwise error during object retoration
Since:
0.3.0
See Also:
backSynchronizeObject(), strFilename

restoreCSV

public void restoreCSV()
                throws StorageException
If derivatives use the generic implementation of restore() with the CSV dump mode, they must override this method.

Specified by:
restoreCSV in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
restore()

restoreXML

public void restoreXML()
                throws StorageException
If derivatives use the generic implementation of restore() with the XML dump mode, they must override this method.

Specified by:
restoreXML in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
restore()

restoreHTML

public void restoreHTML()
                 throws StorageException
If derivatives use the generic implementation of restore() with the HTML dump mode, they must override this method.

Specified by:
restoreHTML in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
restore()

restoreSQL

public void restoreSQL()
                throws StorageException
If derivatives use the generic implementation of restore() with the SQL dump mode, they must override this method.

Specified by:
restoreSQL in interface IStorageManager
Throws:
NotImplementedException
StorageException, - declared, but never thrown
StorageException - in case of I/O or otherwise error
Since:
0.3.0
See Also:
restore()

backSynchronizeObject

public void backSynchronizeObject()
Must to be overridden by the modules that use object serialization with the generic implementation of restore(). By default this method is unimplemented.

Throws:
NotImplementedException
Since:
0.3.0
See Also:
restore()

getFilename

public java.lang.String getFilename()
Retrieves inner filename reference.

Returns:
filename string
Since:
0.3.0

setFilename

public void setFilename(java.lang.String pstrFilename)
Allows to alter inner filename reference.

Parameters:
pstrFilename - new filename
Since:
0.3.0

getDefaultExtension

public java.lang.String getDefaultExtension()
Retrieves default filename extension of this storage manager.

Returns:
extension String
Since:
0.3.0

getDefaultExtension

public static java.lang.String getDefaultExtension(int piDumpMode)
Retrieves default filename extension depending on dump type.

Parameters:
piDumpMode - dump mode to query extensions map by
Returns:
extension String; "unknown" is returned if the parameter is outside of the range
Since:
0.3.0

getDumpMode

public final int getDumpMode()
Retrieves current dump mode.

Returns:
the mode, integer
Since:
0.3.0

setDumpMode

public final void setDumpMode(int piCurrentDumpMode)
Sets the dump mode.

Parameters:
piCurrentDumpMode - the mode
Since:
0.3.0

enableDumpOnNotFound

public final boolean enableDumpOnNotFound(boolean pbEnable)
Enables or disables creation of a file if it does not exist.

Parameters:
pbEnable - new value of the flag
Returns:
old value of the flag
Since:
0.3.0
See Also:
bDumpOnNotFound

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Returns source code revision information.

Returns:
revision string
Since:
0.3.0