com.microsoft.tfs.core.memento
Class XMLMemento

java.lang.Object
  extended by com.microsoft.tfs.core.memento.XMLMemento
All Implemented Interfaces:
Memento

public class XMLMemento
extends java.lang.Object
implements Memento

XMLMemento is an implementation of Memento which serializes its data to/from XML streams. The default encoding for these streams is DEFAULT_ENCODING if null is specified for read(InputStream, String) or write(OutputStream, String).

Since:
TEE-SDK-10.1
Thread-safety:
thread-safe

Field Summary
static java.lang.String DEFAULT_ENCODING
          The encoding used for read(InputStream, String) and write(OutputStream, String) when null is specified for the encoding parameter.
 
Constructor Summary
XMLMemento(java.lang.String name)
          Creates an XMLMemento with the given name and an empty set of attributes and children.
 
Method Summary
 Memento createChild(java.lang.String name)
           Creates a new Memento with the given name and attaches it as a child to this Memento.
 java.util.Map getAllAttributes()
          Gets a map of attribute keys to values.
 Memento[] getAllChildren()
          Gets all the children.
 java.lang.Boolean getBoolean(java.lang.String key)
          Gets the Boolean value of the given key.
 Memento getChild(java.lang.String name)
          Returns a child with the given name.
 Memento[] getChildren(java.lang.String name)
          Returns all children with the given name.
 java.lang.Double getDouble(java.lang.String key)
          Gets the double floating point value of the given key.
 java.lang.Float getFloat(java.lang.String key)
          Gets the floating point value of the given key.
 java.lang.Integer getInteger(java.lang.String key)
          Gets the integer value of the given key.
 java.lang.Long getLong(java.lang.String key)
          Gets the long integer value of the given key.
 java.lang.String getName()
          
 java.lang.String getString(java.lang.String key)
          Gets the string value of the given key.
 java.lang.String getTextData()
          Gets the data from the special text area of the Memento.
 void putBoolean(java.lang.String key, boolean value)
          Sets the value of the given key to the given boolean value.
 void putDouble(java.lang.String key, double value)
          Sets the value of the given key to the given double floating point number.
 void putFloat(java.lang.String key, float value)
          Sets the value of the given key to the given floating point number.
 void putInteger(java.lang.String key, int value)
          Sets the value of the given key to the given integer.
 void putLong(java.lang.String key, long value)
          Sets the value of the given key to the given long integer.
 void putMemento(Memento memento)
          Copy the special text, attributes, and children from the given Memento into 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 special text area to contain the given data.
static XMLMemento read(java.io.InputStream inputStream, java.lang.String encoding)
          Reads an XMLMemento from the next XML element in the given given InputStream in the encoding specified as DEFAULT_ENCODING.
 boolean removeChild(Memento memento)
          Removes the given child.
 Memento[] removeChildren(java.lang.String name)
          Removes all children with the given name.
 void write(java.io.OutputStream outputStream, java.lang.String encoding)
          Writes this XMLMemento as an XML element (with child elements for child Mementos) to the specified OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
The encoding used for read(InputStream, String) and write(OutputStream, String) when null is specified for the encoding parameter.

Constant Field Value:
"UTF-8"
See Also:
Constant Field Values
Constructor Detail

XMLMemento

public XMLMemento(java.lang.String name)
Creates an XMLMemento with the given name and an empty set of attributes and children.

Parameters:
name - the name (must not be null or empty)
Method Detail

read

public static XMLMemento read(java.io.InputStream inputStream,
                              java.lang.String encoding)
                       throws MementoException
Reads an XMLMemento from the next XML element in the given given InputStream in the encoding specified as DEFAULT_ENCODING.

Parameters:
inputStream - the InputStream read to read the XMLMemento from (must not be null)
encoding - the encoding to use when reading the InputStream, null to use the default encoding ( DEFAULT_ENCODING)
Returns:
a Memento modeled as the first Element in the document.
Throws:
MementoException - if an error prevented the creation of the Memento.

write

public void write(java.io.OutputStream outputStream,
                  java.lang.String encoding)
           throws MementoException
Writes this XMLMemento as an XML element (with child elements for child Mementos) to the specified OutputStream.

Parameters:
outputStream - the output stream to write the document to
encoding - the encoding to use when writing the OutputStream, null to use the default encoding ( DEFAULT_ENCODING).
Throws:
MementoException - if there is a problem serializing the document to the stream.

getName

public java.lang.String getName()

