public final class ContextKeyStore extends Observable implements IDatasource
ContextKeyStore
is used to store and access objects in the
application context. Each object is identified by a String key. Use
store()
to make the current state persistent across new start of the
application. The latest state is automatically restored when accessed the
first time.
This class is not meant to be extended.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the ContextKeyStore and removes all objects and keys.
|
static java.lang.Object |
get(java.lang.String key)
Registers a new key value pair.
|
java.lang.Object |
getExpressionValue(java.lang.String rootExpression)
This method is used to retrieve an object from the data model using an
expression.
An expression can be any String an IDatasource implementation
uses to reference an object. |
static ContextKeyStore |
getInstance()
Get the shared instance of ContextKeyStore.
|
static boolean |
remove(java.lang.String key)
Removes the value for passed
key . |
static java.lang.String |
resolve(java.lang.String text)
Replaces tokens identified by {, } (mainly context keys) with the
correspond values.
|
boolean |
restore()
Loads all the keys and it's values stored with
store() and restores
the state of the context to the state when it was last saved. |
static void |
set(java.lang.String key,
java.lang.Object value)
Sets the
value for a specific key . |
static void |
setDefaultValues(java.util.Hashtable d)
Sets the default values to be used if no value has been set for a key.
|
void |
setExpressionValue(java.lang.String rootExpression,
java.lang.Object value)
This method is used to update an object in the data model.
An expression can be any String an IDatasource implementation
uses to reference an object. |
void |
store()
Saves all keys and it's values into a persistent RecordStore.
|
addObserver, deleteObserver, notifyObservers, notifyObservers
public static ContextKeyStore getInstance()
public java.lang.Object getExpressionValue(java.lang.String rootExpression) throws java.lang.Exception
IDatasource
IDatasource
implementation
uses to reference an object.getExpressionValue
in interface IDatasource
rootExpression
- String that references an object in the data modelnull
if there was
no objectjava.lang.Exception
- if an error occured evaluating the given expressionpublic void setExpressionValue(java.lang.String rootExpression, java.lang.Object value) throws java.lang.Exception
IDatasource
IDatasource
implementation
uses to reference an object.setExpressionValue
in interface IDatasource
rootExpression
- String that references an object in the data modelvalue
- new object value for the given expressionjava.lang.Exception
- if an error occured evaluating the given expressionpublic static void setDefaultValues(java.util.Hashtable d)
d
- a Hashtable with key and values used as default valuespublic boolean restore()
store()
and restores
the state of the context to the state when it was last saved. After the
restore, only the keys from the store will be available in the context. If
you call restore()
all changes since the last call of
store()
will be lost!
Currently only Integer, Boolean and String value types are supported.
public void store()
restore()
to load the data, even after restart of the application.
Currently only Integer, Boolean and String value types are supported. All other keys and it's values will not be stored!
public void clear()
public static void set(java.lang.String key, java.lang.Object value)
value
for a specific key
. Both,
key
and value
, must not be null.key
- value
- public static java.lang.Object get(java.lang.String key)
key
- the key to identify the valuepublic static boolean remove(java.lang.String key)
key
.key
- the key to identify the valuepublic static java.lang.String resolve(java.lang.String text)
text
- the text value which needs to be resolved