com.thoughtworks.xstream.persistence
Class FilePersistenceStrategy

java.lang.Object
  extended by com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
      extended by com.thoughtworks.xstream.persistence.FilePersistenceStrategy
All Implemented Interfaces:
PersistenceStrategy

public class FilePersistenceStrategy
extends AbstractFilePersistenceStrategy

PersistenceStrategy to assign keys with single value to objects persisted in files. The default naming strategy is based on the key's type and its SingleValueConverter. It escapes all characters that are normally illegal in the most common file systems. Such a character is escaped with percent escaping as it is done by URL encoding. The XStream used to marshal the values is also requested for the key's SingleValueConverter. A StreamException is thrown if no such converter is registered.

Since:
1.3.1
Author:
Jörg Schaible, Guilherme Silveira

Nested Class Summary
 
Nested classes/interfaces inherited from class com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
AbstractFilePersistenceStrategy.ValidFilenameFilter, AbstractFilePersistenceStrategy.XmlMapEntriesIterator
 
Constructor Summary
FilePersistenceStrategy(java.io.File baseDirectory)
          Create a new FilePersistenceStrategy.
FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream)
          Create a new FilePersistenceStrategy with a provided XStream instance.
FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream, java.lang.String encoding, java.lang.String illegalChars)
          Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.
 
Method Summary
protected  java.lang.String escape(java.lang.String key)
           
protected  java.lang.Object extractKey(java.lang.String name)
          Given a filename, the unescape method returns the key which originated it.
protected  java.lang.String getName(java.lang.Object key)
          Given a key, the escape method returns the filename which shall be used.
protected  boolean isValid(java.io.File dir, java.lang.String name)
           
protected  java.lang.String unescape(java.lang.String name)
           
 
Methods inherited from class com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
containsKey, get, getConverterLookup, getMapper, iterator, put, remove, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilePersistenceStrategy

public FilePersistenceStrategy(java.io.File baseDirectory)
Create a new FilePersistenceStrategy. Use a standard XStream instance with a DomDriver.

Parameters:
baseDirectory - the directory for the serialized values
Since:
1.3.1

FilePersistenceStrategy

public FilePersistenceStrategy(java.io.File baseDirectory,
                               XStream xstream)
Create a new FilePersistenceStrategy with a provided XStream instance.

Parameters:
baseDirectory - the directory for the serialized values
xstream - the XStream instance to use for (de)serialization
Since:
1.3.1

FilePersistenceStrategy

public FilePersistenceStrategy(java.io.File baseDirectory,
                               XStream xstream,
                               java.lang.String encoding,
                               java.lang.String illegalChars)
Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.

Parameters:
baseDirectory - the directory for the serialized values
xstream - the XStream instance to use for (de)serialization
encoding - encoding used to write the files
illegalChars - illegal characters for file names (should always include '%' as long as you do not overwrite the (un)escape methods)
Since:
1.3.1
Method Detail

isValid

protected boolean isValid(java.io.File dir,
                          java.lang.String name)
Overrides:
isValid in class AbstractFilePersistenceStrategy

extractKey

protected java.lang.Object extractKey(java.lang.String name)
Given a filename, the unescape method returns the key which originated it.

Specified by:
extractKey in class AbstractFilePersistenceStrategy
Parameters:
name - the filename
Returns:
the original key

unescape

protected java.lang.String unescape(java.lang.String name)

getName

protected java.lang.String getName(java.lang.Object key)
Given a key, the escape method returns the filename which shall be used.

Specified by:
getName in class AbstractFilePersistenceStrategy
Parameters:
key - the key
Returns:
the desired and escaped filename

escape

protected java.lang.String escape(java.lang.String key)


Copyright © 2004-2011 XStream. All Rights Reserved.