org.entityfs.cap.entityattrs.custom.metadata
Class MetadataCustomAttributesCapabilityProvider<T extends EntityAttributes>

java.lang.Object
  extended by org.entityfs.cap.entityattrs.custom.metadata.MetadataCustomAttributesCapabilityProvider<T>
All Implemented Interfaces:
CapabilityProvider, CapabilityProviderImplementation

public class MetadataCustomAttributesCapabilityProvider<T extends EntityAttributes>
extends Object
implements CapabilityProviderImplementation

This capability provider makes the entities in the file system (except for the root directory) support the ECEntityAttributes capability. Every directory has a named metadata file that by default is called entityattrs.dat that contains the entity attributes for all the directory's child entities. Exactly how entity attributes are stored in the metadata file depends on the implementation of ChildEntityAttributeManager used.

The file system is required to support some kind of ECNamedMetadata capability for its directories. The file system is also required to support the FSCRandomAccessFiles capability.

New entities are created with a set of default attributes created by an EntityType-specific factory object. See setDefaultAttributesFactories(Map). An optional EntityAttributesPreparer can be used to prepare attributes objects for new entities before they are stored.

If the setStoreAttributesLazily(boolean) is set, entity attributes are saved lazily once they differ from their default values. This requires that the default entity attributes factories creates default attributes that always have the same property values. If an EntityAttributesPreparer is set with setEntityAttributesPreparer(EntityAttributesPreparer), new attributes are never stored lazily.

When using this capability, make sure that the file system contents are not modified from anywhere else than through the file system and entity methods. If it is, that can leave this capability seriously confused about the file system state.

For generic information about EntityAttributes capabilities, see the ECEntityAttributes documentation.

The programmer's guide have an example showing how this capability can be used.

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

Field Summary
static String DEFAULT_ATTRIBUTES_FILE_NAME
          The default name of the entity attributes metadata file.
 
Constructor Summary
MetadataCustomAttributesCapabilityProvider()
           
 
Method Summary
 String getAttributesFileName()
           
 Class<T> getAttributesType()
           
 ChildEntityAttributeManagerFactory<T,? extends ChildEntityAttributeManager<T>> getChildEntityAttributeManagerFactory()
           
 Map<EntityType,ObjectFactory<? extends T>> getDefaultAttributesFactories()
          Get (a copy of) the map containing default attributes factories for each entity type.
 EntityAttributesPreparer<T> getEntityAttributesPreparer()
           
 boolean isReadOnlyFileSystemSupported()
           
 boolean isReadWriteFileSystemSupported()
           
 boolean isStoreAttributesLazily()
           
 AdapterFactory proxyAdapterFactory(AdapterFactory af, LogAdapterHolder lah)
          This is called to let the capability provider proxy the file system's adapter factory before the file system is created.
 FileSystemDelegate proxyFileSystemDelegate(FileSystemDelegate fsd, SupportObjects so, boolean readOnly)
          This is used when creating the file system to let the capability provider proxy the file system delegate.
 DirectoryDelegate proxyRootDirectoryDelegate(FileSystemImplementation fs, FileSystemDelegate fsd, DirectoryDelegate dd, LogAdapterHolder lah)
          This is used when creating a file system to let the capability provider proxy the root directory delegate.
 MetadataCustomAttributesCapabilityProvider<T> setAttributesFileName(String name)
          Set the name of the entity attributes metadata file.
 MetadataCustomAttributesCapabilityProvider<T> setAttributesType(Class<T> c)
          Set the concrete class of the attributes managed by this capability provider.
 MetadataCustomAttributesCapabilityProvider<T> setChildEntityAttributeManagerFactory(ChildEntityAttributeManagerFactory<T,? extends ChildEntityAttributeManager<T>> f)
          Set the factory used for creating ChildEntityAttributeManager objects, one per directory, in the file system.
 MetadataCustomAttributesCapabilityProvider<T> setDefaultAttributesFactories(Map<EntityType,? extends ObjectFactory<T>> m)
          Set the default attributes factories.
 MetadataCustomAttributesCapabilityProvider<T> setDefaultAttributesFactory(EntityType et, ObjectFactory<T> f)
          Set the default attributes factory for the specified entity type.
 MetadataCustomAttributesCapabilityProvider<T> setEntityAttributesPreparer(EntityAttributesPreparer<T> eap)
          Set an EntityAttributesPreparer that is used to prepare the entity attributes created by the default entity attributes factory (see setDefaultAttributesFactory(EntityType, ObjectFactory)) when a new entity has been created.
 MetadataCustomAttributesCapabilityProvider<T> setStoreAttributesLazily(boolean b)
          Should entity attributes be stored lazily, once they are modified from their default values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ATTRIBUTES_FILE_NAME

public static final String DEFAULT_ATTRIBUTES_FILE_NAME
The default name of the entity attributes metadata file.

See Also:
setAttributesFileName(String), Constant Field Values
Constructor Detail

MetadataCustomAttributesCapabilityProvider

public MetadataCustomAttributesCapabilityProvider()
Method Detail

setDefaultAttributesFactory

public MetadataCustomAttributesCapabilityProvider<T> setDefaultAttributesFactory(EntityType et,
                                                                                 ObjectFactory<T> f)
Set the default attributes factory for the specified entity type.

Parameters:
et - The entity type.
f - The default attributes factory.
Returns:
this
See Also:
setDefaultAttributesFactories(Map)

setDefaultAttributesFactories

