org.apache.excalibur.store.impl
Class AbstractFilesystemStore

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.store.impl.AbstractReadWriteStore
          extended byorg.apache.excalibur.store.impl.AbstractFilesystemStore
All Implemented Interfaces:
Component, LogEnabled, Store, ThreadSafe

public abstract class AbstractFilesystemStore
extends AbstractReadWriteStore
implements Store, ThreadSafe

Stores objects on the filesystem: String objects as text files, all other objects are serialized. This class must be subclassed in order to set the directory the store should work on.

Version:
CVS $Id: AbstractFilesystemStore.java,v 1.4 2004/02/28 11:47:31 cziegeler Exp $
Author:
Avalon Development Team

Field Summary
protected  java.io.File m_directoryFile
          The directory repository
protected  java.lang.String m_directoryPath
           
 
Fields inherited from class org.apache.excalibur.store.impl.AbstractReadWriteStore
lock
 
Fields inherited from interface org.apache.excalibur.store.Store
PERSISTENT_STORE, ROLE, TRANSIENT_STORE
 
Constructor Summary
AbstractFilesystemStore()
           
 
Method Summary
protected  void addKeys(org.apache.excalibur.store.impl.AbstractFilesystemStore.FSEnumeration enumer, java.io.File directory)
           
protected  int countKeys(java.io.File directory)
           
protected  java.lang.String decode(java.lang.String filename)
          Inverse of encode exept it do not use path.
 java.lang.Object deserializeObject(java.io.File file)
          This method deserializes an object from an input stream.
 java.lang.String deserializeString(java.io.File file)
          Load a text file contents as a String.
protected  void doClear()
          Clear the Store of all elements
protected  boolean doContainsKey(java.lang.Object key)
          Indicates if the given key is associated to a contained object.
protected  void doFree()
          Try to free some used memory.
protected  java.lang.Object doGet(java.lang.Object key)
          Get the File object associated with the given unique key name.
protected  java.util.Enumeration doGetKeys()
          Returns the list of stored files as an Enumeration of Files
protected  int doGetSize()
          Returns count of the objects in the store, or -1 if could not be obtained.
protected  void doRemove(java.lang.Object key)
          Remove the object associated to the given key.
protected  void doStore(java.lang.Object key, java.lang.Object value)
          Store the given object in a persistent state.
protected  java.lang.String encode(java.lang.String s)
          Returns a String that uniquely identifies the object.
protected  java.io.File fileFromKey(java.lang.Object key)
           
 void free()
          Try to free some used memory.
 java.lang.String getDirectoryPath()
          Returns the repository's full pathname
 java.lang.String getFullFilename(java.io.File file)
          Get the complete filename corresponding to a (typically relative) File.
 java.lang.Object getObject(java.lang.Object key)
           
 java.lang.String getString(java.lang.Object key)
           
 void serializeObject(java.io.File file, java.lang.Object object)
          This method serializes an object to an output stream.
 void serializeString(java.io.File file, java.lang.String string)
          Dump a String to a text file.
 void setDirectory(java.io.File directory)
          Sets the repository's location
 void setDirectory(java.lang.String directory)
          Sets the repository's location
 
Methods inherited from class org.apache.excalibur.store.impl.AbstractReadWriteStore
clear, containsKey, get, getChildInstrumentables, getInstrumentableName, getInstruments, keys, remove, setInstrumentableName, size, store
 
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
 
Methods inherited from interface org.apache.excalibur.store.Store
clear, containsKey, get, keys, remove, size, store
 

Field Detail

m_directoryFile

protected java.io.File m_directoryFile
The directory repository


m_directoryPath

protected volatile java.lang.String m_directoryPath
Constructor Detail

AbstractFilesystemStore

public AbstractFilesystemStore()
Method Detail

setDirectory

public void setDirectory(java.lang.String directory)
                  throws java.io.IOException
Sets the repository's location

