org.apache.avalon.cornerstone.blocks.masterstore
Class AbstractFileRepository

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.cornerstone.blocks.masterstore.AbstractFileRepository
All Implemented Interfaces:
Configurable, Contextualizable, Initializable, LogEnabled, Repository, Serviceable
Direct Known Subclasses:
File_Persistent_Object_Repository, File_Persistent_Stream_Repository, XMLFilePersistentObjectRepository

public abstract class AbstractFileRepository
extends AbstractLogEnabled
implements Repository, Contextualizable, Serviceable, Configurable, Initializable

This an abstract class implementing functionality for creating a file-store.

Author:
Avalon Development Team

Field Summary
protected static int BYTE_MASK
           
protected static boolean DEBUG
           
protected static String HANDLED_URL
           
protected static char[] HEX_DIGITS
           
protected  File m_baseDirectory
           
protected  String m_destination
           
protected  String m_extension
           
protected  FilenameFilter m_filter
           
protected  String m_name
           
protected  String m_path
           
protected  ServiceManager m_serviceManager
           
 
Constructor Summary
AbstractFileRepository()
           
 
Method Summary
 void configure(Configuration configuration)
          Configuration of the component by the container.
 boolean containsKey(String key)
          Indicates if the given key is associated to a contained object.
 void contextualize(Context context)
          Contextualization of the component by the container during which the working home directory will be provided.
protected  AbstractFileRepository createChildRepository()
           
protected  String decode(String filename)
          Inverse of encode exept it do not use path.
protected  String encode(String key)
          Returns a String that uniquely identifies the object.
 Repository getChildRepository(String childName)
           
protected abstract  String getExtensionDecorator()
           
protected  File getFile(String key)
           
protected  InputStream getInputStream(String key)
           
protected  OutputStream getOutputStream(String key)
           
 void initialize()
          Initialization of the component by the container.
 Iterator list()
          Returns the list of used keys.
 void remove(String key)
          Remove the object associated to the given key.
 void service(ServiceManager serviceManager)
          Serviceing of the component by the container.
protected  void setDestination(String destination)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
See Also:
Constant Field Values

HANDLED_URL

protected static final String HANDLED_URL
See Also:
Constant Field Values

BYTE_MASK

protected static final int BYTE_MASK
See Also:
Constant Field Values

HEX_DIGITS

protected static final char[] HEX_DIGITS

m_path

protected String m_path

m_destination

protected String m_destination

m_extension

protected String m_extension

m_name

protected String m_name

m_filter

protected FilenameFilter m_filter

m_baseDirectory

protected File m_baseDirectory

m_serviceManager

protected ServiceManager m_serviceManager
Constructor Detail

AbstractFileRepository

public AbstractFileRepository()
Method Detail

getExtensionDecorator

protected abstract String getExtensionDecorator()

contextualize

public void contextualize(Context context)
                   throws ContextException
Contextualization of the component by the container during which the working home directory will be provided.

Specified by:
contextualize in interface Contextualizable
Parameters:
context - the supplied context object
Throws:
ContextException
Context Entry:
key="urn:avalon:home" type="java.io.File"

service

public void service(ServiceManager serviceManager)
             throws ServiceException
Serviceing of the component by the container. This implementation is somewhat suspect in that it does not declare any servicable dependencies.

Specified by:
service in interface Serviceable
Parameters:
serviceManager - a service manager
Throws:
ServiceException

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Configuration of the component by the container.

Specified by:
configure in interface Configurable
Parameters:
configuration - the configuration
Throws:
ConfigurationException - if a configuration error occurs

initialize

public void initialize()
                throws Exception
Initialization of the component by the container.

Specified by:
initialize in interface Initializable
Throws:
Exception - if a initialization stage error occurs

setDestination

protected void setDestination(String destination)
                       throws ConfigurationException
Throws:
ConfigurationException

createChildRepository

protected AbstractFileRepository createChildRepository()
                                                throws Exception
Throws:
Exception

getChildRepository

public Repository getChildRepository(String childName)
Specified by:
getChildRepository in interface Repository

getFile

protected File getFile(String key)
                throws IOException
Throws:
IOException

getInputStream

protected InputStream getInputStream(String key)
                              throws IOException
Throws:
IOException

getOutputStream

protected OutputStream getOutputStream(String key)
                                throws IOException
Throws:
IOException

remove

public void remove(String key)
Remove the object associated to the given key.


containsKey

public boolean containsKey(String key)
Indicates if the given key is associated to a contained object.


list

public Iterator list()
Returns the list of used keys.


encode

protected String encode(String key)
Returns a String that uniquely identifies the object. Note: since this method uses the Object.toString() method, it's up to the caller to make sure that this method doesn't change between different JVM executions (like it may normally happen). For this reason, it's highly recommended (even if not mandated) that Strings be used as keys.


decode

protected String decode(String filename)
Inverse of encode exept it do not use path. So decode(encode(s) - m_path) = s. In other words it returns a String that can be used as key to retive the record contained in the 'filename' file.



Copyright © Apache Software Foundation. All Rights Reserved.