gov.llnl.babel.backend

Class 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

FileManager(Context context)
Create a new instance of the backend file manager object.

Method Summary

void
addListener(FileListener listener)
Add a listener to the file manager.
PrintWriter
createFile(SymbolID id, int type, String groupname, String filename)
Create a file given a symbol ID, type, file group, and file name.
Writer
createWriter(SymbolID id, int type, String groupname, String filename)
Create a file given a symbol, file group, and file name.
File
expandDirectory(SymbolID id, int type)
Generate the relative file name from the symbol ID.
File
expandGlueSubdir(SymbolID id, File file)
File
expandLanguageSubdir(SymbolID id, File file, String language)
File
expandStubMatlabDirectory(SymbolID id, int type, String groupname)
Generate the relative Matlab file name from the symbol ID.
File
expandVPathDirectory(SymbolID id, int type)
Generate the VPATH for the symbol ID.
CodeSplicer
getCodeSplicer(SymbolID id, int type, String file, boolean isSource, boolean prependFullName)
Read the specified file and return a code splicer object representing code splices from the file that should be preserved in the next file.
boolean
getGlueSubdirGeneration()
Get the current style of "glue" code generation.
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
removeListeners(Collection listeners)
Remove a collection of listeners from this file manager.
void
setFileGenerationRootDirectory(String directory)
Change the root directory where files will be generated to something other than the current working directory
void
setGlueSubdirGeneration(boolean glue_dir)
Set the style of file generation for impl and non-impl (ior, etc) files, either all in one directory, or generating the "glue" code (stubs, skels, ior) in a separate glue/ subdirectory.
void
setJavaStylePackageGeneration(boolean java_style)
Set the style of file generation, either all in one directory or Java-style package directories.
void
setVPathDirectory(String directory)
Set the VPATH directory where files can be found (notably IMPLS for CodeSplicers).

Constructor Details

FileManager

public FileManager(Context context)
Create a new instance of the backend file manager object. Normally you get the instance from the Context.

Method Details

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.

createFile

public PrintWriter createFile(SymbolID id,
                              int type,
                              String groupname,
                              String filename)
            throws CodeGenerationException
Create a file given a symbol ID, type, file group, and file name. The return value is 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.

createWriter

public Writer createWriter(SymbolID id,
                           int type,
                           String groupname,
                           String filename)
            throws CodeGenerationException
Create a file given a symbol, file group, and file name. The return value is a Writer 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

expandDirectory

public 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

  • expandGlueSubdir

    public File expandGlueSubdir(SymbolID id,
                                 File file)

    expandLanguageSubdir

    public File expandLanguageSubdir(SymbolID id,
                                     File file,
                                     String language)

    expandStubMatlabDirectory

    public File expandStubMatlabDirectory(SymbolID id,
                                          int type,
                                          String groupname)
    Generate the relative Matlab 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 with prefix @. 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

  • expandVPathDirectory

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

  • getCodeSplicer

    public CodeSplicer getCodeSplicer(SymbolID id,
                                      int type,
                                      String file,
                                      boolean isSource,
                                      boolean prependFullName)
                throws 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 CodeSplicer instance based on the business rules defined by CodeSplicer 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

    getGlueSubdirGeneration

    public boolean getGlueSubdirGeneration()
    Get the current style of "glue" code generation.

    getJavaStylePackageGeneration

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

    removeListener

    public void removeListener(FileListener listener)
    Remove a listener from this file manager.
    Parameters:
    listener - the listener to remove.

    removeListeners

    public void removeListeners(Collection listeners)
    Remove a collection of listeners from this file manager.
    Parameters:
    listeners - the listener collection to remove.

    setFileGenerationRootDirectory

    public void setFileGenerationRootDirectory(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.

    setGlueSubdirGeneration

    public void setGlueSubdirGeneration(boolean glue_dir)
    Set the style of file generation for impl and non-impl (ior, etc) files, either all in one directory, or generating the "glue" code (stubs, skels, ior) in a separate glue/ subdirectory.

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