org.apache.excalibur.store.impl
Class AbstractFilesystemStore

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

public abstract class AbstractFilesystemStore
extends AbstractReadWriteStore

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  File m_directoryFile
          The directory repository
protected  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, File directory)
           
protected  int countKeys(File directory)
           
protected  String decode(String filename)
          Inverse of encode exept it do not use path.
 Object deserializeObject(File file)
          This method deserializes an object from an input stream.
 String deserializeString(File file)
          Load a text file contents as a String.
protected  void doClear()
          Clear the Store of all elements
protected  boolean doContainsKey(Object key)
          Indicates if the given key is associated to a contained object.
protected  void doFree()
          Try to free some used memory.
protected  Object doGet(Object key)
          Get the File object associated with the given unique key name.
protected  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(Object key)
          Remove the object associated to the given key.
protected  void doStore(Object key, Object value)
          Store the given object in a persistent state.
protected  String encode(String s)
          Returns a String that uniquely identifies the object.
protected  File fileFromKey(Object key)
           
 void free()
          Frees some values of the data file.
 String getDirectoryPath()
          Returns the repository's full pathname
 String getFullFilename(File file)
          Get the complete filename corresponding to a (typically relative) File.
 Object getObject(Object key)
           
 String getString(Object key)
           
 void serializeObject(File file, Object object)
          This method serializes an object to an output stream.
 void serializeString(File file, String string)
          Dump a String to a text file.
 void setDirectory(File directory)
          Sets the repository's location
 void setDirectory(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
 

Field Detail

m_directoryFile

protected File m_directoryFile
The directory repository


m_directoryPath

protected volatile String m_directoryPath
Constructor Detail

AbstractFilesystemStore

public AbstractFilesystemStore()
Method Detail

setDirectory

public void setDirectory(String directory)
                  throws IOException
Sets the repository's location

Throws:
IOException

setDirectory

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

Throws:
IOException

getDirectoryPath

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


doGet

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

Specified by:
doGet in class AbstractReadWriteStore

doStore

protected void doStore(Object key,
                       Object value)
                throws 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:
IOException

doRemove

protected void doRemove(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(Object key)
Indicates if the given key is associated to a contained object.

Specified by:
doContainsKey in class AbstractReadWriteStore

doGetKeys

protected 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,
                       File directory)

countKeys

protected int countKeys(File directory)

fileFromKey

protected File fileFromKey(Object key)

getString

public String getString(Object key)
                 throws IOException
Throws:
IOException

free

public void free()
Description copied from class: AbstractReadWriteStore
Frees some values of the data file.

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 Object getObject(Object key)
                 throws IOException,
                        ClassNotFoundException
Throws:
IOException
ClassNotFoundException

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.


encode

protected String encode(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(File file,
                            String string)
                     throws IOException
Dump a String to a text file.

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

deserializeString

public String deserializeString(File file)
                         throws 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:
IOException - IO Error

serializeObject

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

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

deserializeObject

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

Parameters:
file - The input file
Returns:
The deserialized object
Throws:
IOException - IOError
ClassNotFoundException

getFullFilename

public String getFullFilename(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-2012 The Apache Software Foundation. All Rights Reserved.