gov.llnl.babel.backend
Class FileManager

java.lang.Object
  extended by 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
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.
 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.Writer createWriter(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 expandGlueSubdir(SymbolID id, java.io.File file)
           
 java.io.File expandLanguageSubdir(SymbolID id, java.io.File file, java.lang.String language)
           
 java.io.File expandStubMatlabDirectory(SymbolID id, int type, java.lang.String groupname)
          Generate the relative Matlab 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, 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(java.util.Collection listeners)
          Remove a collection of listeners 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
 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(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

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

Method Detail

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.

removeListeners

public void removeListeners(java.util.Collection listeners)
Remove a collection of listeners from this file manager.

Parameters:
listeners - the listener collection to remove.

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.


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.


getGlueSubdirGeneration

public boolean getGlueSubdirGeneration()
Get the current style of "glue" code 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.
Throws:
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 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.
Throws:
CodeGenerationException

createWriter

public java.io.Writer createWriter(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 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
Throws:
CodeGenerationException

getCodeSplicer

public CodeSplicer getCodeSplicer(SymbolID id,
                                  int type,
                                  java.lang.String file,
                                  boolean isSource,
                                  boolean prependFullName)
                           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 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
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)

    expandStubMatlabDirectory

    public java.io.File expandStubMatlabDirectory(SymbolID id,
                                                  int type,
                                                  java.lang.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
  • See Also:
    setJavaStylePackageGeneration(boolean), setFileGenerationRootDirectory(java.lang.String)

    expandLanguageSubdir

    public java.io.File expandLanguageSubdir(SymbolID id,
                                             java.io.File file,
                                             java.lang.String language)

    expandGlueSubdir

    public java.io.File expandGlueSubdir(SymbolID id,
                                         java.io.File file)

    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)