javolution.context
Class PersistentContext

Object
  extended by Context
      extended by PersistentContext
All Implemented Interfaces:
Serializable, XMLSerializable

public class PersistentContext
extends Context

This class represents a context persistent accross multiple program executions. It is typically used to hold persistent references.

How this context is loaded/saved is application specific. Although, the simplest way is to use Javolution XML serialization facility. For example:

      import javolution.xml.XMLObjectReader;
      import javolution.xml.XMLObjectWriter;
      public void main(String[]) {
           // Loads persistent context (typically at start-up).
           XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream("C:/persistent.xml"));
           PersistentContext.setCurrentPersistentContext(reader.read());
           reader.close();
           ...
           ...
           // Saves persistent context for future execution.
           XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream("C:/persistent.xml"));
           writer.write(PersistentContext.getCurrentPersistentContext());
           writer.close();
      }

Version:
4.2, December 31, 2006
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Nested Class Summary
static class PersistentContext.Reference<T>
           This class represents a reference over an object which can be kept persistent accross multiple program executions.
 
Field Summary
 
Fields inherited from class Context
ROOT
 
Constructor Summary
PersistentContext()
          Default constructor.
 
Method Summary
protected  void enterAction()
          Throws UnsupportedOperationException persistent context are global to all threads (singleton).
protected  void exitAction()
          Throws UnsupportedOperationException persistent context are global to all threads (singleton).
static PersistentContext getCurrentPersistentContext()
          Returns the persistent context instance (singleton).
 Map<String,Object> getIdToValue()
          Returns the ID to value mapping for this persistent context.
static void setCurrentPersistentContext(PersistentContext ctx)
          Sets the persistent instance.
 
Methods inherited from class Context
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistentContext

public PersistentContext()
Default constructor.

Method Detail

setCurrentPersistentContext

public static void setCurrentPersistentContext(PersistentContext ctx)
Sets the persistent instance.

Parameters:
ctx - the persistent instance.

getCurrentPersistentContext

public static PersistentContext getCurrentPersistentContext()
Returns the persistent context instance (singleton).

Returns:
the persistent context instance.

getIdToValue

public Map<String,Object> getIdToValue()
Returns the ID to value mapping for this persistent context.

Returns:
the persistent value indexed by identifiers.

enterAction

protected void enterAction()
Throws UnsupportedOperationException persistent context are global to all threads (singleton).

Specified by:
enterAction in class Context

exitAction

protected void exitAction()
Throws UnsupportedOperationException persistent context are global to all threads (singleton).

Specified by:
exitAction in class Context


Copyright © 2005-2012 Javolution. All Rights Reserved.