au.com.prunge.jgenfile.impl.local
Class LocalDeleteItemOperation

java.lang.Object
  |
  +--au.com.prunge.jgenfile.impl.AbstractOperation
        |
        +--au.com.prunge.jgenfile.impl.AbstractItemOperation
              |
              +--au.com.prunge.jgenfile.impl.local.LocalDeleteItemOperation
All Implemented Interfaces:
DeleteItemOperation, ItemOperation, Operation, ProgressObservable

public class LocalDeleteItemOperation
extends AbstractItemOperation
implements DeleteItemOperation, ProgressObservable

An operation that deletes an item on the local file system.

Version:
1.0
Author:
Peter Runge

Constructor Summary
LocalDeleteItemOperation(LocalItem item)
          Constructs a LocalDeleteItemOperation.
 
Method Summary
 void abort()
          Aborts the operation if it is currently running.
 int getDeletedFilesCount()
          Returns the number of files that were deleted by this operation.
 float getProgress()
          Returns the progress of this operation.
protected  void recursiveDelete(File file, Set nonDeletedReferenceSet)
          Recursively deletes all children of this file and then the file itself.
 void runImpl()
          The actual run() implementation goes in this method.
 
Methods inherited from class au.com.prunge.jgenfile.impl.AbstractItemOperation
getItem
 
Methods inherited from class au.com.prunge.jgenfile.impl.AbstractOperation
addOperationHints, checkRun, getLastRunException, getOperationHint, getOperationHints, hasRun, run, setLastRunException, setOperationHint, setOperationHints
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface au.com.prunge.jgenfile.DeleteItemOperation
run
 
Methods inherited from interface au.com.prunge.jgenfile.ItemOperation
getItem
 
Methods inherited from interface au.com.prunge.jgenfile.Operation
addOperationHints, getLastRunException, getOperationHint, getOperationHints, hasRun, setOperationHint, setOperationHints
 

Constructor Detail

LocalDeleteItemOperation

public LocalDeleteItemOperation(LocalItem item)
Constructs a LocalDeleteItemOperation.

Parameters:
item - the item to delete.
Method Detail

getDeletedFilesCount

public int getDeletedFilesCount()
                         throws OperationNotFinishedException,
                                JGenFileException
Description copied from interface: DeleteItemOperation
Returns the number of files that were deleted by this operation. If the number of deleted files is unknown, -1 should be returned.

This number is only useful if the item that was deleted was a directory and contained other items.

Specified by:
getDeletedFilesCount in interface DeleteItemOperation
Throws:
JGenFileException - if another error occurs.
OperationNotFinishedException - if this method was called and the run() method has not finished or has not been called.
See Also:
DeleteItemOperation.getDeletedFilesCount()

getProgress

public float getProgress()
Returns the progress of this operation.

Specified by:
getProgress in interface ProgressObservable
Returns:
a value from 0 (not started) to 1 (finished) indicating the progress of the operation.

runImpl

public void runImpl()
             throws JGenFileException,
                    PartialDeleteException
Description copied from class: AbstractOperation
The actual run() implementation goes in this method. Setting the last run exception and setting hasRun to true is not required by this method as it is handled by the run() method in this class.

If this method completes successfully (i.e. without throwing an exception), the last run exception is set to null indicating no exception occurred and subsequent calls to hasRun() will return true.

If this method throws an exception, the last run exception is filled in and hasRun() subsequent calls to hasRun() will return false.

Specified by:
runImpl in class AbstractOperation
Throws:
JGenFileException - if an error occurs.
PartialDeleteException
See Also:
DeleteItemOperation.run()

recursiveDelete

protected void recursiveDelete(File file,
                               Set nonDeletedReferenceSet)
                        throws JGenFileException
Recursively deletes all children of this file and then the file itself. Also updates the deletedFilesCount.

Parameters:
file - the file to delete.
Throws:
JGenFileException - if one or more files could not be deleted.

abort

public void abort()
Description copied from interface: Operation
Aborts the operation if it is currently running. Has no effect if the operation has not yet started or has finished.

This method should be executed in different thread than the one executing the run method. Operations do not have to immediately abort, but rather should make a best effort to end any long-running operations. When an operation finally does abort, the run method will return, perhaps not comleting all its required work. If this happens, an OperationAbortedException should be thrown.

An aborted operation should not leave the file system in an unstable state. All operations should tie up any loose ends before aborting.

This method could be called in response to a cancel button being pressed.

Specified by:
abort in interface Operation
Overrides:
abort in class AbstractOperation
See Also:
Operation.abort()