org.apache.commons.transaction.file
Class TxFileResourceManager.FileTxContext.TxFileResource

java.lang.Object
  extended by org.apache.commons.transaction.file.FileResourceManager.FileResource
      extended by org.apache.commons.transaction.file.TxFileResourceManager.FileTxContext.TxFileResource
All Implemented Interfaces:
StreamableResource
Enclosing class:
TxFileResourceManager.FileTxContext

protected class TxFileResourceManager.FileTxContext.TxFileResource
extends FileResourceManager.FileResource


Constructor Summary
TxFileResourceManager.FileTxContext.TxFileResource(File file)
           
TxFileResourceManager.FileTxContext.TxFileResource(String path)
           
 
Method Summary
 void copy(TxFileResourceManager.FileTxContext.TxFileResource destination)
           
protected  void copyNonRecursive(TxFileResourceManager.FileTxContext.TxFileResource target)
           
protected  TxFileResourceManager.FileTxContext.TxFileResource create(File file)
           
 void createAsDirectory()
          Creates this resource or a physical directory.
 void createAsFile()
          Creates this resource or a physical file.
 void delete()
          Physically deletes this resource.
 boolean exists()
          Checks if this resource physically exists.
 TxFileResourceManager.FileTxContext.TxFileResource getChild(String name)
          Gets a specific child of this resource.
 List<? extends TxFileResourceManager.FileTxContext.TxFileResource> getChildren()
          Gets the children of the resource.
 TxFileResourceManager.FileTxContext.TxFileResource getParent()
          Gets the parent of this resource, i.e. the directory this resource resides in or null if this is the root folder.
 String getPath()
          Gets the full path of this resource
 Object getProperty(String name)
          Retrieves a specific property.
 boolean isDirectory()
          Checks whether this resource is a directory, i.e. whether it can have children.
 boolean isFile()
          Checks whether this resource is a file, i.e. whether it contains a content stream.
protected  void mkdirs()
           
 void move(TxFileResourceManager.FileTxContext.TxFileResource destination)
           
protected  void moveNonRecursive(TxFileResourceManager.FileTxContext.TxFileResource target)
           
protected  void moveOrcopyRecursive(TxFileResourceManager.FileTxContext.TxFileResource target, boolean move)
           
 void readLock()
          Explicitly sets a read lock on this resource.
 InputStream readStream()
          Gets the input stream associated to this resource.
protected  void removeNonRecursive()
           
 void removeProperty(String name)
          Removes a specific property.
protected  void removeRecursive()
           
 void setProperty(String name, Object newValue)
          Sets a specific property.
 void writeLock()
          Explicitly sets a write lock on this resource.
 OutputStream writeStream(boolean append)
          Gets the output stream associated to this resource.
 
Methods inherited from class org.apache.commons.transaction.file.FileResourceManager.FileResource
copy, getFile, getFileForResource, getName, move, moveOrCopySaneCheck, prepareMoveorCopy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TxFileResourceManager.FileTxContext.TxFileResource

public TxFileResourceManager.FileTxContext.TxFileResource(File file)
                                                   throws ResourceException
Throws:
ResourceException

TxFileResourceManager.FileTxContext.TxFileResource

public TxFileResourceManager.FileTxContext.TxFileResource(String path)
                                                   throws ResourceException
Throws:
ResourceException
Method Detail

createAsDirectory

public void createAsDirectory()
                       throws ResourceException
Description copied from interface: StreamableResource
Creates this resource or a physical directory. In case there already is a physical resource having the same name, this request will fail and throw an exception.

Specified by:
createAsDirectory in interface StreamableResource
Overrides:
createAsDirectory in class FileResourceManager.FileResource
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to create this resource as a directory

createAsFile

public void createAsFile()
                  throws ResourceException
Description copied from interface: StreamableResource
Creates this resource or a physical file. In case there already is a physical resource having the same name, this request will fail and throw an exception.

Specified by:
createAsFile in interface StreamableResource
Overrides:
createAsFile in class FileResourceManager.FileResource
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to create this resource as a file

create

protected TxFileResourceManager.FileTxContext.TxFileResource create(File file)
                                                             throws ResourceException
Overrides:
create in class FileResourceManager.FileResource
Throws:
ResourceException

mkdirs

protected void mkdirs()
               throws ResourceException
Throws:
ResourceException

moveOrcopyRecursive

protected void moveOrcopyRecursive(TxFileResourceManager.FileTxContext.TxFileResource target,
                                   boolean move)
                            throws ResourceException
Throws:
ResourceException

removeRecursive

protected void removeRecursive()
                        throws ResourceException
Throws:
ResourceException

copyNonRecursive

protected void copyNonRecursive(TxFileResourceManager.FileTxContext.TxFileResource target)
                         throws ResourceException
Throws:
ResourceException

moveNonRecursive

protected void moveNonRecursive(TxFileResourceManager.FileTxContext.TxFileResource target)
                         throws ResourceException
Throws:
ResourceException

removeNonRecursive

protected void removeNonRecursive()
                           throws ResourceException
Throws:
ResourceException

delete

public void delete()
            throws ResourceException
Description copied from interface: StreamableResource
Physically deletes this resource.

Specified by:
delete in interface StreamableResource
Overrides:
delete in class FileResourceManager.FileResource
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to delete the resource

exists

public boolean exists()
Description copied from interface: StreamableResource
Checks if this resource physically exists.

