data
Class SerialManager

java.lang.Object
  extended by data.SerialManager

public class SerialManager
extends java.lang.Object

Low layer class to interact with the data in disk

Version:
1.0
Author:
Oscar Flores

Nested Class Summary
static class SerialManager.MyFilter
          It allows to create a custom FilenameFilter in an easy way
 
Field Summary
static java.lang.String PATH_MATRIX
          Path to the matrix folder (where they will be saved)
static java.lang.String PATH_WORKSPACE
          Path to the workspace folder (where they will be saved)
 
Constructor Summary
SerialManager()
           
 
Method Summary
static void deleteMatrix(java.lang.String filename)
          Deletes a Matrix from the library and Workspaces referencing it
static void deleteObject(java.lang.String fileName, java.lang.String filePath, java.lang.String fileExt)
          Deletes an object from the disk.
static void deleteWorkspace(java.lang.String filename)
          Deletes a Workspace from the saved ones
static void exportMatrix(java.lang.String matName, java.lang.String exportName, java.lang.String exportPath)
          Export a saved Matrix from the Matrix directory to another arbitrary directory
private static boolean fileExists(java.lang.String fileName, java.lang.String filePath, java.lang.String fileExt)
          Returns if a given file exists in the given path
private static java.lang.String[] getFileNames(java.lang.String filePath, java.lang.String fileExt)
          Return the names of the files with the given extension in the given path
static java.lang.String[] getMatrixNames()
          Retun the names of all Matrix in the Library
static java.lang.String[] getWorkspaceNames()
          Retun the names of all Workspace saved
static Matrix loadMatrix(java.lang.String filename)
          Return the Matrix previously saved with the given name
private static java.lang.Object loadObject(java.lang.String fileName, java.lang.String filePath, java.lang.String fileExt)
          Loads any object from disk.
static Workspace loadWorkspace(java.lang.String filename)
          Return the Workspace previously saved with the given name
static boolean matrixExists(java.lang.String matName)
          Returns if a Matrix with this name exists
static void saveMatrix(Matrix m, java.lang.String filename)
          Saves a matrix object with the given name
private static void saveObject(java.lang.Object o, java.lang.String fileName, java.lang.String dirPath, java.lang.String fileExt)
          Saves any object in disk.
static void saveWorkspace(Workspace w, java.lang.String filename)
          Saves a Workspace object with the given name
static java.lang.String updateMatrix(java.lang.String matName, java.lang.String newName, java.lang.String newDesc)
          Updates a saved Matrix attributes with the given ones
static boolean workspaceExists(java.lang.String wsName)
          Returns if a Workspace with this name exists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_MATRIX

public static final java.lang.String PATH_MATRIX
Path to the matrix folder (where they will be saved)


PATH_WORKSPACE

public static final java.lang.String PATH_WORKSPACE
Path to the workspace folder (where they will be saved)

Constructor Detail

SerialManager

public SerialManager()
Method Detail

saveObject

private static final void saveObject(java.lang.Object o,
                                     java.lang.String fileName,
                                     java.lang.String dirPath,
                                     java.lang.String fileExt)
                              throws DataException
Saves any object in disk. If the extension is not included in the filename, it will be added

Parameters:
o - Object to be saved
fileName - File's name
dirPath - Path (directory) where to save the file
fileExt - File's extension
Throws:
DataException

loadObject

private static final java.lang.Object loadObject(java.lang.String fileName,
                                                 java.lang.String filePath,
                                                 java.lang.String fileExt)
                                          throws DataException
Loads any object from disk. If the extension is not included in the filename, it will be added

Parameters:
fileName - Name of the object to be loaded
filePath - Path (directory structure) of the object to be loaded
fileExt - Extension of the loaded object
Returns:
true
Throws:
DataException

deleteObject

public static final void deleteObject(java.lang.String fileName,
                                      java.lang.String filePath,
                                      java.lang.String fileExt)
                               throws DataException
Deletes an object from the disk. It performs basic security checks. If the extension is not included in the filename, it will be added

Parameters:
fileName - Name of the file to be deleted
filePath - Path (directory structure) of the object to be deleted
fileExt - Extension of the object wich will be deleted
Throws:
DataException

getFileNames

private static final java.lang.String[] getFileNames(java.lang.String filePath,
                                                     java.lang.String fileExt)
Return the names of the files with the given extension in the given path

Parameters:
filePath - Path (folder route) which will be looked
fileExt - Desired file's extension
Returns:
Array with the names that fulfill the condition or null if none

fileExists

private static final boolean fileExists(java.lang.String fileName,
                                        java.lang.String filePath,
                                        java.lang.String fileExt)
Returns if a given file exists in the given path

Parameters:
fileName - File's name
filePath - Path where look for the file
fileExt - File's extension
Returns:
File has been found?

saveMatrix

public static final void saveMatrix(Matrix m,
                                    java.lang.String filename)
                             throws DataException
Saves a matrix object with the given name

Parameters:
m - Matrix object
filename - Desired name
Throws:
DataException

saveWorkspace

public static final void saveWorkspace(Workspace w,
                                       java.lang.String filename)
                                throws DataException
Saves a Workspace object with the given name

Parameters:
w - Workspace object
filename - Desired name
Throws:
DataException

loadMatrix

public static final Matrix loadMatrix(java.lang.String filename)
                               throws DataException
Return the Matrix previously saved with the given name

Parameters:
filename - Name of the Matrix
Returns:
Loaded Matrix
Throws:
DataException

loadWorkspace

public static final Workspace loadWorkspace(java.lang.String filename)
                                     throws DataException
Return the Workspace previously saved with the given name

Parameters:
filename - Name of the Workspace
Returns:
Loaded Workspace
Throws:
DataException

updateMatrix

public static final java.lang.String updateMatrix(java.lang.String matName,
                                                  java.lang.String newName,
                                                  java.lang.String newDesc)
                                           throws DataException
Updates a saved Matrix attributes with the given ones

Parameters:
matName - Name of the Matrix
newName - New name of the matrix
newDesc - New description of the matrix
Returns:
The name used to save the matrix
Throws:
DataException

exportMatrix

public static final void exportMatrix(java.lang.String matName,
                                      java.lang.String exportName,
                                      java.lang.String exportPath)
                               throws DataException
Export a saved Matrix from the Matrix directory to another arbitrary directory

Parameters:
matName - Name of the Matrix wich will be exported
exportName - Desired name of the exportation
exportPath - Desired exportation path
Throws:
DataException

deleteMatrix

public static final void deleteMatrix(java.lang.String filename)
                               throws DataException
Deletes a Matrix from the library and Workspaces referencing it

Parameters:
filename - Name of the Matrix to be deleted
Throws:
DataException

deleteWorkspace

public static final void deleteWorkspace(java.lang.String filename)
                                  throws DataException
Deletes a Workspace from the saved ones

Parameters:
filename - Name of the Workspace to be deleted
Throws:
DataException

matrixExists

public static final boolean matrixExists(java.lang.String matName)
Returns if a Matrix with this name exists

Parameters:
matName - Matrix name
Returns:
exists a Matrix with this name?

workspaceExists

public static final boolean workspaceExists(java.lang.String wsName)
Returns if a Workspace with this name exists

Parameters:
wsName - Workspace name
Returns:
exists a Workspace with this name?

getMatrixNames

public static final java.lang.String[] getMatrixNames()
Retun the names of all Matrix in the Library

Returns:
Array with Matrix names or null if none

getWorkspaceNames

public static final java.lang.String[] getWorkspaceNames()
Retun the names of all Workspace saved

Returns:
Array with Workspace names or null if none