org.entityfs.impl.adapter
Interface EntityAdapter

All Known Subinterfaces:
ChildRegisteringDirectoryAdapter, DirectoryAdapter, FileAdapter, SymbolicLinkAdapter, ZipEntityAdapter
All Known Implementing Classes:
AbstractRamEntityAdapter, AbstractROEntityAdapter, AbstractRWEntityAdapter, RamDirectoryAdapter, RamFileAdapter, RamSymbolicLinkAdapter, ZipDirectoryAdapter, ZipFileAdapter

public interface EntityAdapter

This is the base interface for an entity adapter. Entity adapters are used by file system implementations to access entities in the backend implementation.

Entity adapters should not use any synchronization. That is the responsibility of the file system implementation layer.

Entity adapter implementations should be careful with caching data. Especially they should not cache any data that assumes any particular location in the backend file system. Entity adapters (and the entities themselves) are not notified when a parent entity is moved.

If the same entity adapter implementations are used for both read/write and read only entities, the entity adapters do not have to check for write access when writing to an entity. That is a responsibility of the file system implementation layer.

The methods in this interface should only be used by file system and capability implementations.

Unlike EntityDelegate:s, entity adapters must never be proxied. Clients should always be able to assume a specific implementation, if they have reason to know about it. For instance, a capability implementation that is specific for a file system implementation must always be able to cast an entity adapter to that file system's implementation of it.

Once it is created, an entity adapter is tied to and reused by its parent entity object. For a file system implementation that uses persistent data in some backend (i.e. does not store any file system data in memory only), the entity object may be garbage collected if it is not actively used. The next time the entity is created, a new entity adapter will also be created. See the discussion in DirectoryAdapter for more information.

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

Method Summary
 boolean canRead()
          Check if the entity can be read from the backend.
 boolean canWrite()
          Check if the entity can be written to in the backend.
 void create()
          Create the backend representation for this entity adapter.
 void delete()
          Delete the entity from the underlying file system.
 boolean exists()
          Check that the entity exists in the backend.
 EntityType getEntityType()
          Get the EntityType for this entity.
 FileSystemAdapter getFileSystemAdapter()
          Get the FileSystemAdapter for the file system where the entity is.
 long getLastModified()
          Get the last modification time for an entity.
 String getName()
          Get the name of the entity.
 DirectoryAdapter getParent()
          Get the parent DirectoryAdapter.
 void init()
          This is called after the entity adapter object and all its dependencies have been created, but before the entity object is published.
 void rename(String newName, DirectoryAdapter newParent)
          Move and/or rename the entity.
 void setLastModified(long time)
          Set the entity's last modification time.
 

Method Detail

init

void init()
This is called after the entity adapter object and all its dependencies have been created, but before the entity object is published.


exists

boolean exists()
Check that the entity exists in the backend. Some EntityValidityControlStrategy:s call this often, so make sure that the implementation is efficient.

Returns:
true if the entity exists.

getName

String getName()
Get the name of the entity.

Returns:
The entity's name.

getFileSystemAdapter

FileSystemAdapter getFileSystemAdapter()
Get the FileSystemAdapter for the file system where the entity is.

Returns:
The entity adapter's FileSystemAdapter.

canRead

boolean canRead()
Check if the entity can be read from the backend.

Returns:
true if the entity can be read.

canWrite

boolean canWrite()
Check if the entity can be written to in the backend.

Returns:
true if the entity can be written to.

getParent

DirectoryAdapter getParent()
Get the parent DirectoryAdapter.

Returns:
The parent DirectoryAdapter.

getLastModified

long getLastModified()
Get the last modification time for an entity.

Returns:
The last modification time for an entity.

setLastModified

void setLastModified(long time)
Set the entity's last modification time.

Parameters:
time - The new last modification time.

create

void create()
            throws FileSystemException
Create the backend representation for this entity adapter. (New file, new directory, new symbolic link, etc.)

Throws:
FileSystemException - On errors.

delete

void delete()
            throws FileSystemException
Delete the entity from the underlying file system.

This method is also responsible for calling ChildRegisteringDirectoryAdapter.unregisterChild(EntityAdapter) on its parent directory.

Throws:
FileSystemException - On errors.

rename

void rename(String newName,
            DirectoryAdapter newParent)
Move and/or rename the entity.

Parameters:
newName - The entity's new name.
newParent - The entity adapter's new parent. This is the same as the old parent if the entity is only renamed.

getEntityType

EntityType getEntityType()
Get the EntityType for this entity.

Returns:
The EntityType for this entity.