org.entityfs.util
Class CompoundEntityHolder

java.lang.Object
  extended by org.entityfs.util.CompoundEntityHolder
All Implemented Interfaces:
EntityHolder, Lockable, ReadLockable

public class CompoundEntityHolder
extends Object
implements EntityHolder

This EntityHolder combines several other EntityHolder:s. It can be used to make several directories look as one, at least if they are to be used as EntityHolder:s.

Since:
1.1
Author:
Karl Gustafsson

Constructor Summary
CompoundEntityHolder(EntityHolder... entityHolders)
          Create a new CompoundEntityHolder from some EntityHolder :s
CompoundEntityHolder(List<? extends EntityHolder> l)
          Create a new CompoundEntityHolder from a list of EntityHolder:s.
 
Method Summary
 boolean containsEntity(EntityView ent)
          Does this entity holder contain the supplied entity? If this is called on a symbolic link, it is checked if the link target is a directory and that directory contains the entity.
 boolean containsEntity(String name)
          Can an entity with the given name be retrieved from this object? If this is called on a symbolic link, it is checked if the link target is a directory and that directory contains an entity with the given name.
 EntityView getEntityOrNull(String name)
          Return the first entity with the supplied name found in the list of EntityHolder:s.
 EntityLock getReadLock()
          Get the read lock without locking it.
 boolean isReadLockedByCurrentThread()
          Does the calling thread hold a read lock for this object? A write lock also qualifies as a read lock.
 EntityLock lockForReading()
          Lock object for reading and return the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundEntityHolder

public CompoundEntityHolder(List<? extends EntityHolder> l)
Create a new CompoundEntityHolder from a list of EntityHolder:s.

Parameters:
l - A list of entity holders. This method makes a copy of this list.

CompoundEntityHolder

public CompoundEntityHolder(EntityHolder... entityHolders)
Create a new CompoundEntityHolder from some EntityHolder :s

Parameters:
entityHolders - The EntityHolder:s.
Method Detail

lockForReading

public EntityLock lockForReading()
Description copied from interface: ReadLockable
Lock object for reading and return the lock. How the lock is acquired is determined by the EntityLockAdapterFactory and LockAcquiringStrategy used. If this is called on an object that somehow is connected to an entity object, that entity's file system's entity lock adapter factory and lock acquiring strategy is used.

A read lock cannot be upgraded to a write lock (just like how Java's ReadWriteLock works).

For more discussions on locks and locking, see Entity and FileSystem.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Specified by:
lockForReading in interface ReadLockable
Returns:
A locked read lock.

getReadLock

public EntityLock getReadLock()
Description copied from interface: ReadLockable
Get the read lock without locking it.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Specified by:
getReadLock in interface ReadLockable
Returns:
The lockable's read lock. This might be unlocked or locked by someone else.

containsEntity

public boolean containsEntity(String name)
                       throws IllegalStateException,
                              NotADirectoryException,
                              CircularReferenceException
Description copied from interface: EntityHolder
Can an entity with the given name be retrieved from this object? If this is called on a symbolic link, it is checked if the link target is a directory and that directory contains an entity with the given name.

Specified by:
containsEntity in interface EntityHolder
Parameters:
name - The name of the entity.
Returns:
true if there is an entity with the given name referenced by this holder.
Throws:
IllegalStateException - If this is called on a disconnected view.
NotADirectoryException - If an entity in a symbolic link target path is not a directory or cannot be dereferenced to a directory.
CircularReferenceException - If symbolic link references are circular. For instance l1 -> l2, l2 -> l1.

containsEntity

public boolean containsEntity(EntityView ent)
                       throws IllegalStateException,
                              NotADirectoryException,
                              CircularReferenceException
Description copied from interface: EntityHolder
Does this entity holder contain the supplied entity? If this is called on a symbolic link, it is checked if the link target is a directory and that directory contains the entity.

Specified by:
containsEntity in interface EntityHolder
Parameters:
ent - The entity (or a view of it).
Returns:
true If the entity holder contains the supplied entity.
Throws:
IllegalStateException - If this is called on a disconnected view.
NotADirectoryException - If an entity in a symbolic link target path is not a directory or cannot be dereferenced to a directory.
CircularReferenceException - If symbolic link references are circular. For instance l1 -> l2, l2 -> l1.

getEntityOrNull

public EntityView getEntityOrNull(String name)
                           throws IllegalStateException,
                                  NotADirectoryException,
                                  CircularReferenceException
Return the first entity with the supplied name found in the list of EntityHolder:s.

Specified by:
getEntityOrNull in interface EntityHolder
Parameters:
name - The name of the entity.
Returns:
An EntityView or null. If this method is called on a DirectoryView and the returned entity is ViewCapable , the returned object inherits the view settings of the parent. If the returned entity is a file, the returned object can be cast to an EFile, if it is a directory, it can be cast to a DirectoryView (or a Directory if this method is called on a Directory rather than a DirectoryView). The type of the returned object can be determined by calling its EntityView.getType() method or by using instanceof.
Throws:
IllegalStateException - If the view is disconnected.
NotADirectoryException - If an entity in the symbolic link target path is not a directory or cannot be dereferenced to a directory.
CircularReferenceException - If the symbolic link references are circular. For instance l1 -> l2, l2 -> l1.

isReadLockedByCurrentThread

public boolean isReadLockedByCurrentThread()
                                    throws IllegalStateException
Description copied from interface: ReadLockable
Does the calling thread hold a read lock for this object? A write lock also qualifies as a read lock.

Specified by:
isReadLockedByCurrentThread in interface ReadLockable
Returns:
true if the lockable object is read or write locked by the current thread.
Throws:
IllegalStateException - If this is called on a disconnected entity view.