Throws:
java.io.IOException

setDirectory

public void setDirectory(java.io.File directory)
                  throws java.io.IOException
Sets the repository's location

Throws:
java.io.IOException

getDirectoryPath

public java.lang.String getDirectoryPath()
Returns the repository's full pathname


doGet

protected java.lang.Object doGet(java.lang.Object key)
Get the File object associated with the given unique key name.

Specified by:
doGet in class AbstractReadWriteStore

doStore

protected void doStore(java.lang.Object key,
                       java.lang.Object value)
                throws java.io.IOException
Store the given object in a persistent state. 1) Null values generate empty directories. 2) String values are dumped to text files 3) Object values are serialized

Specified by:
doStore in class AbstractReadWriteStore
Throws:
java.io.IOException

doRemove

protected void doRemove(java.lang.Object key)
Remove the object associated to the given key.

Specified by:
doRemove in class AbstractReadWriteStore

doClear

protected void doClear()
Clear the Store of all elements

Specified by:
doClear in class AbstractReadWriteStore

doContainsKey

protected boolean doContainsKey(java.lang.Object key)
Indicates if the given key is associated to a contained object.

Specified by:
doContainsKey in class AbstractReadWriteStore

doGetKeys

protected java.util.Enumeration doGetKeys()
Returns the list of stored files as an Enumeration of Files

Specified by:
doGetKeys in class AbstractReadWriteStore

doGetSize

protected int doGetSize()
Returns count of the objects in the store, or -1 if could not be obtained.

Specified by:
doGetSize in class AbstractReadWriteStore

addKeys

protected void addKeys(org.apache.excalibur.store.impl.AbstractFilesystemStore.FSEnumeration enumer,
                       java.io.File directory)

countKeys

protected int countKeys(java.io.File directory)

fileFromKey

protected java.io.File fileFromKey(java.lang.Object key)

getString

public java.lang.String getString(java.lang.Object key)
                           throws java.io.IOException
Throws:
java.io.IOException

free

public void free()
Description copied from interface: Store
Try to free some used memory. The transient store can simply remove some hold data, the persistent store can free all memory by writing the data to a persistent store etc.

Specified by:
free in interface Store
Overrides:
free in class AbstractReadWriteStore

doFree

protected void doFree()
Description copied from class: AbstractReadWriteStore
Try to free some used memory. The transient store can simply remove some hold data, the persistent store can free all memory by writing the data to a persistent store etc.

Specified by:
doFree in class AbstractReadWriteStore

getObject

public java.lang.Object getObject(java.lang.Object key)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

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.


encode

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


serializeString

public void serializeString(java.io.File file,
                            java.lang.String string)
                     throws java.io.IOException
Dump a String to a text file.

Parameters:
file - The output file
string - The string to be dumped
Throws:
java.io.IOException - IO Error

deserializeString

public java.lang.String deserializeString(java.io.File file)
                                   throws java.io.IOException
Load a text file contents as a String. This method does not perform enconding conversions

Parameters:
file - The input file
Returns:
The file contents as a String
Throws:
java.io.IOException - IO Error

serializeObject

public void serializeObject(java.io.File file,
                            java.lang.Object object)
                     throws java.io.IOException
This method serializes an object to an output stream.

Parameters:
file - The output file
object - The object to be serialized
Throws:
java.io.IOException - IOError

deserializeObject

public java.lang.Object deserializeObject(java.io.File file)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
This method deserializes an object from an input stream.

Parameters:
file - The input file
Returns:
The deserialized object
Throws:
java.io.IOException - IOError
java.lang.ClassNotFoundException

getFullFilename

public java.lang.String getFullFilename(java.io.File file)
Get the complete filename corresponding to a (typically relative) File. This method accounts for the possibility of an error in getting the filename's canonical path, returning the io/error-safe absolute form instead

Parameters:
file - The file
Returns:
The file's absolute filename


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.