Package org.eclipse.ui
Class XMLMemento
java.lang.Object
org.eclipse.ui.XMLMemento
- All Implemented Interfaces:
IMemento
This class represents the default implementation of the
IMemento
interface.
This class is not intended to be extended by clients.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionXMLMemento
(Document document, Element element) Creates a memento for the specified document and element. -
Method Summary
Modifier and TypeMethodDescriptionCreate a copy of the child node and append it to this node.createChild
(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.static XMLMemento
createReadRoot
(Reader reader) Creates aDocument
from theReader
and returns a memento on the firstElement
for reading the document.static XMLMemento
createReadRoot
(Reader reader, String baseDir) Creates aDocument
from theReader
and returns a memento on the firstElement
for reading the document.static XMLMemento
createWriteRoot
(String type) Returns a root memento for writing a document.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 n) 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.void
Saves this memento's document current values to the specified writer.toString()
-
Constructor Details
-
XMLMemento
Creates a memento for the specified document and element.Clients should use
createReadRoot
andcreateWriteRoot
to create the initial memento on a document.- Parameters:
document
- the document for the mementoelement
- the element node for the memento
-
-
Method Details
-
createReadRoot
Creates aDocument
from theReader
and returns a memento on the firstElement
for reading the document.Same as calling createReadRoot(reader, null)
- Parameters:
reader
- theReader
used to create the memento's document- Returns:
- a memento on the first
Element
for reading the document - Throws:
WorkbenchException
- if IO problems, invalid format, or no element.
-
createReadRoot
Creates aDocument
from theReader
and returns a memento on the firstElement
for reading the document.- Parameters:
reader
- theReader
used to create the memento's documentbaseDir
- the directory used to resolve relative file names in the XML document. This directory must exist and include the trailing separator. The directory format, including the separators, must be valid for the platform. Can benull
if not needed.- Returns:
- a memento on the first
Element
for reading the document - Throws:
WorkbenchException
- if IO problems, invalid format, or no element.
-
createWriteRoot
Returns a root memento for writing a document.- Parameters:
type
- the element node type to create on the document- Returns:
- the root memento for writing a document
- Throws:
DOMException
- when the element could not be created for the passed type
-
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.- Specified by:
createChild
in interfaceIMemento
- Parameters:
type
- the type- Returns:
- a new child memento
- Throws:
DOMException
- if the child cannot be created- 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.- Specified by:
createChild
in interfaceIMemento
- Parameters:
type
- the typeid
- the child id- Returns:
- a new child memento with the given type and id
- Throws:
DOMException
- if the child cannot be created- See Also:
-
copyChild
Create a copy of the child node and append it to this node.- Parameters:
child
- the child to copy- Returns:
- An IMenento for the new child node.
- Throws:
DOMException
- if the child cannot be created
-
getChild
Description copied from interface:IMemento
Returns the first child with the given type id. -
getChildren
Description copied from interface:IMemento
Returns all children of this node.- Specified by:
getChildren
in interfaceIMemento
- 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.
-
getChildren
Description copied from interface:IMemento
Returns all children with the given type id.- Specified by:
getChildren
in interfaceIMemento
- 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
Description copied from interface:IMemento
Returns the floating point value of the given key. -
getType
Description copied from interface:IMemento
Returns the type for this memento. -
getID
Description copied from interface:IMemento
Returns the id for this memento. -
getInteger
Description copied from interface:IMemento
Returns the integer value of the given key.- Specified by:
getInteger
in interfaceIMemento
- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found or was found but was not an integer
-
getString
Description copied from interface:IMemento
Returns the string value of the given key. -
getBoolean
Description copied from interface:IMemento
Returns the boolean value of the given key.- Specified by:
getBoolean
in interfaceIMemento
- Parameters:
key
- the key- Returns:
- the value, or
null
if the key was not found - Since:
- 3.4
-
getTextData
Returns the data of the Text node of the memento. Each memento is allowed only one Text node.- Specified by:
getTextData
in interfaceIMemento
- Returns:
- the data of the Text node of the memento, or
null
if the memento has no Text node. - Throws:
DOMException
- if the text node is too big- Since:
- 2.0
-
getAttributeKeys
Description copied from interface:IMemento
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.- Specified by:
getAttributeKeys
in interfaceIMemento
- 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.- Specified by:
putFloat
in interfaceIMemento
- Parameters:
key
- the keyf
- the value- Throws:
DOMException
- if the attribute cannot be set
-
putInteger
Sets the value of the given key to the given integer.- Specified by:
putInteger
in interfaceIMemento
- Parameters:
key
- the keyn
- the value- Throws:
DOMException
- if the attribute cannot be set
-
putMemento
Copy the attributes and children frommemento
to the receiver.- Specified by:
putMemento
in interfaceIMemento
- Parameters:
memento
- the IMemento to be copied.- Throws:
DOMException
- if the attributes or children cannot be copied to this node.
-
putString
Sets the value of the given key to the given string.- Specified by:
putString
in interfaceIMemento
- Parameters:
key
- the keyvalue
- the value- Throws:
DOMException
- if the attribute cannot be set
-
putBoolean
Sets the value of the given key to the given boolean value.- Specified by:
putBoolean
in interfaceIMemento
- Parameters:
key
- the keyvalue
- the value- Throws:
DOMException
- if the attribute cannot be set- 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.- Specified by:
putTextData
in interfaceIMemento
- Parameters:
data
- the data to be placed on the Text node- Throws:
DOMException
- if the text node cannot be created under this node.- Since:
- 2.0
-
save
Saves this memento's document current values to the specified writer.- Parameters:
writer
- the writer used to save the memento's document- Throws:
IOException
- if there is a problem serializing the document to the stream.
-
toString
-