gov.llnl.babel.backend
Class FileManager

java.lang.Object
  |
  +--gov.llnl.babel.backend.FileManager

public class FileManager
extends java.lang.Object

FileManager is a singleton class that manages the files generated by the backend code generators. This class tracks what files were generated and their "file group" for use in makefile generation.


Constructor Summary
protected FileManager()
          Create a new instance of the backend file manager object.
 
Method Summary
 void addListener(FileListener listener)
          Add a listener to the file manager.
 java.io.PrintWriter createFile(SymbolID id, int type, java.lang.String groupname, java.lang.String filename)
          Create a file given a symbol ID, type, file group, and file name.
 java.io.FileWriter createFileWriter(SymbolID id, int type, java.lang.String groupname, java.lang.String filename)
          Create a file given a symbol, file group, and file name.
 java.io.File expandDirectory(SymbolID id, int type)
          Generate the relative file name from the symbol ID.
 java.io.File expandVPathDirectory(SymbolID id, int type)
          Generate the VPATH for the symbol ID.
 CodeSplicer getCodeSplicer(SymbolID id, int type, java.lang.String file)
          Read the specified file and return a code splicer object representing code splices from the file that should be preserved in the next file.
static FileManager getInstance()
          Return the singleton instance of the file manager.
 boolean getJavaStylePackageGeneration()
          Get the current style of file generation, either all in one directory or Java-style package directories.
 void removeListener(FileListener listener)
          Remove a listener from this file manager.
 void setFileGenerationRootDirectory(java.lang.String directory)
          Change the root directory where files will be generated to something other than the current working directory
static void setInstance(FileManager instance)
          Set the singleton instance of the configuration.
 void setJavaStylePackageGeneration(boolean java_style)
          Set the style of file generation, either all in one directory or Java-style package directories.
 void setVPathDirectory(java.lang.String directory)
          Set the VPATH directory where files can be found (notably IMPLS for CodeSplicers).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileManager

protected FileManager()
Create a new instance of the backend file manager object. This method is protected since users are not allowed access to the constructor of a singleton class. Use the getInstance method to retrieve a copy of the file manager.

Method Detail

getInstance

public static FileManager getInstance()
Return the singleton instance of the file manager. If the instance has not yet been created, then it will be created by this call.


addListener

public void addListener(FileListener listener)
Add a listener to the file manager. This listener will receive calls for each file created.

Parameters:
listener - a new listener to be added.

removeListener

public void removeListener(FileListener listener)
Remove a listener from this file manager.

Parameters:
listener - the listener to remove.

setInstance

public static void setInstance(FileManager instance)
Set the singleton instance of the configuration. Use this function only if you want to change the default configuration implementation or use multiple configurations in the same application. Otherwise, getInstance will automatically create the configuration for you.


getJavaStylePackageGeneration

public boolean getJavaStylePackageGeneration()
Get the current style of file generation, either all in one directory or Java-style package directories.


setJavaStylePackageGeneration

public void setJavaStylePackageGeneration(boolean java_style)
Set the style of file generation, either all in one directory or Java-style package directories. In the first case, all files are stored in the same directory. In the second, files are stored in package subdirectories that correspond to the SIDL package structure. The default is to use Java-style file generation.


setVPathDirectory

public void setVPathDirectory(java.lang.String directory)
                       throws CodeGenerationException
Set the VPATH directory where files can be found (notably IMPLS for CodeSplicers).

Parameters:
directory - String name of directory ( relative or absolute). If it's null, "", or "." then VPATH is disabled.
CodeGenerationException

setFileGenerationRootDirectory

public void setFileGenerationRootDirectory(java.lang.String directory)
                                    throws CodeGenerationException
Change the root directory where files will be generated to something other than the current working directory

Parameters:
directory - String name of directory (relative or absolute) if it's null, empty, or "." then current directory is assumed.
Throws:
CodeGenerationException

createFile

public java.io.PrintWriter createFile(SymbolID id,
                                      int type,
                                      java.lang.String groupname,
                                      java.lang.String filename)
                               throws CodeGenerationException
Create a file given a symbol ID, type, file group, and file name. The return value is a FileWriter that will typically be used to create a PrintWriter stream that must be closed by the caller when the file handle is no longer needed. The symbol is used to expand the file path; it may be null if no expansion is desired.

Parameters:
id - the file is associated with this symbol ID.
type - the symbol ID is of this type. This should be one of the constants from Type.
groupname - the category this file belongs in.
filename - the file name.
CodeGenerationException

createFileWriter

public java.io.FileWriter createFileWriter(SymbolID id,
                                           int type,
                                           java.lang.String groupname,
                                           java.lang.String filename)
                                    throws CodeGenerationException
Create a file given a symbol, file group, and file name. The return value is a FileWriter that will typically be used to create a PrintWriter stream that must be closed by the caller when the file handle is no longer needed. The symbol is used to expand the file path; it may be null if no expansion is desired.

Parameters:
id - the file being created is related to this symbol id.
type - this constant from Type indicates the type of id.
groupname - the category this file belongs in
filename - the file name
CodeGenerationException

getCodeSplicer

public CodeSplicer getCodeSplicer(SymbolID id,
                                  int type,
                                  java.lang.String file)
                           throws java.io.IOException
Read the specified file and return a code splicer object representing code splices from the file that should be preserved in the next file. If the file does not exist, an empty CodeSplicer instance is returned. This will happen whenever code is generated for the first time. If there is any other error reading the file data, an IOException is thrown. There should be no need to check for null returns.

Returns:
valid (though possibly empty) CodeSplicer
Throws:
java.io.IOException

expandDirectory

public java.io.File expandDirectory(SymbolID id,
                                    int type)
Generate the relative file name from the symbol ID. If the symbol is not null and Java style package directories are enabled, then the SIDL package name of the symbol is converted into a path name. Furthermore, if the root directory and/or the sub directory is set, they are prepended to the path. The resulting directory is not guaranteed to exist in the filesystem.

Parameters:
id - The symbol ID to generate files for
type - The type of the symbol ID. This should be one of the constants from Type.
Returns:
java.io.File representation for the directory to generate the code. Can be null if
  • setJavaStylePackageGeneration(false), and
  • setFileGenerationRootDirectory(null), and
  • See Also:
    setJavaStylePackageGeneration(boolean), setFileGenerationRootDirectory(java.lang.String)

    expandVPathDirectory

    public java.io.File expandVPathDirectory(SymbolID id,
                                             int type)
    Generate the VPATH for the symbol ID. If the result is not null, then the resulting directory is guaranteed to exist. The directory is constructed of the explicit VPATH with the package directories appended only if Java style package directories are enabled.

    Parameters:
    id - The symbol ID to generate files for
    type - The type of the symbol ID being generated. This should be one of the constants from Type.
    Returns:
    java.io.File representation for the directory to generate the code. Can be null if
  • setVPathDirectory(null), or
  • VPATH == Output Directory, or
  • final directory does not exist.
    See Also:
    setJavaStylePackageGeneration(boolean), setFileGenerationRootDirectory(java.lang.String)