Specified by:
exists in interface StreamableResource
Overrides:
exists in class FileResourceManager.FileResource
Returns:
true if it exists

getChild

public TxFileResourceManager.FileTxContext.TxFileResource getChild(String name)
                                                            throws ResourceException
Description copied from interface: StreamableResource
Gets a specific child of this resource. This method returns a resource even if it does not exist.

Specified by:
getChild in interface StreamableResource
Overrides:
getChild in class FileResourceManager.FileResource
Parameters:
name - the name of the child resource
Returns:
the resource object - even if it does not exist
Throws:
ResourceException - in case anything goes fatally wrong

getChildren

public List<? extends TxFileResourceManager.FileTxContext.TxFileResource> getChildren()
                                                                               throws ResourceException
Description copied from interface: StreamableResource
Gets the children of the resource.

Specified by:
getChildren in interface StreamableResource
Overrides:
getChildren in class FileResourceManager.FileResource
Returns:
a list of children (empty if this is a file), never null
Throws:
ResourceException - in case anything goes fatally wrong

getParent

public TxFileResourceManager.FileTxContext.TxFileResource getParent()
                                                             throws ResourceException
Description copied from interface: StreamableResource
Gets the parent of this resource, i.e. the directory this resource resides in or null if this is the root folder.

Specified by:
getParent in interface StreamableResource
Overrides:
getParent in class FileResourceManager.FileResource
Returns:
the parent directory or null if there is none
Throws:
ResourceException - in case anything goes fatally wrong

getPath

public String getPath()
Description copied from interface: StreamableResource
Gets the full path of this resource

Specified by:
getPath in interface StreamableResource
Overrides:
getPath in class FileResourceManager.FileResource
Returns:
the full path

getProperty

public Object getProperty(String name)
Description copied from interface: StreamableResource
Retrieves a specific property. Which properties there are and whether you can create new ones depends on the specific implementation.

Specified by:
getProperty in interface StreamableResource
Overrides:
getProperty in class FileResourceManager.FileResource
Parameters:
name - the name of the property
Returns:
the value of the property or null if there is no such property

isDirectory

public boolean isDirectory()
Description copied from interface: StreamableResource
Checks whether this resource is a directory, i.e. whether it can have children. Note that a resource can be both a directory and a file.

Specified by:
isDirectory in interface StreamableResource
Overrides:
isDirectory in class FileResourceManager.FileResource
Returns:
true if this resource can have children

isFile

public boolean isFile()
Description copied from interface: StreamableResource
Checks whether this resource is a file, i.e. whether it contains a content stream. Note that a resource can be both a directory and a file.

Specified by:
isFile in interface StreamableResource
Overrides:
isFile in class FileResourceManager.FileResource
Returns:
true if this resource contains a content stream

copy

public void copy(TxFileResourceManager.FileTxContext.TxFileResource destination)
          throws ResourceException
Throws:
ResourceException

move

public void move(TxFileResourceManager.FileTxContext.TxFileResource destination)
          throws ResourceException
Throws:
ResourceException

readStream

public InputStream readStream()
                       throws ResourceException
Description copied from interface: StreamableResource
Gets the input stream associated to this resource. You are responsible for closing the stream after using it.

Specified by:
readStream in interface StreamableResource
Overrides:
readStream in class FileResourceManager.FileResource
Returns:
the input stream for reading
Throws:
ResourceException - in case anything goes fatally wrong

writeStream

public OutputStream writeStream(boolean append)
                         throws ResourceException
Description copied from interface: StreamableResource
Gets the output stream associated to this resource. You are responsible for closing the stream after using it.

Specified by:
writeStream in interface StreamableResource
Overrides:
writeStream in class FileResourceManager.FileResource
Parameters:
append - determines whether you append to the existing content
Returns:
the output stream for writing
Throws:
ResourceException - in case anything goes fatally wrong

removeProperty

public void removeProperty(String name)
Description copied from interface: StreamableResource
Removes a specific property. Not all implementations support his operation. If unsupported an exception in thrown.

Specified by:
removeProperty in interface StreamableResource
Overrides:
removeProperty in class FileResourceManager.FileResource
Parameters:
name - the name of the property

setProperty

public void setProperty(String name,
                        Object newValue)
Description copied from interface: StreamableResource
Sets a specific property. Not all implementations support his operation. If unsupported an exception in thrown.

Specified by:
setProperty in interface StreamableResource
Overrides:
setProperty in class FileResourceManager.FileResource
Parameters:
name - the name of the property
newValue - the new value

readLock

public void readLock()
Description copied from interface: StreamableResource
Explicitly sets a read lock on this resource. This means no other thread can write to this resource while this read lock is held. Other threads are allowed to set further read locks, though.

Not all implementations support his operation as it only makes sense in a transactional environment. There is no unlock operation as the release of all locks has to be controlled by the transaction manager.

If unsupported nothing will happen.

Specified by:
readLock in interface StreamableResource
Overrides:
readLock in class FileResourceManager.FileResource

writeLock

public void writeLock()
Description copied from interface: StreamableResource
Explicitly sets a write lock on this resource. This means no other thread can neither write nor read to this resource while this write lock is held.

Not all implementations support his operation as it only makes sense in a transactional environment. There is no unlock operation as the release of all locks has to be controlled by the transaction manager.

If unsupported nothing will happen.

Specified by:
writeLock in interface StreamableResource
Overrides:
writeLock in class FileResourceManager.FileResource


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.