org.apache.james.repository.file
Class AbstractFileRepository

java.lang.Object
  extended by org.apache.james.repository.file.AbstractFileRepository
All Implemented Interfaces:
Configurable, LogEnabled, Repository
Direct Known Subclasses:
FilePersistentObjectRepository, FilePersistentStreamRepository

public abstract class AbstractFileRepository
extends Object
implements Repository, Configurable, LogEnabled

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


Field Summary
protected static int BYTE_MASK
           
protected static boolean DEBUG
           
protected static char[] HEX_DIGITS
           
protected  File m_baseDirectory
           
protected  String m_extension
           
protected  FilenameFilter m_filter
           
protected  String m_name
           
 
Constructor Summary
AbstractFileRepository()
           
 
Method Summary
 void configure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
           
 boolean containsKey(String key)
          Indicates if the given key is associated to a contained object
protected  AbstractFileRepository createChildRepository()
          Return a new instance of this class
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)
          Return the File Object which belongs to the given key
protected  InputStream getInputStream(String key)
          Return the InputStream which belongs to the given key
protected  org.slf4j.Logger getLogger()
           
protected  OutputStream getOutputStream(String key)
          Return the OutputStream which belongs to the given key
 void init()
           
 Iterator<String> list()
          Returns the list of used keys.
 void remove(String key)
          Remove the object associated to the given key.
protected  void setDestination(String destination)
          Set the destination for the repository
 void setFileSystem(FileSystem fileSystem)
           
 void setLog(org.slf4j.Logger logger)
           
 
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

BYTE_MASK

protected static final int BYTE_MASK
See Also:
Constant Field Values

HEX_DIGITS

protected static final char[] HEX_DIGITS

m_extension

protected String m_extension

m_name

protected String m_name

m_filter

protected FilenameFilter m_filter

m_baseDirectory

protected File m_baseDirectory
Constructor Detail

AbstractFileRepository

public AbstractFileRepository()
Method Detail

configure

public void configure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
               throws org.apache.commons.configuration.ConfigurationException
Specified by:
configure in interface Configurable
Throws:
org.apache.commons.configuration.ConfigurationException

setFileSystem

public void setFileSystem(FileSystem fileSystem)

setLog

public void setLog(org.slf4j.Logger logger)
Specified by:
setLog in interface LogEnabled

getLogger

protected org.slf4j.Logger getLogger()

getExtensionDecorator

protected abstract String getExtensionDecorator()

init

@PostConstruct
public void init()
          throws Exception
Throws:
Exception

setDestination

protected void setDestination(String destination)
                       throws org.apache.commons.configuration.ConfigurationException
Set the destination for the repository

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

createChildRepository

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

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

getChildRepository

public Repository getChildRepository(String childName)
Specified by:
getChildRepository in interface Repository
See Also:
Repository.getChildRepository(java.lang.String)

getFile

protected File getFile(String key)
                throws 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:
IOException - get thrown on IO error

getInputStream

protected InputStream getInputStream(String key)
                              throws 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:
IOException - get thrown on IO error

getOutputStream

protected OutputStream getOutputStream(String key)
                                throws 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:
IOException - get thrown on IO error

remove

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

Parameters:
key - the key to remove

containsKey

public boolean containsKey(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 Iterator<String> 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.

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 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 retrieve 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-2012 The Apache Software Foundation. All Rights Reserved.