|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface EntityView
This interface defines an abstract view of an entity. Views are
supported by entities with child entities (entities inheriting
EntityAcceptingEntity). The view uses a
Filter instance for entities to decide
which child entities that are visible. Views can also be nested; it is
possible to create a view of a view.
Each entity class, Directory for instance, implement their
corresponding view interface (DirectoryView), if they have one, so
viewable entities are in practice views of themselves. Many entity methods
work on views rather than entity objects.
All view objects are Observable for updates.
This interface inherits ReadWriteLockable. If that interface's lock
methods are called on a view, the backing entity is locked. See
Entity and FileSystem for more on locking.
EntityView:s (and hence all Entity objects) are
Comparable based on their hashCode:s. This can be useful for
implementing a locking strategy.
When the client is done with an entity view, it can be disconnect()
:ed from the viewed entity or entity view. After that, all methods on the
view will throw IllegalStateException:s when called.
The classes Entities and
EntityViews contains static utility methods for
working with entities and entity views.
Entities,
Filter| Method Summary | ||
|---|---|---|
boolean |
canRead()
Can the application read from the viewed entity, given appropriate access rights and locks? |
|
boolean |
canWrite()
Can the application write to the viewed entity, given appropriate access rights and locks? |
|
Set<EntityView> |
copy(DirectoryView targetDir,
String newName,
boolean preserveAttrs,
EntityLock... setupLocks)
Copy the viewed entity to a new directory and possibly give the target another name. |
|
Set<EntityView> |
copy(DirectoryView targetDir,
String newName,
EntityLock... setupLocks)
Deprecated. This method will be removed in the next release of EntityFS! |
|
void |
copyAttributes(EntityView target)
Copy entity attributes from this entity to the target entity. |
|
void |
createLock(Object identifier)
Create a lock in the viewed entity's EntityLockAdapter. |
|
void |
disconnect()
Disconnect this view from its viewed entity or entity view. |
|
|
getCapability(EntityCapabilityType<T> type)
Get the capability for the entity. |
|
FileSystem |
getFileSystem()
Get the FileSystem that the viewed entity belongs to. |
|
long |
getLastModified()
Get the time of last modification of the viewed entity. |
|
DirectoryView |
getParent()
Get the parent directory for this entity or for this entity view. |
|
EntityType |
getType()
Get the entity's EntityType. |
|
EntityView |
getViewed()
Get the next nested entity view or the entity itself if this is a view of an entity. |
|
Entity |
getViewedEntity()
Get the viewed entity. |
|
boolean |
isConnected()
Check if this view is connected with the viewed entity or with the next nested view. |
|
boolean |
isRootDirectory()
Check if this is the file system's root directory or a view of the root directory. |
|
boolean |
isValid()
Check if the entity or the viewed entity is still valid. |
|
EntityLock |
lock(Object identifier)
Use the file system's LockAcquiringStrategy to acquire a
reentrant lock on the entity. |
|
void |
rename(DirectoryView target,
String name)
Rename the entity and/or move it to another directory in the same file system. |
|
void |
setLastModified(long t)
Set the last modification time of the viewed entity. |
|
boolean |
supportsCapability(EntityCapabilityType<?> type)
Does this entity support the supplied capability type? |
|
void |
touch()
Touch the viewed entity (updates its modification time). |
|
| Methods inherited from interface java.lang.Comparable |
|---|
compareTo |
| Methods inherited from interface org.entityfs.event.Observable |
|---|
addObserver, countObservers, deleteObserver, deleteObservers |
| Methods inherited from interface org.entityfs.Named |
|---|
getName |
| Methods inherited from interface org.entityfs.lock.ReadLockable |
|---|
getReadLock, isReadLockedByCurrentThread, lockForReading |
| Methods inherited from interface org.entityfs.Deletable |
|---|
delete, isDeleted |
| Methods inherited from interface org.entityfs.lock.WriteLockable |
|---|
getWriteLock, isWriteLockedByCurrentThread, lockForWriting |
| Method Detail |
|---|
boolean isRootDirectory()
true if this is this file system's root directory.
DirectoryView getParent()
throws IllegalStateException
Filter instances, same number
of nested views). If this is called on an entity, the parent
Directory instance is returned.
Directory. If
called on an entity view, an identical view of the parent directory. If
this is called on the root directory or on a view of the root directory,
the method returns null.
IllegalStateException - If the view is disconnected.
ReadLockRequiredException - If the client does not have a read lock
for the viewed entity or for its parent.
void disconnect()
throws UnsupportedOperationException,
IllegalStateException
IllegalStateException:s.
The reason for having a disconnect method is to have a simple method to call when a view is not needed anymore. Implementations are responsible for doing all the necessary cleanup, such as deregistering observers, JMX MBeans, etc.
UnsupportedOperationException - If this method is called on an
Entity.
IllegalStateException - If the view already is disconnected.boolean isConnected()
true if this view is connected or if this is called on an
entity object, false otherwise.
FileSystem getFileSystem()
throws IllegalStateException
FileSystem that the viewed entity belongs to.
FileSystem the viewed entity belongs to.
IllegalStateException - If the view is disconnected.
EntityType getType()
throws IllegalStateException
EntityType.
EntityType
IllegalStateException - If the view is disconnected.
long getLastModified()
throws IllegalStateException,
ReadLockRequiredException
IllegalStateException - If the view is disconnected.
ReadLockRequiredException - If the client does not have a read lock
for the viewed entity.
void setLastModified(long t)
throws IllegalStateException,
WriteLockRequiredException,
ReadOnlyException
t - The new last modified time.
IllegalStateException - If the view is disconnected.
WriteLockRequiredException - If the client does not have a write
lock for the viewed entity.
ReadOnlyException - If the file system is read only.
void touch()
throws IllegalStateException,
WriteLockRequiredException,
AccessDeniedException
IllegalStateException - If the view is disconnected.
WriteLockRequiredException - If the client does not have a write
lock for the viewed entity.
AccessDeniedException - If the client does not have write access to
the entity.EntityModifiedEvent on this., ChildEntityModifiedEvent on
this's parent.
boolean canRead()
throws IllegalStateException,
ReadLockRequiredException,
AccessDeniedException
true if the client can read from the entity, false otherwise.
IllegalStateException - If the view is disconnected.
ReadLockRequiredException - If the client does not have a read lock
for the viewed entity.
AccessDeniedException - If the client does not have read access to
the entity.
boolean canWrite()
throws IllegalStateException,
ReadLockRequiredException,
AccessDeniedException
true if the client can write to the entity, false
otherwise.
IllegalStateException - If the view is disconnected.
ReadLockRequiredException - If the client does not have a read lock
for the viewed entity.
AccessDeniedException - If the client does not have write access to
the entity.
boolean isValid()
throws IllegalStateException,
ReadLockRequiredException
This method uses the file system's EntityValidityControlStrategy
to control if the entity is still valid.
true if the entity object is valid, false
otherwise.
IllegalStateException - If the view is disconnected.
ReadLockRequiredException - If the client does not have a read lock
for the viewed entity.Deletable.isDeleted()
EntityView getViewed()
throws IllegalStateException
IllegalStateException - If the view is disconnected.
Entity getViewedEntity()
throws IllegalStateException
Entity. Always returns the viewed
Entity, even if this view is nested.
IllegalStateException - If the view, or any other view in the view
nest chain is disconnected.
EntityLock lock(Object identifier)
throws IllegalStateException
LockAcquiringStrategy to acquire a
reentrant lock on the entity. This can be used instead of synchronized to get a lock for an entity using the same strategy as the
other file system methods.
To avoid deadlocks, clients should use a consequent locking strategy for how custom locks relate to the standard read and write locks on an entity and to other custom locks.
This method always returns a lock for a valid identifier, even if the file system is not locking.
identifier - An identifier for the lock. Each different lock for an
entity has an identifier that is unique for the entity. (A constant
Object instance, for instance.)
null if no lock is defined
for the identifier.
IllegalStateException - If the view is disconnected.
void createLock(Object identifier)
throws IllegalStateException,
WriteLockRequiredException,
IllegalArgumentException
EntityLockAdapter. After
creating it, it can be locked by calling the lock(Object)
method.
To create standalone locks (locks that are not tied to any specific
entity), use the file system's EntityLockAdapter directly.
identifier -
IllegalStateException
WriteLockRequiredException - If the client does not have a write
lock for the viewed entity.
IllegalArgumentException - If there already is a lock defined for
the same identifier.
@Deprecated
Set<EntityView> copy(DirectoryView targetDir,
String newName,
EntityLock... setupLocks)
throws EntityFoundException,
ReadOnlyException,
UncheckedInterruptedException,
LockRequiredException,
IllegalStateException,
AccessDeniedException
Filter instances). If
an entity view is copied is copied into a directory view, the both view's
filters are combined in the returned view.
This method returns a list of entity view objects rather than just a
single EntityView object. The reason for this is that the target
file system may have different ideas about what constitutes an entity
compared with the source file system. An entity in one file system might
be three entities in another file system, or no entity at all. When
copying within the same file system or between file systems with the same
set of capabilities, the returned list always has one entity view in it.
This method does not copy directories recursively. To do that, use the
IteratorCopier.
This method can release locks that are only necessary for setting up the target entity before data is copied to it. This may be the write lock for the target directory.
If the client wants that the target directory should still be locked
after the method call, just increment the write lock's lock count by
calling its lock() method before calling this method.
If the copied entity supports any
ECEntityAttributes capability, its
attributes are not copied by this method. (An entity's attributes
is a property of its parent directory.)
Note: This method is deprecated and will be removed in a future
release (pretty soon). Use
copy(DirectoryView, String, boolean, EntityLock...) instead.
This method does not copy any attributes to the target entity.
targetDir - A view of the target directory.newName - The target entity's name.setupLocks - Locks only necessary for setting up the target entity.
They are unlocked before data is copied to the target entity. The method
is guaranteed to release locks given here, even if it throws an
exception.
EntityFoundException - If there already is an entity with the
target name in the target directory.
ReadOnlyException - If the target directory is read only.
UncheckedInterruptedException - If the current thread is
interrupted during the copy. It is up to the entity implementation to
actually honor this. If it does, it clears the thread's interrupt flag
before throwing the exception.
LockRequiredException - If the caller does not hold any one of the
required locks.
IllegalStateException - If any of this or the target views are
disconnected.
AccessDeniedException - If the client does not have read access to
the source entity or write access to the target directory.NewEntityEvent for all created
entities., ChildEntityAddedEvent for
targetDir., ChildEntityModifiedEvent for
targetDir's parent.
Set<EntityView> copy(DirectoryView targetDir,
String newName,
boolean preserveAttrs,
EntityLock... setupLocks)
throws EntityFoundException,
ReadOnlyException,
UncheckedInterruptedException,
LockRequiredException,
IllegalStateException,
AccessDeniedException
Filter instances). If
an entity view is copied is copied into a directory view, the both view's
filters are combined in the returned view.
This method returns a list of entity view objects rather than just a
single EntityView object. The reason for this is that the target
file system may have different ideas about what constitutes an entity
compared with the source file system. An entity in one file system might
be three entities in another file system, or no entity at all. When
copying within the same file system or between file systems with the same
set of capabilities, the returned list always has one and only one entity
view in it.
This method does not copy directories recursively. To do that, use the
IteratorCopier.
This method can release locks that are only necessary for setting up the
target entity before data is copied to it. This may be the write lock for
the target directory and the read lock for the source entity's parent
directory. See the setupLocks parameter.
If the copied entity supports any
ECEntityAttributes capability, its
attributes are copied by this method if the preserveAttrs
parameter is set to true.
targetDir - A view of the target directory.newName - The target entity's name.preserveAttrs - Should attributes from the source entity be copied
to the target entity? An example of an entity attribute is its latest
modification time. Capabilities may add their own attributes; see the
documentation for each capability for details.setupLocks - Locks only necessary for setting up the target entity.
They are unlocked before data is copied to the target entity. The method
is guaranteed to release locks given here, even if it throws an
exception. The read lock on the source parent directory and/or the write
lock on the target directory can be supplied in this collection. If any
or both of the locks are, they are unlocked before any file data is
copied to the target entity.
EntityFoundException - If there already is an entity with the
target name in the target directory.
ReadOnlyException - If the target directory is read only.
UncheckedInterruptedException - If the current thread is
interrupted during the copy. It is up to the entity implementation to
actually honor this. If it does, it clears the thread's interrupt flag
before throwing the exception.
LockRequiredException - If the caller does not hold any one of the
required locks.
IllegalStateException - If any of this or the target views are
disconnected.
AccessDeniedException - If the client does not have read access to
the source entity or write access to the target directory.setupLocks parameter. In that case, it is
released by this method before file data is copied.NewEntityEvent for all created
entities., ChildEntityAddedEvent for
targetDir., ChildEntityModifiedEvent for
targetDir's parent.
void copyAttributes(EntityView target)
throws ReadOnlyException,
LockRequiredException,
IllegalStateException,
AccessDeniedException
This method sets the latest modification time on the target entity to be the same as on this entity. Capability providers may provide their own attributes that are copied by this method. For instance, entity attribute capabilities copy their entity attributes, but metadata capabilities do not copy metadata to the target entity.
target - The entity to set the attributes on. Only the attributes
supported by this entity are set.
ReadOnlyException - If the target entity is read only.
LockRequiredException - If the caller does not have any of the
required entity locks.
IllegalStateException - If this view or the target view is
disconnected.
AccessDeniedException - If the caller does not have read access to
this entity or its parent directory or write access to the target entity
and its parent directory.EntityModifiedEvent for
target., ChildEntityModifiedEvent for
target's parent directory.
void rename(DirectoryView target,
String name)
throws EntityFoundException,
ReadOnlyException,
WriteLockRequiredException,
AccessDeniedException,
IllegalStateException
If the entity supports any
ECEntityAttributes capability, its
attributes are also moved.
Warning: this method does not verify that a directory is not moved to a sub directory of itself. That may give random errors, or worse: work.
target - The entity's new parent directory. It can be the same
directory as the current parent directory, but not null. The
target directory must be in the same file system as the entity.name - The entity's new name. This might be the current name, but
not null.
EntityFoundException - If an entity with the same name already
exists in the target directory.
ReadOnlyException - If the file system is read only.
WriteLockRequiredException - If the caller does not hold all
required write locks.
AccessDeniedException - If the caller does not have write access to
all required entities.
IllegalStateException - If any of this or the target views are
disconnected.EntityRenamedEvent for this., EntityModifiedEvent for
this's current parent directory., ChildEntityRenamedEvent for
target if target is the same as the this's
current parent directory., ChildEntityRemovedEvent for
this's parent directory if it is different from target., ChildEntityAddedEvent for
target if it is different from this's current parent
directory., EntityModifiedEvent for
target, if it is different from this's current parent
directory (i.e. this event is only generated once for the parent
directory if the entity is renamed)., ChildEntityModifiedEvent for
this's parent directory., ChildEntityModifiedEvent for
target's parent directory if it is different from this's
current parent directory.
boolean supportsCapability(EntityCapabilityType<?> type)
throws IllegalStateException
type - The capability type.
true if the entity supports the capability type.
IllegalStateException - If any of this or the target views are
disconnected.FileSystem.supportsCapabilityForEntity(EntityView,
EntityCapabilityType),
getCapability(EntityCapabilityType)
<T extends EntityCapability> T getCapability(EntityCapabilityType<T> type)
throws UnsupportedCapabilityException,
IllegalStateException
type - The capability type.
UnsupportedCapabilityException - If the entity does not support the
requested capability.
IllegalStateException - If any of this or the target views are
disconnected.FileSystem.getCapabilityForEntity(EntityView, EntityCapabilityType),
supportsCapability(EntityCapabilityType)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||