public class Copernicus
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
Copernicus(java.lang.String[] args)
Parse the specified command-line arguments and then execute
any specified commands.
|
Modifier and Type | Method and Description |
---|---|
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(CompositeEntity 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.
|
static java.io.BufferedReader |
openAsFileOrURL(java.lang.String inputFileName)
Deprecated.
|
CompositeEntity |
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.
|
static java.lang.String |
substitute(java.lang.String input,
java.util.Map substituteMap)
Deprecated.
|
static void |
substitute(java.lang.String inputFileName,
java.util.Map substituteMap,
java.lang.String outputFileName)
Deprecated.
|
static java.lang.String |
substitute(java.lang.String inputFileName,
NamedObj namedObj)
Deprecated.
|
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
public Copernicus(java.lang.String[] args) throws java.lang.Exception
args
- The command-line arguments.java.lang.Exception
- If command line arguments have problems.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(CompositeEntity 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 exportjava.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.@Deprecated public static java.util.HashMap newMap(NamedObj namedObj) throws IllegalActionException
CodeGeneratorUtilities.newMap(NamedObj)
namedObj
- The NamedObj that contains Parameters.IllegalActionException
@Deprecated 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 openjava.io.FileNotFoundException
- If the file cannot be found.java.io.IOException
- If there were problems creating
the BufferedReader.public CompositeEntity 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
@Deprecated 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 "../../..".@Deprecated 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
@Deprecated 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.IOException
substitute(String, Map, String)
@Deprecated 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.IOException
substitute(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