com.anji.persistence
Class FilePersistence

java.lang.Object
  extended by com.anji.persistence.FilePersistence
All Implemented Interfaces:
Persistence, Configurable

public class FilePersistence
extends java.lang.Object
implements Persistence

Simple file-based implementation of persistence layer. All files are stored in a file named baseDir/type/type+key. All objects stores must implement XmlPersistable.type is derived from XmlPersistable.getXmlRootTag(), and key is derived from XmlPersistable.getId().

Author:
Philip Tucker

Field Summary
static java.lang.String BASE_DIR_KEY
          properties key, base directory for persistence storage
 
Fields inherited from interface com.anji.persistence.Persistence
PERSISTENCE_CLASS_KEY
 
Constructor Summary
FilePersistence()
           
 
Method Summary
static Chromosome chromosomeFromXml(Configuration config, org.w3c.dom.Node chromNode)
           
static Chromosome chromosomeFromXml(Configuration config, java.lang.String xml)
           
 void deleteChromosome(java.lang.String id)
          delete chromosome identified by by id
protected  java.lang.String fullPath(java.lang.String type, java.lang.String key)
          Construct full path of file based on type and key.
 void init(Properties props)
          See Parameter Details for specific property settings.
 Chromosome loadChromosome(java.lang.String id, Configuration config)
           
 Genotype loadGenotype(Configuration config)
          loads genotype as of latest generation in run
 void reset()
          remove all data from storage
 void startRun(java.lang.String aRunId)
          Begin run.
 void store(Activator a)
           
 void store(Chromosome c)
           
 void store(Run r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE_DIR_KEY

public static final java.lang.String BASE_DIR_KEY
properties key, base directory for persistence storage

See Also:
Constant Field Values
Constructor Detail

FilePersistence

public FilePersistence()
Method Detail

init

public void init(Properties props)
See Parameter Details for specific property settings.

Specified by:
init in interface Persistence
Specified by:
init in interface Configurable
Parameters:
props - configuration parameters

fullPath

protected java.lang.String fullPath(java.lang.String type,
                                    java.lang.String key)
Construct full path of file based on type and key.

Parameters:
type -
key -
Returns:
String resulting path

reset

public void reset()
Description copied from interface: Persistence
remove all data from storage

Specified by:
reset in interface Persistence
See Also:
Persistence.reset()

store

public void store(Chromosome c)
           throws java.lang.Exception
Specified by:
store in interface Persistence
Parameters:
c - chromosome to store
Throws:
java.lang.Exception
See Also:
Persistence.store(org.jgap.Chromosome)

store

public void store(Activator a)
           throws java.lang.Exception
Specified by:
store in interface Persistence
Parameters:
a - activator to store
Throws:
java.lang.Exception
See Also:
Persistence.store(com.anji.integration.Activator)

store

public void store(Run r)
           throws java.lang.Exception
Specified by:
store in interface Persistence
Parameters:
r - run to store
Throws:
java.lang.Exception
See Also:
Persistence.store(com.anji.run.Run)

chromosomeFromXml

public static Chromosome chromosomeFromXml(Configuration config,
                                           java.lang.String xml)
                                    throws java.lang.Exception
Parameters:
config -
xml -
Returns:
chromosome constructed from xml
Throws:
java.lang.Exception

chromosomeFromXml

public static Chromosome chromosomeFromXml(Configuration config,
                                           org.w3c.dom.Node chromNode)
Parameters:
config -
chromNode -
Returns:
chromosome constructed from xml

loadChromosome

public Chromosome loadChromosome(java.lang.String id,
                                 Configuration config)
Specified by:
loadChromosome in interface Persistence
Returns:
chromosome from persistence
See Also:
Persistence.loadChromosome(java.lang.String, org.jgap.Configuration)

deleteChromosome

public void deleteChromosome(java.lang.String id)
                      throws java.lang.Exception
Description copied from interface: Persistence
delete chromosome identified by by id

Specified by:
deleteChromosome in interface Persistence
Parameters:
id - id of chromosome to delete
Throws:
java.lang.Exception
See Also:
Persistence.deleteChromosome(java.lang.String)

loadGenotype

public Genotype loadGenotype(Configuration config)
Description copied from interface: Persistence
loads genotype as of latest generation in run

Specified by:
loadGenotype in interface Persistence
Returns:
genotype; null if there is no previous run
See Also:
Persistence.loadGenotype(org.jgap.Configuration)

startRun

public void startRun(java.lang.String aRunId)
Description copied from interface: Persistence
Begin run. All successive calls to this persistance object will be in the context of this run.

Specified by:
startRun in interface Persistence
See Also:
Persistence.startRun(java.lang.String)