net.sf.jameleon.util
Class StateStorer

java.lang.Object
  extended by net.sf.jameleon.util.StateStorer

public class StateStorer
extends Object

A bean that keeps track of a list of Storables and calls the store on each at the appropriate time. The appropriate times are:

  1. ON_ERROR_EVENT - When some error occurs.
  2. ON_STATE_CHANGE_EVENT - Everytime the object changes state.
  3. ON_NO_EVENT - Never store the state.
The default event is ON_ERROR_EVENT. When one of these event occurs, first the storableEvent event is checked to see if the event is to be recorded. If the event is not to be recorded, then nothing happens. If the event is to be recorded, then the Storable.store(java.lang.String,int) is called for each Storable in the list of registered Storables.


Field Summary
protected  boolean available
           
static int DEFAULT_EVENT
          The default event at which to store the state of the object.
static String DEFAULT_STORE_DIR
          The default event at which to store the state of the object.
protected static org.apache.log4j.Logger log
           
static int ON_COMMAND_EVENT
          Don't store the state of the object.
static int ON_ERROR_EVENT
          Only store the state of the object on an unexpected error ( not an assertion error ).
static int ON_NO_EVENT
          Don't store the state of the object.
static int ON_STATE_CHANGE_EVENT
          Store the state of the object everytime the state itself changes.
protected static StateStorer stateStorer
           
protected  int storableEvent
          When to store the state of the Storables.
protected  Set storables
          A list of storables whose state will be stored at the appropriate time.
protected  File storeDir
          The directory to store the Storables' state to.
 
Method Summary
 void addStorable(Storable s)
          Adds a Storable for which the state will be stored when the appropriate event occurs..
 void eventOccured(int event)
          Records that an event occured.
static StateStorer getInstance()
           
 int getStorableEvent()
           
 Set getStorables()
          Gets the list of storables to be stored when the appropriate event occurs.
 File getStoreDir()
           
protected  boolean isStateStorable(int event)
          Tests whether the state of a storable is to be stored or not.
 void removeStorable(Storable s)
          Removes a Storable for which the state will be stored when the appropriate event occurs..
 void reset()
           
 void setStorableEvent(int event)
          Sets the event at which the state of the storables will be saved.
 void setStoreDir(File dir)
           
protected  void storeState(int event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateStorer

protected static StateStorer stateStorer

storableEvent

protected int storableEvent
When to store the state of the Storables.


storables

protected Set storables
A list of storables whose state will be stored at the appropriate time.


DEFAULT_STORE_DIR

public static final String DEFAULT_STORE_DIR
The default event at which to store the state of the object.

See Also:
Constant Field Values

storeDir

protected File storeDir
The directory to store the Storables' state to.


ON_ERROR_EVENT

public static final int ON_ERROR_EVENT
Only store the state of the object on an unexpected error ( not an assertion error ).

See Also:
Constant Field Values

ON_STATE_CHANGE_EVENT

public static final int ON_STATE_CHANGE_EVENT
Store the state of the object everytime the state itself changes.

See Also:
Constant Field Values

ON_NO_EVENT

public static final int ON_NO_EVENT
Don't store the state of the object.

See Also:
Constant Field Values

ON_COMMAND_EVENT

public static final int ON_COMMAND_EVENT
Don't store the state of the object.

See Also:
Constant Field Values

DEFAULT_EVENT

public static final int DEFAULT_EVENT
The default event at which to store the state of the object.

See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log

available

protected boolean available
Method Detail

getInstance

public static StateStorer getInstance()

reset

public void reset()

isStateStorable

protected boolean isStateStorable(int event)
Tests whether the state of a storable is to be stored or not.

Parameters:
event - - use ON_ERROR for an error or ON_STATE_CHANGE for a simple state change.
Returns:
true if the state

eventOccured

public void eventOccured(int event)
Records that an event occured. If the event is set as a storable event at runtime, then thee state of all Storables will be recorded.

Parameters:
event - - The event type that occured.

getStorableEvent

public int getStorableEvent()
Returns:
the event at which the Storables' state will be stored.

setStorableEvent

public void setStorableEvent(int event)
Sets the event at which the state of the storables will be saved.

Parameters:
event - - the event at which the Storables' state will be stored. If an invalid event is passed, the storableEvent will not be changed.

getStorables

public Set getStorables()
Gets the list of storables to be stored when the appropriate event occurs.

Returns:
The list of storables to be stored when the appropriate event occurs.

addStorable

public void addStorable(Storable s)
Adds a Storable for which the state will be stored when the appropriate event occurs..

Parameters:
s - - a Storable object..

removeStorable

public void removeStorable(Storable s)
Removes a Storable for which the state will be stored when the appropriate event occurs..

Parameters:
s - - the Storable object to removed from the list of objects

storeState

protected void storeState(int event)

getStoreDir

public File getStoreDir()

setStoreDir

public void setStoreDir(File dir)


Copyright © 2003-2008 Christian Hargraves. All Rights Reserved.