gov.nih.nci.cagrid.introduce.servicetools
Class FilePersistenceHelper

java.lang.Object
  extended by gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper
Direct Known Subclasses:
XmlPersistenceHelper

public class FilePersistenceHelper
extends java.lang.Object

This helper contains common functions for managing persistent information stored as files.


Field Summary
protected  java.lang.Class beanClass
           
protected  java.lang.String fileSuffix
           
protected  java.io.File storageDir
           
 
Constructor Summary
FilePersistenceHelper(java.lang.Class beanClass, java.io.File storageDir, java.lang.String suffix)
          Creates FilePersistenceHelper with specific storage directory and file suffix.
FilePersistenceHelper(java.lang.Class beanClass, ServiceConfiguration configuration, java.lang.String suffix)
          Creates FilePersistenceHelper with default storage directory based on the beanClass name and specified suffix.
FilePersistenceHelper(java.lang.Class beanClass, java.lang.String storageDir, java.lang.String suffix)
          Creates FilePersistenceHelper with specific storage directory and file suffix.
 
Method Summary
static void createStorageDirectory(java.io.File dir)
          Ensures the directory specified exists, is readable and writeable.
 java.lang.Class getBeanClass()
           
static java.io.File getDefaultStorageDirectory(java.io.File baseDir, java.lang.Class beanClass)
           
 java.lang.String getFileSuffix()
           
 java.io.File getKeyAsFile(java.lang.Class clazz, java.lang.Object key)
          Create a file object based on the key supplied in parameter.
 java.io.File getStorageDirectory()
           
 java.util.List list()
          This function returns the keys of the objects that have been stored.
 void remove(java.lang.Class clazz, java.lang.Object key)
           
 void removeAll()
          Removes all stored objects from file system.
protected  void setStorageDirectory(java.io.File dir)
           
protected  void setStorageDirectory(java.lang.String strDir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beanClass

protected java.lang.Class beanClass

storageDir

protected java.io.File storageDir

fileSuffix

protected java.lang.String fileSuffix
Constructor Detail

FilePersistenceHelper

public FilePersistenceHelper(java.lang.Class beanClass,
                             ServiceConfiguration configuration,
                             java.lang.String suffix)
                      throws java.io.IOException
Creates FilePersistenceHelper with default storage directory based on the beanClass name and specified suffix.

Throws:
java.io.IOException

FilePersistenceHelper

public FilePersistenceHelper(java.lang.Class beanClass,
                             java.lang.String storageDir,
                             java.lang.String suffix)
                      throws java.io.IOException
Creates FilePersistenceHelper with specific storage directory and file suffix.

Throws:
java.io.IOException

FilePersistenceHelper

public FilePersistenceHelper(java.lang.Class beanClass,
                             java.io.File storageDir,
                             java.lang.String suffix)
                      throws java.io.IOException
Creates FilePersistenceHelper with specific storage directory and file suffix.

Throws:
java.io.IOException
Method Detail

getDefaultStorageDirectory

public static java.io.File getDefaultStorageDirectory(java.io.File baseDir,
                                                      java.lang.Class beanClass)
                                               throws java.io.IOException
Throws:
java.io.IOException

createStorageDirectory

public static void createStorageDirectory(java.io.File dir)
                                   throws java.io.IOException
Ensures the directory specified exists, is readable and writeable. If the directory does not exist it is created.

Parameters:
dir - the directory to create or check the permissions of
Throws:
java.io.IOException - if failed to create the directory or if the directory exists but has invalid permissions.

setStorageDirectory

protected void setStorageDirectory(java.lang.String strDir)
                            throws java.io.IOException
Throws:
java.io.IOException

setStorageDirectory

protected void setStorageDirectory(java.io.File dir)
                            throws java.io.IOException
Throws:
java.io.IOException

getStorageDirectory

public java.io.File getStorageDirectory()

getFileSuffix

public java.lang.String getFileSuffix()

getBeanClass

public java.lang.Class getBeanClass()

getKeyAsFile

public java.io.File getKeyAsFile(java.lang.Class clazz,
                                 java.lang.Object key)
Create a file object based on the key supplied in parameter. The file name will follow the format:

file name :== (class name)_(key scalar value).xml

where:


remove

public void remove(java.lang.Class clazz,
                   java.lang.Object key)
            throws org.globus.wsrf.ResourceException
Throws:
org.globus.wsrf.ResourceException

list

public java.util.List list()
                    throws java.lang.Exception
This function returns the keys of the objects that have been stored. This should be used by the home in order to recover state, by listing all the stored object keys and adding them to the map of resources. The consumer code must test for null.

Returns:
List the list of key values
Throws:
java.lang.Exception

removeAll

public void removeAll()
               throws java.lang.Exception
Removes all stored objects from file system.

Throws:
java.lang.Exception