Nuxeo Enterprise Platform 5.4

org.nuxeo.common.persistence
Class XMLMemento

java.lang.Object
  extended by org.nuxeo.common.persistence.XMLMemento
All Implemented Interfaces:
Memento

public final class XMLMemento
extends java.lang.Object
implements Memento

Implementation of the Memento interface.

This class is not intended to be extended by clients.

See Also:
Memento

Field Summary
 
Fields inherited from interface org.nuxeo.common.persistence.Memento
TAG_ID
 
Constructor Summary
XMLMemento(org.w3c.dom.Document document, org.w3c.dom.Element element)
          Creates a memento for the specified document and element.
 
Method Summary
 Memento copyChild(Memento child)
           
 Memento createChild(java.lang.String type)
          Creates a new child of this memento with the given type.
 Memento createChild(java.lang.String type, java.lang.String id)
          Creates a new child of this memento with the given type and id.
static XMLMemento createReadRoot(java.io.Reader reader)
          Creates a Document from the Reader and returns a memento on the first Element for reading the document.
static XMLMemento createReadRoot(java.io.Reader reader, java.lang.String baseDir)
          Creates a Document from the Reader and returns a memento on the first Element for reading the document.
static XMLMemento createWriteRoot(java.lang.String type)
          Returns a root memento for writing a document.
 java.lang.Boolean getBoolean(java.lang.String key)
          Returns the boolean value of the given key.
 Memento getChild(java.lang.String type)
          Returns the first child with the given type id.
 Memento[] getChildren(java.lang.String type)
          Returns all children with the given type id.
 java.lang.Float getFloat(java.lang.String key)
          Returns the floating point value of the given key.
 java.lang.String getID()
          Returns the id for this memento.
 java.lang.Integer getInteger(java.lang.String key)
          Returns the integer value of the given key.
 java.lang.String getString(java.lang.String key)
          Returns the string value of the given key.
 java.lang.String getTextData()
          Returns the data of the Text node of the memento.
 void putBoolean(java.lang.String key, boolean value)
          Sets the value of the given key to the given boolean.
 void putFloat(java.lang.String key, float f)
          Sets the value of the given key to the given floating point number.
 void putInteger(java.lang.String key, int n)
          Sets the value of the given key to the given integer.
 void putMemento(Memento memento)
          Copy the attributes and children from memento to the receiver.
 void putString(java.lang.String key, java.lang.String value)
          Sets the value of the given key to the given string.
 void putTextData(java.lang.String data)
          Sets the memento's Text node to contain the given data.
 void save(java.io.Writer writer)
          Saves this memento's document current values to the specified writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLMemento

public XMLMemento(org.w3c.dom.Document document,
                  org.w3c.dom.Element element)
Creates a memento for the specified document and element.

Clients should use createReadRoot and createWriteRoot to create the initial memento on a document.

Parameters:
document - the document for the memento
element - the element node for the memento
Method Detail

createReadRoot

public static XMLMemento createReadRoot(java.io.Reader reader)
                                 throws java.lang.Exception
Creates a Document from the Reader and returns a memento on the first Element for reading the document.

Same as calling createReadRoot(reader, null).

Parameters:
reader - the Reader used to create the memento's document
Returns:
a memento on the first Element for reading the document
Throws:
java.lang.Exception - if IO problems, invalid format, or no element.

createReadRoot

public static XMLMemento createReadRoot(java.io.Reader reader,
                                        java.lang.String baseDir)
                                 throws java.lang.Exception
Creates a Document from the Reader and returns a memento on the first Element for reading the document.

Parameters:
reader - the Reader used to create the memento's document
baseDir - 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 be null if not needed.
Returns:
a memento on the first Element for reading the document
Throws:
java.lang.Exception - if IO problems, invalid format, or no element.

createWriteRoot

public static XMLMemento createWriteRoot(java.lang.String type)
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

createChild

public Memento createChild(java.lang.String type)
Description copied from interface: Memento
Creates a new child of this memento with the given type.