Specified by:
getName in interface Memento
Returns:
this Memento's name (never null or empty)

createChild

public Memento createChild(java.lang.String name)

Creates a new Memento with the given name and attaches it as a child to this Memento. Child names do not have to be unique within a memento; multiple children with the same name are allowed.

Use the Memento.getChild(String) and Memento.getChildren(String) methods to retrieve children by name.

Specified by:
createChild in interface Memento
Parameters:
name - the name of the child Memento (must not be null or empty)
Returns:
the new child Memento created in this memento

getChild

public Memento getChild(java.lang.String name)
Returns a child with the given name. The order in which children are stored is not specified, so this method may return a child with the given name at any position in the child collection. To access multiple children with the same name, use Memento.getChildren(String).

Specified by:
getChild in interface Memento
Parameters:
name - the name of the child Memento to get (must not be null or empty)
Returns:
the first child with the given name

getChildren

public Memento[] getChildren(java.lang.String name)
Returns all children with the given name.

Specified by:
getChildren in interface Memento
Parameters:
name - the name of the child Mementos to get (must not be null or empty)
Returns:
an array of children with the given name, never null but may be empty

getAllChildren

public Memento[] getAllChildren()
Gets all the children.

Specified by:
getAllChildren in interface Memento
Returns:
an array of all children, never null but may be empty

removeChildren

public Memento[] removeChildren(java.lang.String name)
Removes all children with the given name.

Specified by:
removeChildren in interface Memento
Parameters:
name - the name of the children to remove (must not be null or empty)
Returns:
the children that were removed, never null but may be empty

removeChild

public boolean removeChild(Memento memento)
Removes the given child. The memento is matched to this memento's children by object equality.

Specified by:
removeChild in interface Memento
Parameters:
memento - the child to remove (must not be null)
Returns:
true if the memento was a child (and was removed), false if the memento was not a child

getAllAttributes

public java.util.Map getAllAttributes()
Gets a map of attribute keys to values. All keys and values are Strings.

Specified by:
getAllAttributes in interface Memento
Returns:
the Map of attribute String keys to String values (never null)

getDouble

public java.lang.Double getDouble(java.lang.String key)
Gets the double floating point value of the given key.

Specified by:
getDouble 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

getFloat

public java.lang.Float getFloat(java.lang.String key)
Gets 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

getInteger

public java.lang.Integer getInteger(java.lang.String key)
Gets 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

getLong

public java.lang.Long getLong(java.lang.String key)
Gets the long integer value of the given key.

Specified by:
getLong 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)
Gets 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

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key)
Gets 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

getTextData

public java.lang.String getTextData()
Gets the data from the special text area of the Memento. Each Memento is allowed only one special text area.

Specified by:
getTextData in interface Memento
Returns:
the contents of the special text area of the Memento, or null if the Memento has no text.

putDouble

public void putDouble(java.lang.String key,
                      double value)
Sets the value of the given key to the given double floating point number.

Specified by:
putDouble in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value

putFloat

public void putFloat(java.lang.String key,
                     float value)
Sets the value of the given key to the given floating point number.

Specified by:
putFloat in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value

putInteger

public void putInteger(java.lang.String key,
                       int value)
Sets the value of the given key to the given integer.

Specified by:
putInteger in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value (may be null or empty)

putLong

public void putLong(java.lang.String key,
                    long value)
Sets the value of the given key to the given long integer.

Specified by:
putLong in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value (may be null or empty)

putString

public void putString(java.lang.String key,
                      java.lang.String value)
Sets the value of the given key to the given string.

Specified by:
putString in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value (may be null or empty)

putBoolean

public void putBoolean(java.lang.String key,
                       boolean value)
Sets the value of the given key to the given boolean value.

Specified by:
putBoolean in interface Memento
Parameters:
key - the key (must not be null or empty)
value - the value (may be null or empty)

putTextData

public void putTextData(java.lang.String data)
Sets the Memento's special text area to contain the given data. If a special text value was previously set, it is replaced with the given text. Each memento is allowed only one special text value.

Specified by:
putTextData in interface Memento
Parameters:
data - the text to be placed into the special text area (may be null or empty)

putMemento

public void putMemento(Memento memento)
Copy the special text, attributes, and children from the given Memento into the receiver. The name of the receiver Memento is not changed.

Specified by:
putMemento in interface Memento
Parameters:
memento - the Memento to be copied (must not be null)


© 2015 Microsoft. All rights reserved.