Interface IMemento
- All Known Implementing Classes:
XMLMemento
Mementos were designed with the following requirements in mind:
- Certain objects need to be saved and restored across platform sessions.
- When an object is restored, an appropriate class for an object might not be available. It must be possible to skip an object in this case.
- When an object is restored, the appropriate class for the object may be different from the one when the object was originally saved. If so, the new class should still be able to read the old form of the data.
Mementos meet these requirements by providing support for storing a mapping of arbitrary string keys to primitive values, and by allowing mementos to have other mementos as children (arranged into a tree). A robust external storage format based on XML is used.
The key for an attribute may be any alpha numeric value that doesn't start
with a number. eg: [A-Za-z][A-Za-z0-9]* Using '.' is unsupported. However,
the value of TAG_ID
is reserved for internal use.
The default implementation can throw a DOMException
for createChild
and put operations. See XMLMemento
.
This interface is not intended to be implemented or extended by clients.
- See Also:
- Restriction:
- This interface is not intended to be implemented by clients.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateChild
(String type) Creates a new child of this memento with the given type.createChild
(String type, String id) Creates a new child of this memento with the given type and id.String[]
Returns an array of all the attribute keys of the memento.getBoolean
(String key) Returns the boolean value of the given key.Returns the first child with the given type id.IMemento[]
Returns all children of this node.IMemento[]
getChildren
(String type) Returns all children with the given type id.Returns the floating point value of the given key.getID()
Returns the id for this memento.getInteger
(String key) Returns the integer value of the given key.Returns the string value of the given key.Returns the data of the Text node of the memento.getType()
Returns the type for this memento.void
putBoolean
(String key, boolean value) Sets the value of the given key to the given boolean value.void
Sets the value of the given key to the given floating point number.void
putInteger
(String key, int value) Sets the value of the given key to the given integer.void
putMemento
(IMemento memento) Copy the attributes and children frommemento
to the receiver.void
Sets the value of the given key to the given string.void
putTextData
(String data) Sets the memento's Text node to contain the given data.
-
Field Details
-
TAG_ID
Special reserved key used to store the memento id (value"IMemento.internal.id"
).- See Also:
-
-
Method Details
-
createChild
Creates a new child of this memento with the given type.The
getChild
andgetChildren
methods are used to retrieve children of a given type.- Parameters:
type
- the type- Returns:
- a new child memento
- See Also:
-
createChild
Creates a new child of this memento with the given type and id. The id is stored in the child memento (using a special reserved key,TAG_ID
) and can be retrieved usinggetId
.The
getChild
andgetChildren
methods are used to retrieve children of a given type.- Parameters:
type
- the typeid
- the child id- Returns:
- a new child memento with the given type and id
- See Also:
-
getChild
Returns the first child with the given type id.- Parameters:
type
- the type id- Returns:
- the first child with the given type. May return
null
.
-
getChildren
IMemento[] getChildren()Returns all children of this node.- Returns:
- an array of children of this node. This will not be
null
. If there are no children, an array of length zero will be returned. - Since:
- 3.8
-
getChildren
Returns all children with the given type id.- Parameters:
type
- the type id- Returns:
- an array of children with the given type. This will not be
null
. If there are no keys, an array of length zero will be returned.
-
getFloat
Returns the floating point value of the given key.- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found or was found but was not a floating point number
-
getType
String getType()Returns the type for this memento.- Returns:
- the memento type
- Since:
- 3.4
- See Also:
-
getID
String getID()Returns the id for this memento.- Returns:
- the memento id, or
null
if none - See Also:
-
getInteger
Returns the integer value of the given key.- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found or was found but was not an integer
-
getString
Returns the string value of the given key.- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found
-
getBoolean
Returns the boolean value of the given key.- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found - Since:
- 3.4
-
getTextData
String getTextData()Returns the data of the Text node of the memento. Each memento is allowed only one Text node.- Returns:
- the data of the Text node of the memento, or
null
if the memento has no Text node. - Since:
- 2.0
-
getAttributeKeys
String[] getAttributeKeys()Returns an array of all the attribute keys of the memento. This will not benull
. If there are no keys, an array of length zero will be returned.- Returns:
- an array with all the attribute keys of the memento
- Since:
- 3.4
-
putFloat
Sets the value of the given key to the given floating point number.- Parameters:
key
- the keyvalue
- the value
-
putInteger
Sets the value of the given key to the given integer.- Parameters:
key
- the keyvalue
- the value
-
putMemento
Copy the attributes and children frommemento
to the receiver.- Parameters:
memento
- the IMemento to be copied.
-
putString
Sets the value of the given key to the given string.- Parameters:
key
- the keyvalue
- the value
-
putBoolean
Sets the value of the given key to the given boolean value.- Parameters:
key
- the keyvalue
- the value- Since:
- 3.4
-
putTextData
Sets the memento's Text node to contain the given data. Creates the Text node if none exists. If a Text node does exist, it's current contents are replaced. Each memento is allowed only one text node.- Parameters:
data
- the data to be placed on the Text node- Since:
- 2.0
-