org.entityfs.impl.impl
Class AbstractFileSystem

java.lang.Object
  extended by org.entityfs.impl.impl.AbstractFileSystem
All Implemented Interfaces:
Observable, FileSystem, FileSystemImplementation
Direct Known Subclasses:
ROFileSystemImpl, RWFileSystemImpl

public abstract class AbstractFileSystem
extends Object
implements FileSystemImplementation

This is an abstract base class for FileSystem implementations.

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

Constructor Summary
protected AbstractFileSystem(String name, SupportObjects fso, FileSystemDelegate fsd)
           
 
Method Summary
 void addObserver(EntityObserver obs)
          Add an observer.
 void close()
          Delegates to the FileSystemAdapter.
 int countObservers()
          Count the number of currently listening observers.
 void deleteObserver(EntityObserver obs)
          Deregister the observer.
 void deleteObservers()
          Deregisters all observers.
protected  void finalize()
           
 AccessController getAccessController()
          Get the file system's access controller.
 int getBufferSize()
          Get the buffer size configured when creating the file system.
<T extends FileSystemCapability>
T
getCapability(FileSystemCapabilityType<T> t)
          Get a supported FileSystemCapability.
<T extends EntityCapability>
T
getCapabilityForEntity(EntityView ev, EntityCapabilityType<T> type)
          Get a supported EntityCapability for an Entity (or an entity viewed by an EntityView.
 FileSystemDelegate getDelegate()
          Get the file system delegate.
 EventManager getEventManager()
          Get this file system's event manager.
 FileSystemAdapter getFileSystemAdapter()
          Get the backend adapter for this file system.
 LockAcquiringStrategy getLockAcquiringStrategy()
          Get the file system's lock acquiring strategy object.
 EntityLockAdapterFactory getLockAdapterFactory()
          Get the file system's lock adapter factory.
 LockCommandExecutor getLockCommandExecutor()
          Get the file system's lock command executor.
 LogAdapter getLogAdapter()
          Convenient alternative to calling getLogAdapterHolder().getLogAdapter().
 LogAdapterHolder getLogAdapterHolder()
          Get the file system's current LogAdapterHolder.
 String getName()
          Get the file system's name.
 List<EntityObserver> getObserverList()
          Get the list of EntityObserver:s that are registered for this file system object.
 Directory getRootDirectory()
          Get the file system's root directory.
 Set<FileSystemCapabilityType<?>> getSupportedCapabilities()
          Get the set of all supported file system capability types for this file system.
 Set<EntityCapabilityType<?>> getSupportedEntityCapabilities()
          Get the set of all supported entity capability types for this file system.
 SupportObjects getSupportObjects()
          Get this file system's support objects.
 Directory getTemporaryFilesDirectory()
          Get the directory where this file system keeps its temporary files.
 void init()
          This method calls init on the file system delegate.
 boolean isAccessControlling()
          Does the file system use any kind of access controls?
 void setLogAdapter(LogAdapter logAdapter)
           
 void setRootDirectory(DirectoryImplementation di)
          Set the file system's root directory.
 void setTemporaryFilesDirectory(Directory d)
          Set the directory where this file system keeps its temporary files.
 boolean supportsCapability(FileSystemCapabilityType<?> cap)
          Check if the file system supports a specific FileSystemCapability .
 boolean supportsCapabilityForEntity(EntityView ev, EntityCapabilityType<?> type)
          Check if an Entity (or an entity viewed by an EntityView supports a specific EntityCapability.
 boolean supportsCapabilityForEntityType(EntityType et, EntityCapabilityType<?> type)
          Check if a entity type supports a capability type in this file system.
 String toString()
          This method delegates to ...
 void validateEntityName(String name, EntityType et)
          Default validation implementation.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.entityfs.FileSystem
isLocking, isReadOnly, setReadOnly
 

Constructor Detail

AbstractFileSystem

protected AbstractFileSystem(String name,
                             SupportObjects fso,
                             FileSystemDelegate fsd)
Method Detail

init

public void init()
This method calls init on the file system delegate. Be sure to call super.init() if overriding this method.

Specified by:
init in interface FileSystemImplementation

setRootDirectory

public void setRootDirectory(DirectoryImplementation di)
Description copied from interface: FileSystemImplementation
Set the file system's root directory. This is called when the file system is created.

Specified by:
setRootDirectory in interface FileSystemImplementation
Parameters:
di - The root directory.

setTemporaryFilesDirectory

public void setTemporaryFilesDirectory(Directory d)
Description copied from interface: FileSystem
Set the directory where this file system keeps its temporary files. This is optional.

Specified by:
setTemporaryFilesDirectory in interface FileSystem
Parameters:
d - The Directory for temporary files. The directory must be in this file system.
See Also:
FileSystem.getTemporaryFilesDirectory()

getTemporaryFilesDirectory

public Directory getTemporaryFilesDirectory()
Description copied from interface: FileSystem
Get the directory where this file system keeps its temporary files. The directory must have been set with a call to FileSystem.setTemporaryFilesDirectory(Directory) before calling this method.

Specified by:
getTemporaryFilesDirectory in interface FileSystem
Returns:
The directory for temporary files, or null if it has not been set.

getDelegate

public FileSystemDelegate getDelegate()
Description copied from interface: FileSystemImplementation
Get the file system delegate.

Specified by:
getDelegate in interface FileSystemImplementation
Returns:
The file system delegate.

getFileSystemAdapter

public FileSystemAdapter getFileSystemAdapter()
Description copied from interface: FileSystemImplementation
Get the backend adapter for this file system. This should only be used by those wanting to short circuit the file system delegates and knows what adapter implementation that they can expect here. (I.e. other file system delegates and perhaps some capability providers.) Use on own risk...

Specified by:
getFileSystemAdapter in interface FileSystemImplementation
Returns:
The file system adapter.

addObserver

public void addObserver(EntityObserver obs)
Description copied from interface: Observable
Add an observer.

Specified by:
addObserver in interface Observable
Parameters:
obs - The new observer.

deleteObserver

public void deleteObserver(EntityObserver obs)
Description copied from interface: Observable
Deregister the observer.

Specified by:
deleteObserver in interface Observable
Parameters:
obs - The observer to deregister. If the observer is not listening to this observable, this method does nothing.

deleteObservers

public void deleteObservers()
Description copied from interface: Observable
Deregisters all observers.

Specified by:
deleteObservers in interface Observable

countObservers

public int countObservers()
Description copied from interface: Observable
Count the number of currently listening observers.

Specified by:
countObservers in interface Observable
Returns:
The number of observers.

getObserverList

public List<EntityObserver> getObserverList()
Description copied from interface: FileSystemImplementation
Get the list of EntityObserver:s that are registered for this file system object. The returned list should be immutable.

Specified by:
getObserverList in interface FileSystemImplementation
Returns:
The list of registered EntityObserver:s.

getName

public String getName()
Description copied from interface: FileSystem
Get the file system's name. The file system name is a unique identifier that may be set by the client when creating the file system. This can for instance be used to tell different {link FileSystem} instances apart when registering JMX MBeans for the file system.

Specified by:
getName in interface FileSystem
Returns:
The file system name. If set, it should be unique within the current system (JVM, application server cluster, etc.).

isAccessControlling

public boolean isAccessControlling()
Description copied from interface: FileSystem
Does the file system use any kind of access controls?

Specified by:
isAccessControlling in interface FileSystem
Returns:
true if the file system is access controlling, false if not.

getLogAdapterHolder

public LogAdapterHolder getLogAdapterHolder()
Description copied from interface: FileSystem
Get the file system's current LogAdapterHolder.

Specified by:
getLogAdapterHolder in interface FileSystem
Returns:
The file system's LogAdapterHolder.
See Also:
FileSystem.getLogAdapter()

getLockAdapterFactory

public EntityLockAdapterFactory getLockAdapterFactory()
Description copied from interface: FileSystem
Get the file system's lock adapter factory. Clients can use this to create their own LockAdapter:s for their own locking.

Specified by:
getLockAdapterFactory in interface FileSystem
Returns:
The file system's lock adapter factory.

getLockAcquiringStrategy

public LockAcquiringStrategy getLockAcquiringStrategy()
Description copied from interface: FileSystem
Get the file system's lock acquiring strategy object. Clients can use this to acquire locks in the same way as the file system.

Specified by:
getLockAcquiringStrategy in interface FileSystem
Returns:
The file system's lock acquiring strategy.

getSupportObjects

public SupportObjects getSupportObjects()
Description copied from interface: FileSystemImplementation
Get this file system's support objects.

Specified by:
getSupportObjects in interface FileSystemImplementation
Returns:
This file system's support objects.

getLogAdapter

public LogAdapter getLogAdapter()
Description copied from interface: FileSystem
Convenient alternative to calling getLogAdapterHolder().getLogAdapter().

The LogAdapter returned from this method should not be saved by the client. (Not for a long time, anyway.) Save the file system's LogAdapterHolder instead or let the client call getLogAdapter() every time it wants to log.

Specified by:
getLogAdapter in interface FileSystem
Returns:
The current LogAdapter.
See Also:
FileSystem.getLogAdapterHolder()

getAccessController

public AccessController getAccessController()
Description copied from interface: FileSystem
Get the file system's access controller.

Specified by:
getAccessController in interface FileSystem
Returns:
The file system's access controller, or DisabledAccessController.INSTANCE if access controls are disabled.

getLockCommandExecutor

public LockCommandExecutor getLockCommandExecutor()
Description copied from interface: FileSystem
Get the file system's lock command executor. The lock command executor can be used to acquire locks for several entities at once in a way that is compliant with the executor's locking strategy.

This is used, for instance, by utility classes to acquire locks required for access control checks and other operations.

The default LockCommandExecutor implementation is LockCommandExecutorImpl. Some AccessController:s may require other implementations.

Specified by:
getLockCommandExecutor in interface FileSystem
Returns:
The file system's lock command executor.

getEventManager

public EventManager getEventManager()
Description copied from interface: FileSystemImplementation
Get this file system's event manager. This is used by entity implementations to fire events.

Specified by:
getEventManager in interface FileSystemImplementation
Returns:
This file system's event manager.

getBufferSize

public int getBufferSize()
Description copied from interface: FileSystem
Get the buffer size configured when creating the file system. The buffer size is used as the default size of temporary buffers used for various tasks such as for copying files (for some implementations). The default size is 4096 bytes.

Specified by:
getBufferSize in interface FileSystem
Returns:
The size of temporary buffers in bytes.

getRootDirectory

public Directory getRootDirectory()
Description copied from interface: FileSystem
Get the file system's root directory.

Specified by:
getRootDirectory in interface FileSystem
Returns:
The root directory.

setLogAdapter

public void setLogAdapter(LogAdapter logAdapter)

supportsCapability

public boolean supportsCapability(FileSystemCapabilityType<?> cap)
Description copied from interface: FileSystem
Check if the file system supports a specific FileSystemCapability . Capabilities are either supported directly by file system implementations or by CapabilityProvider:s given to the file system at creation time.

Specified by:
supportsCapability in interface FileSystem
Parameters:
cap - The capability's FileSystemCapabilityType.
Returns:
true if the file system supports the capability, false if not.
See Also:
FileSystem.getCapability(FileSystemCapabilityType)

getCapability

public <T extends FileSystemCapability> T getCapability(FileSystemCapabilityType<T> t)
Description copied from interface: FileSystem
Get a supported FileSystemCapability.

Specified by:
getCapability in interface FileSystem
Parameters:
t - The capability's FileSystemCapabilityType.
Returns:
The capability object.
See Also:
FileSystem.supportsCapability(FileSystemCapabilityType)

getSupportedCapabilities

public Set<FileSystemCapabilityType<?>> getSupportedCapabilities()
Description copied from interface: FileSystem
Get the set of all supported file system capability types for this file system.

Specified by:
getSupportedCapabilities in interface FileSystem
Returns:
The set of all supported file system capability types.

supportsCapabilityForEntity

public boolean supportsCapabilityForEntity(EntityView ev,
                                           EntityCapabilityType<?> type)
Description copied from interface: FileSystem
Check if an Entity (or an entity viewed by an EntityView supports a specific EntityCapability. Capabilities are either supported directly by file system implementations or by CapabilityProvider:s given to the file system at creation time.

Specified by:
supportsCapabilityForEntity in interface FileSystem
Parameters:
ev - The EntityView to check for.
type - The capability's EntityCapabilityType.
Returns:
true if the entity supports the capability, false if not.
See Also:
FileSystem.getCapabilityForEntity(EntityView, EntityCapabilityType), FileSystem.supportsCapabilityForEntityType(EntityType, EntityCapabilityType), EntityView.supportsCapability(EntityCapabilityType)

supportsCapabilityForEntityType

public boolean supportsCapabilityForEntityType(EntityType et,
                                               EntityCapabilityType<?> type)
Description copied from interface: FileSystem
Check if a entity type supports a capability type in this file system. Capabilities are either supported directly by file system implementations or by CapabilityProvider:s given to the file system at creation time.

There may be exceptions to the result returned by this method for certain special entities (i.e. the root directory). For querying about capabilities of existing entities, use the EntityView.supportsCapability(EntityCapabilityType) method instead.

Specified by:
supportsCapabilityForEntityType in interface FileSystem
Parameters:
et - The entity type.
type - The entity capability type.
Returns:
true if the capability type is supported by the supplied entity type in this file systems. (There may be exceptions to that rule, however. See above.)
See Also:
FileSystem.supportsCapabilityForEntity(EntityView, EntityCapabilityType)

getCapabilityForEntity

public <T extends EntityCapability> T getCapabilityForEntity(EntityView ev,
                                                             EntityCapabilityType<T> type)
Description copied from interface: FileSystem
Get a supported EntityCapability for an Entity (or an entity viewed by an EntityView.

Specified by:
getCapabilityForEntity in interface FileSystem
Parameters:
ev - The EntityView to get the capability object for.
type - The capability's EntityCapabilityType.
Returns:
An EntityCapability object for the Entity.
See Also:
FileSystem.supportsCapabilityForEntity(EntityView, EntityCapabilityType), EntityView.getCapability(EntityCapabilityType)

getSupportedEntityCapabilities

public Set<EntityCapabilityType<?>> getSupportedEntityCapabilities()
Description copied from interface: FileSystem
Get the set of all supported entity capability types for this file system.

Specified by:
getSupportedEntityCapabilities in interface FileSystem
Returns:
The set of all supported entity capability types for this file system.

validateEntityName

public void validateEntityName(String name,
                               EntityType et)
Default validation implementation. Subclasses may override this if necessary.

Specified by:
validateEntityName in interface FileSystemImplementation
Parameters:
name - The name to validate.
et - The type of the entity.

close

public void close()
Delegates to the FileSystemAdapter.

Specified by:
close in interface FileSystem

toString

public String toString()
This method delegates to ... the file system delegate.

Overrides:
toString in class Object

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable