org.apache.cocoon.components.store
Class FilesystemStore

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.components.store.FilesystemStore
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.parameters.Parameterizable, Store, org.apache.avalon.framework.thread.ThreadSafe

public final class FilesystemStore
extends org.apache.avalon.framework.logger.AbstractLoggable
implements Store, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.framework.thread.ThreadSafe

Stores objects on the filesystem: String objects as text files, all other objects are serialized.

Version:
CVS $Id: FilesystemStore.java,v 1.13 2002/03/08 04:09:59 vgritsenko Exp $
Author:
?, Vadim Gritsenko

Field Summary
protected  java.io.File cacheDir
           
protected  java.io.File directoryFile
          The directory repository
protected  java.lang.String directoryPath
           
protected  java.io.File workDir
           
 
Fields inherited from interface org.apache.cocoon.components.store.Store
PERSISTENT_CACHE, ROLE, TRANSIENT_CACHE
 
Constructor Summary
FilesystemStore()
           
 
Method Summary
protected  void addKeys(org.apache.cocoon.components.store.FilesystemStore.FSEnumeration enum, java.io.File directory)
           
 boolean containsKey(java.lang.Object key)
          Indicates if the given key is associated to a contained object.
 void contextualize(org.apache.avalon.framework.context.Context context)
           
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.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()
           
 java.lang.Object get(java.lang.Object key)
          Get the File object associated with the given unique key name.
 java.lang.String getDirectoryPath()
          Returns the repository's full pathname
 java.lang.Object getObject(java.lang.Object key)
           
 java.lang.String getString(java.lang.Object key)
           
 void hold(java.lang.Object key, java.lang.Object value)
          Holds the given object in a volatile state.
 java.util.Enumeration keys()
          Returns the list of stored files as an Enumeration of Files
 void parameterize(org.apache.avalon.framework.parameters.Parameters params)
           
 void remove(java.lang.Object key)
          Remove the object associated to the given key.
 void setDirectory(java.io.File directory)
          Sets the repository's location
 void setDirectory(java.lang.String directory)
          Sets the repository's location
 int size()
          Returns count of the objects in the store, or -1 if could not be obtained.
 void store(java.lang.Object key, java.lang.Object value)
          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
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workDir

protected java.io.File workDir

cacheDir

protected java.io.File cacheDir

directoryFile

protected java.io.File directoryFile
The directory repository

directoryPath

protected volatile java.lang.String directoryPath
Constructor Detail

FilesystemStore

public FilesystemStore()
Method Detail

setDirectory

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

contextualize

public void contextualize(org.apache.avalon.framework.context.Context context)
                   throws org.apache.avalon.framework.context.ContextException
Specified by:
contextualize in interface org.apache.avalon.framework.context.Contextualizable

parameterize

public void parameterize(org.apache.avalon.framework.parameters.Parameters params)
                  throws org.apache.avalon.framework.parameters.ParameterException
Specified by:
parameterize in interface org.apache.avalon.framework.parameters.Parameterizable

setDirectory

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

getDirectoryPath

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

get

public java.lang.Object get(java.lang.Object key)
Get the File object associated with the given unique key name.
Specified by:
get in interface Store

store

public void store(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:
store in interface Store

hold

public void hold(java.lang.Object key,
                 java.lang.Object value)
          throws java.io.IOException
Holds the given object in a volatile state.
Specified by:
hold in interface Store

remove

public void remove(java.lang.Object key)
Remove the object associated to the given key.
Specified by:
remove in interface Store

containsKey

public boolean containsKey(java.lang.Object key)
Indicates if the given key is associated to a contained object.
Specified by:
containsKey in interface Store

keys

public java.util.Enumeration keys()
Returns the list of stored files as an Enumeration of Files
Specified by:
keys in interface Store

size

public int size()
Returns count of the objects in the store, or -1 if could not be obtained.
Specified by:
size in interface Store

addKeys

protected void addKeys(org.apache.cocoon.components.store.FilesystemStore.FSEnumeration enum,
                       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

free

public void free()
Specified by:
free in interface Store

getObject

public java.lang.Object getObject(java.lang.Object key)
                           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

public 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.


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.