org.apache.commons.transaction.file
Class FileResourceManager.FileResource

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

protected static class FileResourceManager.FileResource
extends Object
implements StreamableResource


Constructor Summary
FileResourceManager.FileResource(File file)
           
FileResourceManager.FileResource(String path)
           
 
Method Summary
 void copy(StreamableResource destination)
          Copies this resource to a new one.
protected  FileResourceManager.FileResource 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.
 FileResourceManager.FileResource getChild(String name)
          Gets a specific child of this resource.
 List<? extends FileResourceManager.FileResource> getChildren()
          Gets the children of the resource.
protected  File getFile()
           
protected static File getFileForResource(StreamableResource resource)
           
 String getName()
          Gets the name, i.e. the last segment of the path.
 FileResourceManager.FileResource 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.
 void move(StreamableResource destination)
          Moves (or renames) this resource to a new one.
protected  void moveOrCopySaneCheck(StreamableResource destination)
           
protected  boolean prepareMoveorCopy(StreamableResource destination)
           
 void readLock()
          Explicitly sets a read lock on this resource.
 InputStream readStream()
          Gets the input stream associated to this resource.
 void removeProperty(String name)
          Removes a specific property.
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileResourceManager.FileResource

public FileResourceManager.FileResource(String path)
                                 throws ResourceException
Throws:
ResourceException

FileResourceManager.FileResource

public FileResourceManager.FileResource(File file)
                                 throws ResourceException
Throws:
ResourceException
Method Detail

getFileForResource

protected static File getFileForResource(StreamableResource resource)
                                  throws ResourceException
Throws:
ResourceException

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
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
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to create this resource as a file

delete

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

Specified by:
delete in interface StreamableResource
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
Returns:
true if it exists

getChildren

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

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

getParent

public FileResourceManager.FileResource 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
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
Returns:
the full path

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
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
Returns:
true if this resource contains a content stream

move

public void move(StreamableResource destination)
          throws ResourceException
Description copied from interface: StreamableResource
Moves (or renames) this resource to a new one. If nothing goes wrong this resource will be deleted afterwards.

Specified by:
move in interface StreamableResource
Parameters:
destination - the new resource
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to move this resource

copy

public void copy(StreamableResource destination)
          throws ResourceException
Description copied from interface: StreamableResource
Copies this resource to a new one. If nothing goes wrong there will be two existing resources afterwards.

Specified by:
copy in interface StreamableResource
Parameters:
destination - the new resource
Throws:
ResourceException - in case anything goes fatally wrong or you have not been able to copy this resource

prepareMoveorCopy

protected boolean prepareMoveorCopy(StreamableResource destination)
                             throws ResourceException
Throws:
ResourceException

moveOrCopySaneCheck

protected void moveOrCopySaneCheck(StreamableResource 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
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
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
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
Parameters:
name - the name of the property
newValue - the new value

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
Parameters:
name - the name of the property
Returns:
the value of the property or null if there is no such property

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

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

getFile

protected File getFile()

create

protected FileResourceManager.FileResource create(File file)
                                           throws ResourceException
Throws:
ResourceException

getChild

public FileResourceManager.FileResource 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
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

getName

public String getName()
Description copied from interface: StreamableResource
Gets the name, i.e. the last segment of the path.

Specified by:
getName in interface StreamableResource
Returns:
the name


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