org.entityfs.ram
Class RamDirectoryAdapter

java.lang.Object
  extended by org.entityfs.impl.impl.adapter.AbstractRWEntityAdapter<RamFileSystemAdapter,RamDirectoryAdapter>
      extended by org.entityfs.ram.AbstractRamEntityAdapter
          extended by org.entityfs.ram.RamDirectoryAdapter
All Implemented Interfaces:
ChildRegisteringDirectoryAdapter, DirectoryAdapter, EntityAdapter

public final class RamDirectoryAdapter
extends AbstractRamEntityAdapter
implements ChildRegisteringDirectoryAdapter

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-ram

Constructor Summary
RamDirectoryAdapter(RamFileSystemAdapter fs, RamDirectoryAdapter parent, String name)
           
 
Method Summary
 void assertCanBeDeleted(Collection<String> cetd)
          Override the inherited implementation and add the check to see if the directory is empty.
 boolean containsEntity(String name)
          Check if the directory contains an entity with the given name (case sensitive or insensitive depending on the file system).
 void deleteChild(String name)
          Delete the named child.
 EntityAdapter getChild(String name)
          Get the adapter for a child entity.
 EntityType getChildEntityType(String name)
          Get the type of the child entity with the given name,
 String[] getEntityNames()
          Get an array with the names of all child entities.
 EntityType getEntityType()
          Get the EntityType for this entity.
 T getFileSystemAdapter()
          Get the FileSystemAdapter for the file system where the entity is.
 void init()
          This implementation does nothing.
 void registerChild(EntityAdapter ea)
          This is used by directory adapters that have to keep track of child entities themselves (the RAM file system directory adapters, for instance).
 String toString()
           
 void unregisterChild(EntityAdapter ea)
          For directory adapters that keep track of all child entities themselves, this method is used to unregister a child entity that is deleted or moved from the directory.
 
Methods inherited from class org.entityfs.ram.AbstractRamEntityAdapter
canRead, canWrite, create, delete, exists, getLastModified, rename, setLastModified
 
Methods inherited from class org.entityfs.impl.impl.adapter.AbstractRWEntityAdapter
getName, getParent, setName, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.entityfs.impl.adapter.EntityAdapter
canRead, canWrite, create, delete, exists, getFileSystemAdapter, getLastModified, getName, getParent, init, rename, setLastModified
 

Constructor Detail

RamDirectoryAdapter

public RamDirectoryAdapter(RamFileSystemAdapter fs,
                           RamDirectoryAdapter parent,
                           String name)
Parameters:
parent -
name -
Method Detail

containsEntity

public boolean containsEntity(String name)
Description copied from interface: DirectoryAdapter
Check if the directory contains an entity with the given name (case sensitive or insensitive depending on the file system).

Specified by:
containsEntity in interface DirectoryAdapter
Parameters:
name - The name of the entity.
Returns:
true if the directory contains the named entity, false otherwise.

getChildEntityType

public EntityType getChildEntityType(String name)
Description copied from interface: DirectoryAdapter
Get the type of the child entity with the given name,

Specified by:
getChildEntityType in interface DirectoryAdapter
Parameters:
name - The name of the entity.
Returns:
The EntityType, or null if no such entity exists.

getEntityNames

public String[] getEntityNames()
Description copied from interface: DirectoryAdapter
Get an array with the names of all child entities.

Specified by:
getEntityNames in interface DirectoryAdapter
Returns:
An array with the names of all child entities. If the directory is empty, an empty array is returned.

assertCanBeDeleted

public void assertCanBeDeleted(Collection<String> cetd)
Override the inherited implementation and add the check to see if the directory is empty.

Specified by:
assertCanBeDeleted in interface DirectoryAdapter
Parameters:
cetd - The names of child entities to delete before deleting the directory. This may be null.

registerChild

public void registerChild(EntityAdapter ea)
Description copied from interface: ChildRegisteringDirectoryAdapter
This is used by directory adapters that have to keep track of child entities themselves (the RAM file system directory adapters, for instance).

This method is called by the directory entity implementation when a new entity is created or an existing entity is found.

Specified by:
registerChild in interface ChildRegisteringDirectoryAdapter
Parameters:
ea - The child entity adapter to register.
See Also:
ChildRegisteringDirectoryAdapter.unregisterChild(EntityAdapter), ChildRegisteringDirectoryAdapter.getChild(String)

unregisterChild

public void unregisterChild(EntityAdapter ea)
Description copied from interface: ChildRegisteringDirectoryAdapter
For directory adapters that keep track of all child entities themselves, this method is used to unregister a child entity that is deleted or moved from the directory.

This method should be called by entity adapter methods that move or delete entities.

Specified by:
unregisterChild in interface ChildRegisteringDirectoryAdapter
Parameters:
ea - The child to unregister.
See Also:
ChildRegisteringDirectoryAdapter.registerChild(EntityAdapter), ChildRegisteringDirectoryAdapter.getChild(String), EntityAdapter.delete(), EntityAdapter.rename(String, DirectoryAdapter)

getChild

public EntityAdapter getChild(String name)
Description copied from interface: ChildRegisteringDirectoryAdapter
Get the adapter for a child entity. This can only be used on directory adapters that keep track of their child adapters.

Specified by:
getChild in interface ChildRegisteringDirectoryAdapter
Parameters:
name - The name of the child entity.
Returns:
The child entity adapter.
See Also:
ChildRegisteringDirectoryAdapter.registerChild(EntityAdapter), ChildRegisteringDirectoryAdapter.unregisterChild(EntityAdapter)

getEntityType

public EntityType getEntityType()
Description copied from interface: EntityAdapter
Get the EntityType for this entity.

Specified by:
getEntityType in interface EntityAdapter
Returns:
The EntityType for this entity.

deleteChild

public void deleteChild(String name)
Description copied from interface: DirectoryAdapter
Delete the named child. The caller is responsible for making sure that no entity adapters representing the deleted children will be used in the future.

If the named child entity does not exist, this method exits silently.

Specified by:
deleteChild in interface DirectoryAdapter
Parameters:
name - The name of the child to delete.

toString

public String toString()
Overrides:
toString in class Object

init

public void init()
This implementation does nothing. Override if necessary.

Specified by:
init in interface EntityAdapter

getFileSystemAdapter

public T getFileSystemAdapter()
Description copied from interface: EntityAdapter
Get the FileSystemAdapter for the file system where the entity is.

Specified by:
getFileSystemAdapter in interface EntityAdapter
Returns:
The entity adapter's FileSystemAdapter.