|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectptolemy.copernicus.kernel.Copernicus
public class Copernicus
A Standalone application that generates code using the Ptolemy II code generation system. This class acts a wrapper for the copernicus.*.Main classes by providing defaults arguments for the various backends. The generatorAttribute Parameter names a MoML file that contains definitions for other Parameters and Variables that control the compilation and execution of the model The default compilation arguments are read in from a file named compileCommandTemplate.in, variables are substituted and the compile command executed and then default arguments are read in from a file named runCommandTemplate.in.
For example:
java -classpath $PTII ptolemy.copernicus.kernel.Copernicus foo.xmlwill read in the $PTII/ptolemy/copernicus/java/compileCommandTemplate.in, substitute in the appropriate variables and then generate code for foo.xml
The default code generator is the deep java code generator in $PTII/ptolemy/copernicus/java.
The argument that names the xml file containing the model to generate
code for should be a relative pathname. The xml file argument is
converted into a URL internally.
If no xml file argument is specified,
then code is generated for
$PTII/ptolemy/domains/sdf/demo/OrthogonalCom/OrthogonalCom.xml
Generating code is fairly complex, so there are many other parameters that can be set as the other arguments.
The general format is
-VariableName VariableValue, for example:
-codeGenerator "shallow"
For example:
java -classpath $PTII ptolemy.copernicus.kernel.GenerateCode -codeGenerator "shallow" foo.xml
The initial parameters, their values and any documentation can be printed with
java -classpath $PTII ptolemy.copernicus.kernel.GenerateCode -helpIf you have rebuilt Ptolemy II from sources, and have a shell such as bash available, then you can use
$PTII/bin/copernicus
as a shortcut. For example
$PTII/bin/copernicus -codeGenerator "shallow" foo.xml
The details of how this class works can be found in the
GeneratorAttribute documentation.
| Red (cxh) |
| Red (cxh) |
| Field Summary | |
|---|---|
protected java.lang.String[] |
_commandFlags
The command-line options that are either present or not. |
protected java.lang.String[][] |
_commandOptions
The command-line options that take arguments. |
protected java.lang.String |
_commandTemplate
The form of the command line. |
protected static boolean |
_test
If true, then auto exit after a few seconds. |
protected boolean |
_verbose
If true, then print debugging information. |
static java.lang.String |
GENERATOR_NAME
The name of the GeneratorAttribute |
| Constructor Summary | |
|---|---|
Copernicus(java.lang.String[] args)
Parse the specified command-line arguments and then execute any specified commands. |
|
| Method Summary | |
|---|---|
protected boolean |
_parseArg(java.lang.String arg)
Parse a command-line argument. |
protected void |
_parseArgs(java.lang.String[] args)
Parse the command-line arguments. |
protected void |
_saveParsedArgs()
Save arguments that were parsed in the generatorAttribute of the model. |
static java.lang.String |
commandToRun(GeneratorAttribute generatorAttribute)
Return the command to run the generated code. |
static void |
compileAndRun(CompositeActor model,
GeneratorAttribute generatorAttribute)
Possibly create the generated code and run it. |
static int |
executeCommand(java.lang.String command)
Execute a command in a subshell, and print out the results in standard error and standard out. |
static java.lang.String |
exportMoMLToTemporaryFile(NamedObj namedObj)
Export the MoML of the namedObj argument to a temporary file. |
static void |
main(java.lang.String[] args)
Create a new instance of this application, passing it the command-line arguments. |
static java.util.HashMap |
newMap(NamedObj namedObj)
Deprecated. See CodeGeneratorUtilities.newMap(NamedObj) |
static java.io.BufferedReader |
openAsFileOrURL(java.lang.String inputFileName)
Deprecated. See CodeGeneratorUtilities.openAsFileOrURL(String) |
CompositeActor |
readInModel(java.lang.String modelPathOrURL)
Read in a MoML class, either as a top level model or a file, initialize the model, then create instance classes for actors. |
static void |
substitute(java.io.BufferedReader inputFile,
java.util.Map substituteMap,
java.lang.String outputFileName)
Deprecated. See CodeGeneratorUtilities.substitute(BufferedReader, Map, String) |
static java.lang.String |
substitute(java.lang.String input,
java.util.Map substituteMap)
Deprecated. See CodeGeneratorUtilities.substitute(String, Map) |
static void |
substitute(java.lang.String inputFileName,
java.util.Map substituteMap,
java.lang.String outputFileName)
Deprecated. See CodeGeneratorUtilities.substitute(String, Map, String) |
static java.lang.String |
substitute(java.lang.String inputFileName,
NamedObj namedObj)
Deprecated. See CodeGeneratorUtilities.substitute(String, NamedObj) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String GENERATOR_NAME
protected java.lang.String[] _commandFlags
protected java.lang.String[][] _commandOptions
protected java.lang.String _commandTemplate
protected static boolean _test
protected boolean _verbose
| Constructor Detail |
|---|
public Copernicus(java.lang.String[] args)
throws java.lang.Exception
args - The command-line arguments.
java.lang.Exception - If command line arguments have problems.| Method Detail |
|---|
public static java.lang.String commandToRun(GeneratorAttribute generatorAttribute)
throws java.lang.Exception
generatorAttribute - The GeneratorAttribute that contains
the Parameters that determine the command to run.
java.lang.Exception
public static void compileAndRun(CompositeActor model,
GeneratorAttribute generatorAttribute)
throws java.lang.Exception
generatorAttribute - The GeneratorAttribute that contains
the parameters that determine the commands to create and run
the generated code.
java.lang.Exception
public static int executeCommand(java.lang.String command)
throws java.lang.Exception
command - The command to execute.
java.lang.Exception
public static java.lang.String exportMoMLToTemporaryFile(NamedObj namedObj)
throws java.lang.Exception
namedObj - The NamedObj to export
java.lang.Exception - If the temporary file cannot be created.File.createTempFile(java.lang.String, java.lang.String, java.io.File)public static void main(java.lang.String[] args)
args - The command-line arguments.
public static java.util.HashMap newMap(NamedObj namedObj)
throws IllegalActionException
CodeGeneratorUtilities.newMap(NamedObj)
namedObj - The NamedObj that contains Parameters.
IllegalActionException
public static java.io.BufferedReader openAsFileOrURL(java.lang.String inputFileName)
throws java.io.FileNotFoundException,
java.io.IOException
CodeGeneratorUtilities.openAsFileOrURL(String)
inputFileName - The name of the file or URL to open
java.io.FileNotFoundException - If the file cannot be found.
java.io.IOException - If there were problems creating
the BufferedReader.
public CompositeActor readInModel(java.lang.String modelPathOrURL)
throws IllegalActionException,
NameDuplicationException
The MoML class name is processed as follows:
ptolemy.domains.sdf.demo.OrthogonalCom.OrthogonalCom
and inserted into a MoML fragment:
<entity name="ToplevelModel" class=" + momlClassName + "/>
and then passed to MoMLParser.parse().
IllegalActionException - If the model cannot be parsed.
NameDuplicationException
public static java.lang.String substitute(java.lang.String input,
java.util.Map substituteMap)
CodeGeneratorUtilities.substitute(String, Map)
input - The input string that contains substrings
like "@codeBase@".substituteMap - The Map of String keys like "@codeBase@"
and String values like "../../..".
public static java.lang.String substitute(java.lang.String inputFileName,
NamedObj namedObj)
throws java.io.FileNotFoundException,
java.io.IOException
CodeGeneratorUtilities.substitute(String, NamedObj)
@ParameterName@ in inputFileName, and
substitute in the value of the Parameter and return the results.
inputFileName - The name of the file to read from.namedObj - The NamedObj that contains Parameters to
be searched for in inputFileName.
java.io.FileNotFoundException
java.io.IOException
public static void substitute(java.io.BufferedReader inputFile,
java.util.Map substituteMap,
java.lang.String outputFileName)
throws java.io.FileNotFoundException,
java.io.IOException
CodeGeneratorUtilities.substitute(BufferedReader, Map, String)
inputFile - A BufferedReader that refers to the file to be
read in.substituteMap - The Map of String keys like "@codeBase@"
and String values like "../../..".outputFileName - The name of the file to write to.
java.io.FileNotFoundException
java.io.IOExceptionsubstitute(String, Map, String)
public static void substitute(java.lang.String inputFileName,
java.util.Map substituteMap,
java.lang.String outputFileName)
throws java.io.FileNotFoundException,
java.io.IOException
CodeGeneratorUtilities.substitute(String, Map, String)
inputFileName - The name of the file to read from.substituteMap - The Map of String keys like "@codeBase@"
and String values like "../../..".outputFileName - The name of the file to write to.
java.io.FileNotFoundException
java.io.IOExceptionsubstitute(BufferedReader, Map, String)
protected boolean _parseArg(java.lang.String arg)
throws java.lang.Exception
java.lang.Exception - If something goes wrong.
protected void _parseArgs(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception - If an argument is not understood or triggers
an error.
protected void _saveParsedArgs()
throws java.lang.Exception
java.lang.Exception
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||