|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.lock.AbstractLockable
org.entityfs.impl.impl.AbstractEntityImpl
org.entityfs.impl.impl.AbstractEntityAcceptingEntityImpl<DirectoryView>
org.entityfs.impl.impl.DirectoryImpl
public class DirectoryImpl
Directory implementation.
Field Summary |
---|
Fields inherited from interface org.entityfs.Directory |
---|
DEFAULT_TEMP_FILE_SUFFIX, MINIMUM_TEMP_FILE_PREFIX_LENGTH |
Constructor Summary | |
---|---|
protected |
DirectoryImpl(FileSystemImplementation fs,
DirectoryImplementation parent,
DirectoryDelegate dd)
|
Method Summary | |
---|---|
void |
addChildEntity(String name,
EntityImplementation entity)
Used to add a new entity to the directory when an entity is created. |
void |
assertCanBeDeleted()
Perform entity type-specific checks in addition to the checks in the delete method. |
void |
assertNoChildEntityWithName(String name)
Assert that an entity with the given name does not exist in the directory. |
boolean |
canBeDereferenced()
Can the entity-accepting entity be dereferenced. |
boolean |
containsEntity(EntityView ev)
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. |
Set<EntityView> |
copy(DirectoryView targetDir,
String targetName,
boolean preserveAttrs,
EntityLock... setupLocks)
Copy the viewed entity to a new directory and possibly give the target another name. |
Set<EntityView> |
copyFrom(EntityImplementation ent,
String targetName,
boolean preserveAttrs,
List<EntityAttributeSetter> asl,
EntityLock[] setupLocks)
Copy the contents from the EntityAdapter to one or more new
entities in the viewed directory. |
EntityDelegate |
createChildDelegate(EntityType et,
String name,
Object data)
|
protected void |
deleteInternal()
This method is called by AbstractEntityImpl.delete() after it has performed all
validity, access control and lock checks. |
Entity |
getEntityOrNull(String name)
Get the named entity. |
EntityType |
getType()
Get the entity's EntityType . |
String |
getUniqueEntityName(String prefix,
String suffix)
Get a unique entity name with the given prefix and suffix in the directory. |
DirectoryView |
getViewedDir()
|
DirectoryImplementation |
getViewedDirImplementation()
|
void |
handleDisappearingChild(EntityImplementation entity)
Called whenever it is detected that a child entity has disappeared from the directory. |
boolean |
isEmpty()
Is the listable empty? If a directory view is empty, the viewed directory may still contain entities that are hidden by the view's filter. |
boolean |
isView()
|
Iterator<EntityView> |
iterator()
|
Set<EntityView> |
listEntities()
Return all entities that are visible in this directory. |
EntityImplementation |
newEntity(EntityType et,
String name,
Object data)
Create a new child entity in the directory. |
DirectoryView |
newView(Filter<? super EntityView> filter)
Create a new, connected view on this entity or entity view. |
void |
removeChildEntity(EntityImplementation entity,
DirectoryImplementation newParent)
Called by the child entity when it should be removed from the directory. |
void |
renameChildEntity(String name,
EntityImplementation entity,
DirectoryImplementation oldParent,
String oldName)
Called by a child entity when it is renamed. |
String |
toString()
Subclasses should override this to return something more pretty. |
Methods inherited from class org.entityfs.impl.impl.AbstractEntityAcceptingEntityImpl |
---|
copyViewSettings, dereferenceOrNull, getFilter, hasFilters |
Methods inherited from class org.entityfs.lock.AbstractLockable |
---|
assertIsReadLocked, assertIsWriteLocked, getLockAcquiringStrategy, getLockAdapter, getLocked, getReadLock, getWriteLock, isReadLockedByCurrentThread, isWriteLockedByCurrentThread, lock, lockForReading, lockForWriting, logLockStack |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.entityfs.EntityAcceptingEntityView |
---|
dereferenceOrNull |
Methods inherited from interface org.entityfs.ViewCapable |
---|
getFilter, hasFilters |
Methods inherited from interface org.entityfs.impl.EntityViewImplementation |
---|
getAbsoluteLocationNoLocking, getFileSystemImplementation, getNameNoLocking, getObserverList |
Methods inherited from interface org.entityfs.Entity |
---|
hasExecuteAccess, hasReadAccess, hasWriteAccess |
Methods inherited from interface org.entityfs.EntityView |
---|
canRead, canWrite, copy, copyAttributes, createLock, disconnect, getCapability, getFileSystem, getLastModified, getParent, getViewed, getViewedEntity, isConnected, isRootDirectory, isValid, lock, rename, setLastModified, supportsCapability, touch |
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 |
Constructor Detail |
---|
protected DirectoryImpl(FileSystemImplementation fs, DirectoryImplementation parent, DirectoryDelegate dd)
Method Detail |
---|
public EntityType getType()
EntityView
EntityType
.
getType
in interface EntityView
ETDirectory.TYPE
, always.public boolean isView()
false
, always.public void assertNoChildEntityWithName(String name) throws EntityFoundException
assertNoChildEntityWithName
in interface DirectoryImplementation
name
- The name of the child entity.
EntityFoundException
- If an entity with the given name exists in
the directory.public void assertCanBeDeleted()
AbstractEntityImpl
delete
method.
assertCanBeDeleted
in class AbstractEntityImpl
public void handleDisappearingChild(EntityImplementation entity)
handleDisappearingChild
in interface DirectoryImplementation
entity
- public void removeChildEntity(EntityImplementation entity, DirectoryImplementation newParent)
DirectoryImplementation
ChildEntityManager
and for firing the EntityModifiedEvent
and ChildEntityRemovedEvent
events.
removeChildEntity
in interface DirectoryImplementation
entity
- The entity to remove.newParent
- The entity's parent directory after the current
operation if the entity is being moved. This is set to null
if
the entity is deleted.public void addChildEntity(String name, EntityImplementation entity)
DirectoryImplementation
ChildEntityManager
and for firing the
ChildEntityAddedEvent
and EntityModifiedEvent
events.
addChildEntity
in interface DirectoryImplementation
name
- The entity's name.entity
- The entity.public void renameChildEntity(String name, EntityImplementation entity, DirectoryImplementation oldParent, String oldName)
DirectoryImplementation
DirectoryImplementation.removeChildEntity(EntityImplementation, DirectoryImplementation)
before calling this method, so it should not be present in the child
entity manager by the time that this method is called. This method is
responsible for adding the child entity to the child entity manager and
for firing the ChildEntityRenamedEvent
if the entity was renamed
within the same directory, or the ChildEntityAddedEvent
if the
entity was moved in from another directory.
renameChildEntity
in interface DirectoryImplementation
name
- The entity's (new) name.entity
- The entity.oldParent
- The old parent directory.oldName
- The old name.public boolean containsEntity(String name)
EntityHolder
containsEntity
in interface EntityHolder
name
- The name of the entity.
true
if there is an entity with the given name referenced
by this holder.public boolean containsEntity(EntityView ev)
EntityHolder
containsEntity
in interface EntityHolder
ev
- The entity (or a view of it).
true
If the entity holder contains the supplied entity.public boolean canBeDereferenced()
EntityAcceptingEntityView
canBeDereferenced
in interface EntityAcceptingEntityView<DirectoryView>
false
, always.public Entity getEntityOrNull(String name)
EntityHolder
If this is called on a directory view, and the returned entity is
ViewCapable
, the returned entity view inherits the same view
settings as the directory view (same filter instances).
If this is called on an EntityHolder
that contains several
entities with the same name, the implementation may choose how to deal
with that. This can never happen for directories since entity names in a
directory are required to be unique.
getEntityOrNull
in interface EntityHolder
name
- The name of the entity.
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
.public Set<EntityView> listEntities()
EntityListable
If this is called on a directory view, all returned ViewCapable
entities inherit the view's filters.
listEntities
in interface EntityListable
Set
of entity views. If this is called on a directory
entity object, a set of entity objects (not views) are returned. The set
may be empty, but never null
.public Iterator<EntityView> iterator()
iterator
in interface Iterable<EntityView>
Iterable
public boolean isEmpty()
EntityListable
isEmpty
in interface EntityListable
true
if the directory view is empty.public EntityImplementation newEntity(EntityType et, String name, Object data) throws EntityFoundException
DirectoryView
ViewCapable
, a view
with the same filter instances as the directory view is returned.
Directories
also contains methods for creating
child entities.
newEntity
in interface DirectoryView
et
- The type of the entity to create.name
- The name of the new entity.data
- Entity type-specific data needed to create the entity. Most
entity types (files and directories) happily accept null
.
ViewCapable
, it inherits
the view settings of this directory view. The result can be casted to the
entity interface specified by the supplied entity type, et
. For
instance to an EFile
if et
is an ETFile
or to a
DirectoryView
if et
is an ETDirectory
.
EntityFoundException
- If an entity with the same name already
exists in the directory.public String getUniqueEntityName(String prefix, String suffix)
DirectoryView
getUniqueEntityName
in interface DirectoryView
prefix
- The prefix string to be used in generating the entity name.
It must contain at least three characters.suffix
- The file name suffix, for instance .tmp
.
public DirectoryView newView(Filter<? super EntityView> filter)
ViewCapable
newView
in interface ViewCapable<DirectoryView>
filter
- The filter that determines which child entities will be visible
in the view.
Directory
is a DirectoryView
, for instance.public DirectoryView getViewedDir()
public DirectoryImplementation getViewedDirImplementation()
public Set<EntityView> copy(DirectoryView targetDir, String targetName, boolean preserveAttrs, EntityLock... setupLocks)
EntityView
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
.
copy
in interface EntityView
targetDir
- A view of the target directory.targetName
- 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.
public Set<EntityView> copyFrom(EntityImplementation ent, String targetName, boolean preserveAttrs, List<EntityAttributeSetter> asl, EntityLock[] setupLocks)
DirectoryViewImplementation
EntityAdapter
to one or more new
entities in the viewed directory. The directory implementation of this
method delegates to
DirectoryDelegate.copyFromEntity(EntityImplementation, String, boolean, List, EntityLock[])
after validating the target directory.
copyFrom
in interface DirectoryViewImplementation
ent
- The entity to copy from.targetName
- The name of the new entity.preserveAttrs
- Should entity attributes be copied to the target
entity?asl
- A list of EntityAttributeSetter
objects that are run
just after the target entity has been created, before the setupLocks
are released. May be null
. This may only be non-
null
if preserveAttrs
is true
.setupLocks
- Locks required for setting up the target entity. The
locks are released when the target entity has been created. It is the
responsibility of this method to unlock the lock (once), even in case of
errors.
ViewCapable
entities inherit the
filter instances from this directory view.public EntityDelegate createChildDelegate(EntityType et, String name, Object data)
protected void deleteInternal()
AbstractEntityImpl
AbstractEntityImpl.delete()
after it has performed all
validity, access control and lock checks. Subclasses implement this to
call their delegate's delete
method.
deleteInternal
in class AbstractEntityImpl
public String toString()
AbstractEntityImpl
toString
in class AbstractEntityImpl
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |