org.gersteinlab.tyna.webapp.data
Class FileDataStore

java.lang.Object
  extended by org.gersteinlab.tyna.webapp.data.FileDataStore

public class FileDataStore
extends java.lang.Object

        This class is the agent for accessing data files.
        

Version:
1.0 (October 2, 2005) Change History: 1.0 - Initial version
Author:
Kevin Yuk-Lap Yip

Field Summary
protected  java.lang.String categoryDir
          The directory to store categories
protected  javax.servlet.ServletContext context
          The servlet context
protected  java.lang.String networkDir
          The directory to store networks
protected  java.util.Random rand
          A random number generator
protected  SecurityController sc
          Security controller
protected  javax.servlet.http.HttpSession session
          The current HTTP session
protected  java.lang.String tempDir
          The temp directory
 
Constructor Summary
FileDataStore(javax.servlet.ServletContext context, javax.servlet.http.HttpSession session)
          Default constructor.
 
Method Summary
 void deleteCategoryFile(int categoryId)
          Delete a cateogry file.
 void deleteNetworkFile(int networkId)
          Delete a network file.
protected  java.io.File getCategoryFile(int categoryId)
          Get a File object of a category.
 java.io.InputStream getCategoryInputStream(int categoryId)
          Get an input stream of a category.
 java.io.Reader getCategoryReader(int categoryId)
          Get a reader of a category.
protected  java.io.File getNetworkFile(int networkId)
          Get a File object of a network.
 java.io.InputStream getNetworkInputStream(int networkId)
          Get an input stream of a network.
 java.io.Reader getNetworkReader(int networkId)
          Get a reader of a network.
 java.io.File getTempFile(long tempId, java.lang.String suffix)
          Get a File object of an existing temporary file.
 long getTempFileId(java.lang.String suffix)
          Get the file ID of a new temporary file.
 java.io.InputStream getTempFileInputStream(long tempId, java.lang.String suffix)
          Get an input stream of a temporarily stored file.
 java.io.OutputStream getTempFileOutputStream(long tempId, java.lang.String suffix)
          Get an output stream of a temporarily stored file.
 java.io.Reader getTempFileReader(long tempId, java.lang.String suffix)
          Get a reader of a temporarily stored file.
 java.io.Writer getTempFileWriter(long tempId, java.lang.String suffix)
          Get a writer of a temporarily stored file.
 void storeCategoryPerm(long tempId, Category category)
          Store a category permanently.
 long storeCategoryTemp(java.io.InputStream dataSrc)
          Store a category temporarily.
 long storeCategoryTemp(java.io.Reader dataSrc)
          Store a category temporarily.
protected  void storeFile(java.io.InputStream dataSrc, java.io.File tgtFile)
          Store a file.
protected  void storeFile(java.io.Reader dataSrc, java.io.File tgtFile)
          Store a file.
 void storeNetworkFromObj(long tempId, Network network)
          Store a network from a serialized graph object.
 void storeNetworkPerm(long tempId, Network network)
          Store a network permanently.
 long storeNetworkTemp(java.io.InputStream dataSrc)
          Store a network temporarily.
 long storeNetworkTemp(java.io.Reader dataSrc)
          Store a network temporarily.
 long storeTempFile(java.io.InputStream dataSrc, java.lang.String suffix)
          Store a file temporarily.
 long storeTempFile(java.io.Reader dataSrc, java.lang.String suffix)
          Store a file temporarily.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected javax.servlet.ServletContext context
The servlet context


session

protected javax.servlet.http.HttpSession session
The current HTTP session


sc

protected SecurityController sc
Security controller


categoryDir

protected java.lang.String categoryDir
The directory to store categories


networkDir

protected java.lang.String networkDir
The directory to store networks


tempDir

protected java.lang.String tempDir
The temp directory


rand

protected java.util.Random rand
A random number generator

Constructor Detail

FileDataStore

public FileDataStore(javax.servlet.ServletContext context,
                     javax.servlet.http.HttpSession session)
              throws ConfigException
Default constructor. It reads the configurations from the configuration file.

Parameters:
context - The servlet context for locating the current directory
session - The current HTTP session
Throws:
ConfigException - If there is any problem in reading the configuration file
Method Detail

storeNetworkTemp

public long storeNetworkTemp(java.io.InputStream dataSrc)
                      throws java.io.IOException
Store a network temporarily. This method does not check the format of the network, but simply stores it.

Parameters:
dataSrc - The data source
Returns:
A temporarily ID for the network
Throws:
java.io.IOException - If any IO problem occurs when storing the data

storeNetworkTemp

public long storeNetworkTemp(java.io.Reader dataSrc)
                      throws java.io.IOException
Store a network temporarily. This method does not check the format of the network, but simply stores it.

Parameters:
dataSrc - The data source
Returns:
A temporarily ID for the network
Throws:
java.io.IOException - If any IO problem occurs when storing the data

storeNetworkPerm

public void storeNetworkPerm(long tempId,
                             Network network)
                      throws ConfigException,
                             GraphTypeException,
                             InputFormatException,
                             java.io.IOException,
                             java.sql.SQLException
Store a network permanently. This method checks the format, and stores the network only if the format is correct. If everything is ok, the temp file will be deleted.

Parameters:
tempId - The temporary network ID
network - The network to be stored
Throws:
ConfigException - If any problems occur due to invalid configuration
GraphTypeException - If the network is not consistent with the specified graph type
InputFormatException - If the network does not conform to the input format
java.io.IOException - If any IO problem occurs when storing the data
java.sql.SQLException - If any database related problem occurs

storeNetworkFromObj

public void storeNetworkFromObj(long tempId,
                                Network network)
                         throws ConfigException,
                                GraphTypeException,
                                InputFormatException,
                                java.io.IOException,
                                java.sql.SQLException
Store a network from a serialized graph object. This method checks the format, and stores the network only if the format is correct.

Parameters:
tempId - The temporary network ID
network - The network to be stored
Throws:
ConfigException - If any problems occur due to invalid configuration
GraphTypeException - If the network is not consistent with the specified graph type
InputFormatException - If the network does not conform to the input format
java.io.IOException - If any IO problem occurs when storing the data
java.sql.SQLException - If any database related problem occurs

getNetworkInputStream

public java.io.InputStream getNetworkInputStream(int networkId)
                                          throws java.io.IOException,
                                                 SecurityException
Get an input stream of a network.

Parameters:
networkId - The ID of the network
Returns:
The input strema
Throws:
java.io.IOException - If any IO problem occurs when storing the data
SecurityException - If the current user does not have the permission to read the network

getNetworkReader

public java.io.Reader getNetworkReader(int networkId)
                                throws java.io.IOException,
                                       SecurityException
Get a reader of a network.

Parameters:
networkId - The ID of the network
Returns:
The reader
Throws:
java.io.IOException - If any IO problem occurs when storing the data
SecurityException - If the current user does not have the permission to read the network

deleteNetworkFile

public void deleteNetworkFile(int networkId)
                       throws java.io.IOException,
                              SecurityException
Delete a network file.

Parameters:
networkId - The ID of the network
Throws:
java.io.IOException - If any IO problem occurs when deleting the network file
SecurityException - If the current user does not have the permission to delete the network file

storeCategoryTemp

public long storeCategoryTemp(java.io.InputStream dataSrc)
                       throws java.io.IOException
Store a category temporarily. This method does not check the format of the category, but simply stores it.

Parameters:
dataSrc - The data source
Returns:
A temporarily ID for the category
Throws:
java.io.IOException - If any IO problem occurs when storing the data

storeCategoryTemp

public long storeCategoryTemp(java.io.Reader dataSrc)
                       throws java.io.IOException
Store a category temporarily. This method does not check the format of the category, but simply stores it.

Parameters:
dataSrc - The data source
Returns:
A temporarily ID for the category
Throws:
java.io.IOException - If any IO problem occurs when storing the data

storeCategoryPerm

public void storeCategoryPerm(long tempId,
                              Category category)
                       throws java.io.IOException
Store a category permanently. In the current version it simply moves the temporary file to the permanent location.

Parameters:
tempId - The temporary network ID
category - The category to be stored
Throws:
java.io.IOException - If any IO problem occurs when storing the data

getCategoryInputStream

public java.io.InputStream getCategoryInputStream(int categoryId)
                                           throws java.io.IOException,
                                                  SecurityException
Get an input stream of a category.

Parameters:
categoryId - The ID of the category
Returns:
The input stream
Throws:
java.io.IOException - If any IO problem occurs when storing the data
SecurityException - If the current user does not have the permission to read the network

getCategoryReader

public java.io.Reader getCategoryReader(int categoryId)
                                 throws java.io.IOException,
                                        SecurityException
Get a reader of a category.

Parameters:
categoryId - The ID of the category
Returns:
The reader
Throws:
java.io.IOException - If any IO problem occurs when storing the data
SecurityException - If the current user does not have the permission to read the network

deleteCategoryFile

public void deleteCategoryFile(int categoryId)
                        throws java.io.IOException,
                               SecurityException
Delete a cateogry file.

Parameters:
categoryId - The ID of the category
Throws:
java.io.IOException - If any IO problem occurs when deleting the category file
SecurityException - If the current user does not have the permission to delete the category file

storeTempFile

public long storeTempFile(java.io.InputStream dataSrc,
                          java.lang.String suffix)
                   throws java.io.IOException
Store a file temporarily.

Parameters:
dataSrc - The data source
suffix - The suffix of the file
Returns:
A temporarily ID for the file
Throws:
java.io.IOException - If any IO problem occurs when storing the data

storeTempFile

public long storeTempFile(java.io.Reader dataSrc,
                          java.lang.String suffix)
                   throws java.io.IOException
Store a file temporarily.

Parameters:
dataSrc - The data source
suffix - The suffix of the file
Returns:
A temporarily ID for the file
Throws:
java.io.IOException - If any IO problem occurs when storing the data

getTempFileId

public long getTempFileId(java.lang.String suffix)
                   throws java.io.IOException
Get the file ID of a new temporary file.

Parameters:
suffix - The suffix of the file
Returns:
The file ID
Throws:
java.io.IOException - If any IO problem occurs when creating the temp file

getTempFile

public java.io.File getTempFile(long tempId,
                                java.lang.String suffix)
Get a File object of an existing temporary file.

Parameters:
tempId - The temporary ID of the file
suffix - The suffix of the file
Returns:
The File object

getTempFileInputStream

public java.io.InputStream getTempFileInputStream(long tempId,
                                                  java.lang.String suffix)
                                           throws java.io.IOException
Get an input stream of a temporarily stored file.

Parameters:
tempId - The ID of the file
Returns:
The input stream
Throws:
java.io.IOException - If any IO problem occurs when getting the stream

getTempFileReader

public java.io.Reader getTempFileReader(long tempId,
                                        java.lang.String suffix)
                                 throws java.io.IOException
Get a reader of a temporarily stored file.

Parameters:
tempId - The ID of the file
Returns:
The reader
Throws:
java.io.IOException - If any IO problem occurs when getting the reader

getTempFileOutputStream

public java.io.OutputStream getTempFileOutputStream(long tempId,
                                                    java.lang.String suffix)
                                             throws java.io.IOException
Get an output stream of a temporarily stored file.

Parameters:
tempId - The ID of the file
Returns:
The output stream
Throws:
java.io.IOException - If any IO problem occurs when getting the stream

getTempFileWriter

public java.io.Writer getTempFileWriter(long tempId,
                                        java.lang.String suffix)
                                 throws java.io.IOException
Get a writer of a temporarily stored file.

Parameters:
tempId - The ID of the file
Returns:
The writer
Throws:
java.io.IOException - If any IO problem occurs when getting the writer

getNetworkFile

protected java.io.File getNetworkFile(int networkId)
Get a File object of a network.

Parameters:
networkId - The ID of the network
Returns:
The File object

getCategoryFile

protected java.io.File getCategoryFile(int categoryId)
Get a File object of a category.

Parameters:
categoryId - The ID of the category
Returns:
The File object

storeFile

protected void storeFile(java.io.InputStream dataSrc,
                         java.io.File tgtFile)
                  throws java.io.IOException
Store a file.

Parameters:
dataSrc - The data source
tgtFile - The target file
Throws:
java.io.IOException - If any IO problem occurs

storeFile

protected void storeFile(java.io.Reader dataSrc,
                         java.io.File tgtFile)
                  throws java.io.IOException
Store a file.

Parameters:
dataSrc - The data source
tgtFile - The target file
Throws:
java.io.IOException - If any IO problem occurs