org.schmant.support
Class FutureEntity

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.support.FutureEntity
Direct Known Subclasses:
FutureDirectory, FutureFile

public class FutureEntity
extends AbstractArgumentChecker

An instance of this class represents the location of a future entity (a file or directory). It is often used to instruct process tasks where they should put their results. It can also be used when configuring the source of an action task if the source entity has not been created yet when the task is configured.

Objects of this type are immutable. Once they are created, they cannot be modified.

This object is thread-safe. It can safely be used by concurrent threads without any synchronizing in the client code.

Since:
0.5
Author:
Karl Gustafsson

Constructor Summary
FutureEntity(DirectoryView base, RelativeLocation loc)
          Create a FutureEntity as a (perhaps future) entity with the supplied location relative to an existing directory.
FutureEntity(DirectoryView parentDir, String name)
          Create a FutureEntity as a (perhaps future) entity in an existing parent directory.
FutureEntity(EntityView ent)
          Create a FutureEntity representing an entity that exists now.
FutureEntity(File f)
          Create a FutureEntity representing a File path in the file system.
 
Method Summary
 boolean exists()
          Does the entity represented by this future entity exist?
 DirectoryView getBaseDirectory()
          Get the base directory for this future entity.
 DirectoryView getDirectory()
          Get the directory referenced by this future entity, possibly creating it if it does not already exist.
 EntityView getEntity()
          Get the entity represented by this future entity.
 EntityView getEntityOrNull()
          Get the entity represented by this future entity, returning null if the entity does not exist.
 EFile getFile()
          Get the file referenced by this future entity, possibly creating it if it does not already exist.
 File getFileObject()
          Get the File object referencing the future entity.
protected  RelativeLocation getLocation()
          Return the future entity's location relative to the base directory.
 String getName()
          Get the name of the future entity.
 DirectoryView getParent()
          Get the parent directory of the future entity.
 DirectoryView getParentOrNull()
          Get the parent directory of the future entity.
 RelativeLocation getRelativeLocation()
          Get the future entity's location relative to its base directory.
 boolean isExistingDirectory()
          Does this future entity reference an existing directory?
 boolean isExistingFile()
          Does this future entity reference an existing file?
 String toString()
           
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FutureEntity

public FutureEntity(DirectoryView parentDir,
                    String name)
Create a FutureEntity as a (perhaps future) entity in an existing parent directory.

Parameters:
parentDir - The parent directory.
name - The entity's name

FutureEntity

public FutureEntity(DirectoryView base,
                    RelativeLocation loc)
Create a FutureEntity as a (perhaps future) entity with the supplied location relative to an existing directory.

Parameters:
base - An existing directory.
loc - The entity's location relative to the directory.

FutureEntity

public FutureEntity(EntityView ent)
Create a FutureEntity representing an entity that exists now. The created future entity does not represent the supplied entity, rather the supplied entity's parent and its name. So, if the entity is deleted this is still a valid future entity.

Parameters:
ent - An existing entity.

FutureEntity

public FutureEntity(File f)
Create a FutureEntity representing a File path in the file system. When any of the getter methods are called on this object, a temporary read/write file system containing the entity's parent directory and the entity (unless the entity itself is the root directory), is returned.

Parameters:
f - The file path for the future entity.
Method Detail

getParent

public DirectoryView getParent()
Get the parent directory of the future entity. If the directory does not already exist, it is created by this method.

This method is protected by the object's intrinsic lock (synchronized). If it creates the parent directory, it will also acquire temporary locks on the directories it needs to lock in order to do that.

Returns:
The future entity's parent, created if it did not previously exist. If the future entity is the root directory of a file system, this method returns null

getParentOrNull

public DirectoryView getParentOrNull()
Get the parent directory of the future entity. If the directory does not already exist, this method returns null.

Returns:
The future entity's parent, if it exists. If the future entity is the root directory of a file system, this method always returns null

getBaseDirectory

public DirectoryView getBaseDirectory()
Get the base directory for this future entity. This is either the immediate parent directory or some other directory higher up in the parent directory hierarchy, depending on how this object was created.

Returns:
The future entity's base directory or null if the future entity references the root directory of a file system.

getRelativeLocation

public RelativeLocation getRelativeLocation()
Get the future entity's location relative to its base directory.

Returns:
The future entity's location or null if the future entity references the root directory of a file system.

getName

public String getName()
Get the name of the future entity.

Returns:
The future entity's name.

getLocation

protected RelativeLocation getLocation()
Return the future entity's location relative to the base directory.

Returns:
The future entity's location relative to the base directory. If the future entity was not created with a relative location, this method will return null.

getEntity

public EntityView getEntity()
                     throws FutureEntityNotCreatedYetException
Get the entity represented by this future entity. The entity must exist.

Returns:
The entity.
Throws:
FutureEntityNotCreatedYetException - If the entity does not exist.

getEntityOrNull

public EntityView getEntityOrNull()
Get the entity represented by this future entity, returning null if the entity does not exist.

Returns:
The entity, or null.

exists

public boolean exists()
Does the entity represented by this future entity exist?

Returns:
true if the entity exists, false if not.

isExistingDirectory

public boolean isExistingDirectory()
Does this future entity reference an existing directory?

Returns:
true if this future entity references an already existing directory.

isExistingFile

public boolean isExistingFile()
Does this future entity reference an existing file?

Returns:
true if this future entity references an already existing file.
Since:
0.8

getFile

public EFile getFile()
              throws WrongEntityTypeException
Get the file referenced by this future entity, possibly creating it if it does not already exist.

Returns:
The file referenced by this future entity.
Throws:
WrongEntityTypeException - If the future entity references an existing directory.
See Also:
getDirectory()

getFileObject

public File getFileObject()
Get the File object referencing the future entity. If the entity does not exist, a File object referencing the future entity's location is returned without creating the entity.

The future entity must be in a File-backed file system.

Returns:
A File referencing the future entity's location.

getDirectory

public DirectoryView getDirectory()
                           throws WrongEntityTypeException
Get the directory referenced by this future entity, possibly creating it if it does not already exist.

Returns:
The directory referenced by the future entity.
Throws:
WrongEntityTypeException - If the future entity references an existing file.
See Also:
getFile()

toString

public String toString()
Overrides:
toString in class Object