org.apache.james.mailrepository.filepair
Class AbstractFileRepository

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.mailrepository.filepair.AbstractFileRepository
All Implemented Interfaces:
org.apache.avalon.cornerstone.services.store.Repository, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable
Direct Known Subclasses:
File_Persistent_Object_Repository, File_Persistent_Stream_Repository

public abstract class AbstractFileRepository
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.cornerstone.services.store.Repository, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable

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


Field Summary
protected static int BYTE_MASK
           
protected static boolean DEBUG
           
protected static java.lang.String HANDLED_URL
           
protected static char[] HEX_DIGITS
           
protected  java.io.File m_baseDirectory
           
protected  java.lang.String m_destination
           
protected  java.lang.String m_extension
           
protected  java.io.FilenameFilter m_filter
           
protected  java.lang.String m_name
           
protected  java.lang.String m_path
           
protected  org.apache.avalon.framework.service.ServiceManager m_serviceManager
           
 
Constructor Summary
AbstractFileRepository()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 boolean containsKey(java.lang.String key)
          Indicates if the given key is associated to a contained object
protected  AbstractFileRepository createChildRepository()
          Return a new instance of this class
protected  java.lang.String decode(java.lang.String filename)
          Inverse of encode exept it do not use path.
protected  java.lang.String encode(java.lang.String key)
          Returns a String that uniquely identifies the object.
 org.apache.avalon.cornerstone.services.store.Repository getChildRepository(java.lang.String childName)
           
protected abstract  java.lang.String getExtensionDecorator()
           
protected  java.io.File getFile(java.lang.String key)
          Return the File Object which belongs to the given key
protected  java.io.InputStream getInputStream(java.lang.String key)
          Return the InputStream which belongs to the given key
protected  java.io.OutputStream getOutputStream(java.lang.String key)
          Return the OutputStream which belongs to the given key
 void initialize()
           
 java.util.Iterator list()
          Returns the list of used keys.
 void remove(java.lang.String key)
          Remove the object associated to the given key.
 void service(org.apache.avalon.framework.service.ServiceManager serviceManager)
           
protected  void setDestination(java.lang.String destination)
          Set the destination for the repository
 
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 java.lang.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 java.lang.String m_path

m_destination

protected java.lang.String m_destination

m_extension

protected java.lang.String m_extension

m_name

protected java.lang.String m_name

m_filter

protected java.io.FilenameFilter m_filter

m_baseDirectory

protected java.io.File m_baseDirectory

m_serviceManager

protected org.apache.avalon.framework.service.ServiceManager m_serviceManager
Constructor Detail

AbstractFileRepository

public AbstractFileRepository()
Method Detail

getExtensionDecorator

protected abstract java.lang.String getExtensionDecorator()

service

public void service(org.apache.avalon.framework.service.ServiceManager serviceManager)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
Serviceable.service(ServiceManager)

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

initialize

public void initialize()
                throws java.lang.Exception
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception
See Also:
Initializable.initialize()

setDestination

protected void setDestination(java.lang.String destination)
                       throws org.apache.avalon.framework.configuration.ConfigurationException
Set the destination for the repository

Parameters:
destination - the destination under which the repository get stored
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - get thrown on invalid destintion syntax

createChildRepository

protected AbstractFileRepository createChildRepository()
                                                throws java.lang.Exception
Return a new instance of this class

Returns:
class a new instance of AbstractFileRepository
Throws:
java.lang.Exception - get thrown if an error is detected while create the new instance

getChildRepository

public org.apache.avalon.cornerstone.services.store.Repository getChildRepository(java.lang.String childName)
Specified by:
getChildRepository in interface org.apache.avalon.cornerstone.services.store.Repository
See Also:
Repository.getChildRepository(String)

getFile

protected java.io.File getFile(java.lang.String key)
                        throws java.io.IOException
Return the File Object which belongs to the given key

Parameters:
key - the key for which the File get returned
Returns:
file the File associted with the given Key
Throws:
java.io.IOException - get thrown on IO error

getInputStream

protected java.io.InputStream getInputStream(java.lang.String key)
                                      throws java.io.IOException
Return the InputStream which belongs to the given key

Parameters:
key - the key for which the InputStream get returned
Returns:
in the InputStram associted with the given key
Throws:
java.io.IOException - get thrown on IO error

getOutputStream

protected java.io.OutputStream getOutputStream(java.lang.String key)
                                        throws java.io.IOException
Return the OutputStream which belongs to the given key

Parameters:
key - the key for which the OutputStream get returned
Returns:
out the OutputStream
Throws:
java.io.IOException - get thrown on IO error

remove

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

Parameters:
key - the key to remove

containsKey

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

Parameters:
key - the key which checked for
Returns:
true if the repository contains the key

list

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


encode

protected java.lang.String encode(java.lang.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.

Parameters:
key - the key for which the Object should be searched
Returns:
result a unique String represent the Object which belongs to the key

decode

protected java.lang.String decode(java.lang.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.

Parameters:
filename - the filename for which the key should generated
Returns:
key a String which can be used to retrieve the filename


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.