rvl.swv
Class AbstractEngine

java.lang.Object
  extended by rvl.swv.AbstractEngine
All Implemented Interfaces:
EngineInterface
Direct Known Subclasses:
DOSEngine, GenStatEngine, LaTeXEngine, MapleEngine, REngine, SASEngine, SplusEngine, StataEngine, SWVEngine, UnixEngine

public abstract class AbstractEngine
extends java.lang.Object
implements EngineInterface

This is an abstract implementation of EngineInterface that can be extended to easily create an EngineInterface for a new piece of software.

To use, extend this class and define these variables in the constructor (defaults, if any, are shown):

In the configuration file, define engineName.binary to a string giving the command to run the program. It should contain the substring %codefile%, and optionally, %outfile%. The appropriate filenames are substituted to form the command line that is executed.

In most cases, only a few methods need to be overridden:


Field Summary
 java.lang.String codeExt
          Extension to add to the file's base name for the code file (include the initial "dot") This should be unique to this engine.
 java.lang.String commentEnd
          String to put after a comment in the code file.
 java.lang.String commentStart
          String to put before a comment in the code file.
 java.lang.String endCode
          Code to put at beginning of code file, before any code chunks
 java.lang.String engineName
          Name of this engine -- used in error msgs and such
 java.lang.String medExt
          Extension to add to intermediate file when post-processing is used.
 int[] okfigfmts
          List of figure file formats supported by this engine
 java.lang.String outExt
          Extension to add to the file's base name for the output file produced by running the code file (include the initial "dot") This should be unique to this engine, if possible
 java.lang.String startupCode
          Code to put at beginning of code file, before any code chunks
 
Constructor Summary
AbstractEngine()
          Default constructor
 
Method Summary
 void closeCodeFile()
          Close the code file
 void closeFig()
          Put code to close the graphics file created by setupFig
 void deleteCodeFile()
          Delete the code and output files
 java.lang.String[] getFileNames()
          Return code and output file names
 boolean openCodeFile(java.lang.String baseName)
          Open a file for saving the code.
 void postProcess()
          Post-process the output file produced by runCode().
AbstractEngine does nothing but can override it
 void putCode(java.lang.String line)
          Add a line of code to the code file
 void putComment(java.lang.String text)
          Add a comment line to the source code
 void putExpr(java.lang.String expr)
          Evaluate an expression and put it in the output stream
 void putSeparator(java.lang.String text)
          Put code that will add the given text in a separate line of the engine's output.
 void putStartup(boolean weaving)
          Startup code
 java.lang.Process runCode()
          Run the code, and return its Process object
 void setBinary(java.lang.String binloc)
          Set where to find the program to run on the code.
 void setParents(StatWeave parent, FileInterface filei)
          Set the parents that drive this instance
 FigFile setupFig(java.lang.String chunkName)
          Put code that will set up a file to receive figure output This method uses the contents of okfigfmts and negotiates with the current FileInterface to determine what figure format to actually use, and how to size it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engineName

public java.lang.String engineName
Name of this engine -- used in error msgs and such


codeExt

public java.lang.String codeExt
Extension to add to the file's base name for the code file (include the initial "dot") This should be unique to this engine.


outExt

public java.lang.String outExt
Extension to add to the file's base name for the output file produced by running the code file (include the initial "dot") This should be unique to this engine, if possible


medExt

public java.lang.String medExt
Extension to add to intermediate file when post-processing is used. This defaults to null and no post-processing


commentStart

public java.lang.String commentStart
String to put before a comment in the code file. Default is "/* "


commentEnd

public java.lang.String commentEnd
String to put after a comment in the code file. Default is " */"


startupCode

public java.lang.String startupCode
Code to put at beginning of code file, before any code chunks


endCode

public java.lang.String endCode
Code to put at beginning of code file, before any code chunks


okfigfmts

public int[] okfigfmts
List of figure file formats supported by this engine

Constructor Detail

AbstractEngine

public AbstractEngine()
Default constructor

Method Detail

openCodeFile

public boolean openCodeFile(java.lang.String baseName)
Open a file for saving the code. Return true if successful

Specified by:
openCodeFile in interface EngineInterface

closeCodeFile

public void closeCodeFile()
Close the code file

Specified by:
closeCodeFile in interface EngineInterface

deleteCodeFile

public void deleteCodeFile()
Delete the code and output files

Specified by:
deleteCodeFile in interface EngineInterface

getFileNames

public java.lang.String[] getFileNames()
Return code and output file names

Specified by:
getFileNames in interface EngineInterface

setParents

public void setParents(StatWeave parent,
                       FileInterface filei)
Set the parents that drive this instance

Specified by:
setParents in interface EngineInterface

setBinary

public void setBinary(java.lang.String binloc)
Set where to find the program to run on the code. (This need not be called if only tangling)

Specified by:
setBinary in interface EngineInterface

putCode

public void putCode(java.lang.String line)
Add a line of code to the code file

Specified by:
putCode in interface EngineInterface

putExpr

public void putExpr(java.lang.String expr)
Evaluate an expression and put it in the output stream

Specified by:
putExpr in interface EngineInterface

putStartup

public void putStartup(boolean weaving)
Startup code

Specified by:
putStartup in interface EngineInterface

putSeparator

public void putSeparator(java.lang.String text)
Put code that will add the given text in a separate line of the engine's output. This is used by the parent to keep track of beginnings and ends of output chunks.

Specified by:
putSeparator in interface EngineInterface

putComment

public void putComment(java.lang.String text)
Add a comment line to the source code

Specified by:
putComment in interface EngineInterface

setupFig

public FigFile setupFig(java.lang.String chunkName)
Put code that will set up a file to receive figure output This method uses the contents of okfigfmts and negotiates with the current FileInterface to determine what figure format to actually use, and how to size it. The extending class should call this as a superclass method, then use the properties of the returned object as needed in outputting the needed setup code for the figure

Specified by:
setupFig in interface EngineInterface
Returns:
null if no format can be found; otherwise the object can be used by the extending class to finish setting up the figure.

closeFig

public void closeFig()
Put code to close the graphics file created by setupFig

Specified by:
closeFig in interface EngineInterface

runCode

public java.lang.Process runCode()
Run the code, and return its Process object

Specified by:
runCode in interface EngineInterface

postProcess

public void postProcess()
Post-process the output file produced by runCode().
AbstractEngine does nothing but can override it

Specified by:
postProcess in interface EngineInterface