The getChild and getChildren methods are used to retrieve children of a given type.

Specified by:
createChild in interface Memento
Parameters:
type - the type
Returns:
a new child memento
See Also:
Memento.getChild(java.lang.String), Memento.getChildren(java.lang.String)

createChild

public Memento createChild(java.lang.String type,
                           java.lang.String id)
Description copied from interface: Memento
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 using getId.

The getChild and getChildren methods are used to retrieve children of a given type.

Specified by:
createChild in interface Memento
Parameters:
type - the type
id - the child id
Returns:
a new child memento with the given type and id
See Also:
Memento.getID()

copyChild

public Memento copyChild(Memento child)

getChild

public Memento getChild(java.lang.String type)
Description copied from interface: Memento
Returns the first child with the given type id.

Specified by:
getChild in interface Memento
Parameters:
type - the type id
Returns:
the first child with the given type

getChildren

public Memento[] getChildren(java.lang.String type)
Description copied from interface: Memento
Returns all children with the given type id.

Specified by:
getChildren in interface Memento
Parameters:
type - the type id
Returns:
an array of children with the given type

getFloat

public java.lang.Float getFloat(java.lang.String key)
Description copied from interface: Memento
Returns the floating point value of the given key.

Specified by:
getFloat in interface Memento
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

getID

public java.lang.String getID()
Description copied from interface: Memento
Returns the id for this memento.

Specified by:
getID in interface Memento
Returns:
the memento id, or null if none
See Also:
Memento.createChild(String, String)

getInteger

public java.lang.Integer getInteger(java.lang.String key)
Description copied from interface: Memento
Returns the integer value of the given key.

Specified by:
getInteger in interface Memento
Parameters:
key - the key
Returns:
the value, or null if the key was not found or was found but was not an integer

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key)
Description copied from interface: Memento
Returns the boolean value of the given key.

Specified by:
getBoolean in interface Memento
Parameters:
key - the key
Returns:
the value, or null if the key was not found or was found but was not an integer

getString

public java.lang.String getString(java.lang.String key)
Description copied from interface: Memento
Returns the string value of the given key.

Specified by:
getString in interface Memento
Parameters:
key - the key
Returns:
the value, or null if the key was not found

getTextData

public java.lang.String getTextData()
Description copied from interface: Memento
Returns the data of the Text node of the memento. Each memento is allowed only one Text node.

Specified by:
getTextData in interface Memento
Returns:
the data of the Text node of the memento, or null if the memento has no Text node.

putFloat

public void putFloat(java.lang.String key,
                     float f)
Description copied from interface: Memento
Sets the value of the given key to the given floating point number.

Specified by:
putFloat in interface Memento
Parameters:
key - the key
f - the value

putInteger

public void putInteger(java.lang.String key,
                       int n)
Description copied from interface: Memento
Sets the value of the given key to the given integer.

Specified by:
putInteger in interface Memento
Parameters:
key - the key
n - the value

putBoolean

public void putBoolean(java.lang.String key,
                       boolean value)
Description copied from interface: Memento
Sets the value of the given key to the given boolean.

Specified by:
putBoolean in interface Memento
Parameters:
key - the key
value - the value

putMemento

public void putMemento(Memento memento)
Description copied from interface: Memento
Copy the attributes and children from memento to the receiver.

Specified by:
putMemento in interface Memento
Parameters:
memento - the Memento to be copied.

putString

public void putString(java.lang.String key,
                      java.lang.String value)
Description copied from interface: Memento
Sets the value of the given key to the given string.

Specified by:
putString in interface Memento
Parameters:
key - the key
value - the value

putTextData

public void putTextData(java.lang.String data)
Description copied from interface: Memento
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 interface Memento
Parameters:
data - the data to be placed on the Text node

save

public void save(java.io.Writer writer)
Saves this memento's document current values to the specified writer.

Parameters:
writer - the writer used to save the memento's document

Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.