public MetadataCustomAttributesCapabilityProvider<T> setDefaultAttributesFactories(Map<EntityType,? extends ObjectFactory<T>> m)
Set the default attributes factories.

Any previously set default attributes factories are discarded.

Parameters:
m - The mapping between entity types and attribute factories. The map should at least contain keys for the ETFile and ETDirectory entity types.
Returns:
this
See Also:
setDefaultAttributesFactory(EntityType, ObjectFactory)

getDefaultAttributesFactories

public Map<EntityType,ObjectFactory<? extends T>> getDefaultAttributesFactories()
Get (a copy of) the map containing default attributes factories for each entity type.

Returns:
A copy of the map containing default attributes factories for each entity type.

setAttributesFileName

public MetadataCustomAttributesCapabilityProvider<T> setAttributesFileName(String name)
Set the name of the entity attributes metadata file. If this is not set, the default name DEFAULT_ATTRIBUTES_FILE_NAME is used.

Parameters:
name - The name of the entity attributes metadata file. This must be a valid file name in this file system.
Returns:
this

getAttributesFileName

public String getAttributesFileName()

setEntityAttributesPreparer

public MetadataCustomAttributesCapabilityProvider<T> setEntityAttributesPreparer(EntityAttributesPreparer<T> eap)
Set an EntityAttributesPreparer that is used to prepare the entity attributes created by the default entity attributes factory (see setDefaultAttributesFactory(EntityType, ObjectFactory)) when a new entity has been created.

This is optional.

Parameters:
eap - The entity attributes preparer for new entities.
Returns:
this.

getEntityAttributesPreparer

public EntityAttributesPreparer<T> getEntityAttributesPreparer()

setChildEntityAttributeManagerFactory

public MetadataCustomAttributesCapabilityProvider<T> setChildEntityAttributeManagerFactory(ChildEntityAttributeManagerFactory<T,? extends ChildEntityAttributeManager<T>> f)
Set the factory used for creating ChildEntityAttributeManager objects, one per directory, in the file system.

Parameters:
f - The factory.
Returns:
this

getChildEntityAttributeManagerFactory

public ChildEntityAttributeManagerFactory<T,? extends ChildEntityAttributeManager<T>> getChildEntityAttributeManagerFactory()

setStoreAttributesLazily

public MetadataCustomAttributesCapabilityProvider<T> setStoreAttributesLazily(boolean b)
Should entity attributes be stored lazily, once they are modified from their default values. Using this requires that the default attributes factories always set the same property values on their created attributes objects.

Parameters:
b - Should attributes objects be stored lazily?
Returns:
this.

isStoreAttributesLazily

public boolean isStoreAttributesLazily()

setAttributesType

public MetadataCustomAttributesCapabilityProvider<T> setAttributesType(Class<T> c)
Set the concrete class of the attributes managed by this capability provider.

Parameters:
c - The attributes class
Returns:
this.

getAttributesType

public Class<T> getAttributesType()

proxyAdapterFactory

public AdapterFactory proxyAdapterFactory(AdapterFactory af,
                                          LogAdapterHolder lah)
Description copied from interface: CapabilityProviderImplementation
This is called to let the capability provider proxy the file system's adapter factory before the file system is created.

Specified by:
proxyAdapterFactory in interface CapabilityProviderImplementation
Parameters:
af - The adapter factory.
lah - The (future) file system's log adapter holder.
Returns:
The (future) file system's adapter factory, possibly proxied. If the adapter factory should not be proxied, return the supplied factory, never return null.

proxyFileSystemDelegate

public FileSystemDelegate proxyFileSystemDelegate(FileSystemDelegate fsd,
                                                  SupportObjects so,
                                                  boolean readOnly)
Description copied from interface: CapabilityProviderImplementation
This is used when creating the file system to let the capability provider proxy the file system delegate.

This method can check that all capabilities that the capability provider require in order to work are present in the FileSystemDelegate to proxy. If not, the method throws an FileSystemConfigurationException.

When this method is called, no owning FileSystemImplementation is created yet, so a call to FileSystemDelegate.getOwner() will return null.

Specified by:
proxyFileSystemDelegate in interface CapabilityProviderImplementation
Parameters:
fsd - The file system delegate to proxy.
so - The file system's support objects. Maybe useful for implementations of this method, maybe not.
readOnly - Is the file system read only?
Returns:
A file system delegate. Either a proxy of fsd or fsd itself. Never null.

proxyRootDirectoryDelegate

public DirectoryDelegate proxyRootDirectoryDelegate(FileSystemImplementation fs,
                                                    FileSystemDelegate fsd,
                                                    DirectoryDelegate dd,
                                                    LogAdapterHolder lah)
Description copied from interface: CapabilityProviderImplementation
This is used when creating a file system to let the capability provider proxy the root directory delegate. Most capability providers do this.

Specified by:
proxyRootDirectoryDelegate in interface CapabilityProviderImplementation
Parameters:
fs - The file system object.
fsd - The file system delegate created by CapabilityProviderImplementation.proxyFileSystemDelegate(FileSystemDelegate, SupportObjects, boolean) .
dd - The root directory delegate.
Returns:
A directory delegate. Either a proxy of dd or dd itself. Never null.

isReadOnlyFileSystemSupported

public boolean isReadOnlyFileSystemSupported()
Specified by:
isReadOnlyFileSystemSupported in interface CapabilityProviderImplementation
Returns:
true, always.

isReadWriteFileSystemSupported

public boolean isReadWriteFileSystemSupported()
Specified by:
isReadWriteFileSystemSupported in interface CapabilityProviderImplementation
Returns:
true, always.