com.partnersoft.io.vfs
Class UndoableVfs

java.lang.Object
  extended by com.partnersoft.io.vfs.UndoableVfs
All Implemented Interfaces:
Vfs

public class UndoableVfs
extends java.lang.Object
implements Vfs

A wrapper around an editable VFS that allows transactional undo.

To use, you must start a transaction using startTransaction(), then end it with endTransaction(). The latter returns an Undoable you can store.

The implementation is based on storing changes in a subdirectory of the VFS. This allows efficient moves and copies. By default this subdirectory is archive/vfs.

Copyright 2009 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis

Constructor Summary
UndoableVfs(Vfs vfs)
           
UndoableVfs(Vfs vfs, Path archivePath)
           
UndoableVfs(Vfs vfs, java.lang.String archivePath)
           
 
Method Summary
 void clearTransactions()
           
 VfsDirectory directoryFor(Path path)
          Returns a VfsDirectory for the given path.
 VfsDirectory directoryFor(java.lang.String pathString)
          Returns a VfsDirectory for the given path.
 java.lang.String endTransaction()
          Ends a file modification transaction.
 VfsFile fileFor(Path path)
          Returns a VfsFile for the given path.
 VfsFile fileFor(java.lang.String pathString)
          Returns a VfsFile for the given path string.
 Path getAbsolutePath()
          Absolute path to the root of this Vfs.
 boolean inTransaction()
           
 boolean isTransactionNode(VfsNode node)
           
 boolean isWritable()
          True if this module supports writing.
 java.util.List<java.lang.String> listRedoTransactions()
          Lists the available transaction names in the redo queue, ordered from oldest to newest by original transaction time.
 java.util.List<java.lang.String> listUndoTransactions()
          Lists the available transaction names in the undo queue, ordered from newest to oldest by original transaction time.
 void redo()
           
 void redo(java.lang.String transactionName)
          Redoes the named transaction.
 java.lang.String startTransaction()
          Starts a file modification transaction.
 void undo()
           
 void undo(java.lang.String transactionName)
          Undoes the named transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UndoableVfs

public UndoableVfs(Vfs vfs)

UndoableVfs

public UndoableVfs(Vfs vfs,
                   Path archivePath)

UndoableVfs

public UndoableVfs(Vfs vfs,
                   java.lang.String archivePath)
Method Detail

isTransactionNode

public boolean isTransactionNode(VfsNode node)

inTransaction

public boolean inTransaction()

startTransaction

public java.lang.String startTransaction()
                                  throws java.io.IOException
Starts a file modification transaction. Returns a unique name that can be used later to revert the modifications. Will fail if you call this while a transaction is already in progress. Note that starting a new transaction clears the redo queue.

Throws:
java.io.IOException

endTransaction

public java.lang.String endTransaction()
                                throws java.io.IOException
Ends a file modification transaction. Returns a unique name that can be used later to revert the modifications. Will fail if a transaction is not already in progress.

Throws:
java.io.IOException

listUndoTransactions

public java.util.List<java.lang.String> listUndoTransactions()
                                                      throws java.io.IOException
Lists the available transaction names in the undo queue, ordered from newest to oldest by original transaction time.

Throws:
java.io.IOException

listRedoTransactions

public java.util.List<java.lang.String> listRedoTransactions()
                                                      throws java.io.IOException
Lists the available transaction names in the redo queue, ordered from oldest to newest by original transaction time.

Throws:
java.io.IOException

undo

public void undo(java.lang.String transactionName)
          throws java.io.IOException
Undoes the named transaction. It has to be in the undo queue; after undo it will be in the redo queue.

Throws:
java.io.IOException

redo

public void redo(java.lang.String transactionName)
          throws java.io.IOException
Redoes the named transaction. It has to be in the redo queue, and afterwards it will be in the undo queue again.

Throws:
java.io.IOException

redo

public void redo()
          throws java.io.IOException
Throws:
java.io.IOException

undo

public void undo()
          throws java.io.IOException
Throws:
java.io.IOException

clearTransactions

public void clearTransactions()
                       throws java.io.IOException
Throws:
java.io.IOException

directoryFor

public VfsDirectory directoryFor(Path path)
Description copied from interface: Vfs
Returns a VfsDirectory for the given path. Note that this does not imply that the underlying file actually exists. You may use the methods provided by the VfsDirectory to list and modify the directory's contents.

Specified by:
directoryFor in interface Vfs
Parameters:
path - to directory
Returns:
directory for given path

directoryFor

public VfsDirectory directoryFor(java.lang.String pathString)
Description copied from interface: Vfs
Returns a VfsDirectory for the given path. This is the same as directoryFor(new Path(pathString).

Specified by:
directoryFor in interface Vfs
Parameters:
pathString - string-encoded path to directory
Returns:
directory for given path

fileFor

public VfsFile fileFor(Path path)
Description copied from interface: Vfs
Returns a VfsFile for the given path. Note that this does not imply that the underlying file actually exists. You may use the methods provided by the VfsFile to read and write the file's contents.

Specified by:
fileFor in interface Vfs
Parameters:
path - to file
Returns:
file for given path

fileFor

public VfsFile fileFor(java.lang.String pathString)
Description copied from interface: Vfs
Returns a VfsFile for the given path string. This is the same as fileFor(new Path(pathString).

Specified by:
fileFor in interface Vfs
Parameters:
pathString - string-encoded path to file
Returns:
file for given path

getAbsolutePath

public Path getAbsolutePath()
Description copied from interface: Vfs
Absolute path to the root of this Vfs. Meaning depends on type of Vfs.

Specified by:
getAbsolutePath in interface Vfs

isWritable

public boolean isWritable()
Description copied from interface: Vfs
True if this module supports writing.

Specified by:
isWritable in interface Vfs
Returns:
true if module is writable