|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.actor.gui.ConfigurationApplication
public class ConfigurationApplication
An application that reads one or more files specified on the command line, or instantiates one or more Java classes specified by the -class option. If one of these files is an XML file that defines a Configuration, or one of the classes is an instance of Configuration, then all subsequent files will be read by delegating to the Configuration, invoking its openModel() method. A command-line file is assumed to be a MoML file or a file that can be opened by the specified configuration.
For example, this command uses the HyVisual configuration to open a model:
$PTII/bin/moml $PTII/ptolemy/configs/hyvisual/configuration.xml $PTII/ptolemy/domains/ct/demo/StickyMasses/StickyMasses.xml
If a Ptolemy model is instantiated on the command line, either by giving a MoML file or a -class argument, then parameters of that model can be set on the command line. The syntax is:
$PTII/bin/ptolemy modelFile.xml -parameterName valuewhere parameterName is the name of a parameter relative to the top level of a model or the director of a model. For instance, if foo.xml defines a toplevel entity named
x
and
x
contains an entity named y
and a
parameter named a
, and y
contains a
parameter named b
, then:
$PTII/bin/ptolemy foo.xml -a 5 -y.b 10would set the values of the two parameters.
Note that strings need to have double quotes converted to
"
so to set a parameter named c
to the string "bar"
it might be necessary to do
something like:
$PTII/bin/ptolemy foo.xml -a 5 -y.b 10 -c ""bar""The
"
is necessary to convert the double quote
to something safe to in an XML file.
The -class option can be used to specify a Java class to be loaded. The named class must have a constructor that takes a Workspace as an argument. In the example below, $PTII/ptolemy/domains/sdf/demo/Butterfly/Butterfly.java is a class that has a constructor Butterfly(Workspace).
$PTII/bin/ptolemy -class ptolemy.domains.sdf.demo.Butterfly.ButterflyNote that -class is very well tested now that we have use MoML for almost all models.
Derived classes may provide default configurations. In particular, the protected method _createDefaultConfiguration() is called before any arguments are processed to provide a default configuration for those command-line command-line arguments. In this base class, that method returns null, so no default configuration is provided.
If no arguments are given at all, then a default configuration is instead obtained by calling the protected method _createEmptyConfiguration(). In this base class, that method also returns null, so calling this with no arguments will not be very useful. No configuration will be created and no models will be opened. Derived classes can specify a configuration that opens some welcome window, or a blank editor.
This class read the following parameters from the configuration:
_applicationInitializer
>property name="_applicationInitializer" class="ptolemy.data.expr.StringParameter" value="org.kepler.gui.KeplerInitializer"/<
Configuration
Red (eal) |
Yellow (eal) |
Nested Class Summary | |
---|---|
(package private) static class |
ConfigurationApplication.ConfigurationFilenameFilter
Look for directories that contain files named configuration.xml and intro.htm. |
static class |
ConfigurationApplication.IgnoreErrorHandler
Error Handler that ignore errors. |
Field Summary | |
---|---|
private int |
_activeCount
|
protected java.lang.String |
_basePath
The base path of the configuration directory, usually "ptolemy/configs" for Ptolemy II, but subclasses might have configurations in a different directory. |
protected java.lang.String[][] |
_commandFlagsWithDescriptions
The command-line options that are either present or not. |
protected static java.lang.String[][] |
_commandOptions
The command-line options that take arguments. |
protected java.lang.String |
_commandTemplate
The form of the command line. |
protected Configuration |
_configuration
The configuration model of this application. |
protected boolean |
_exit
Indicator that -runThenExit was requested. |
private boolean |
_expectingClass
|
private static java.net.URL |
_initialSpecificationURL
|
private java.util.List |
_parameterNames
|
private java.util.List |
_parameterValues
|
protected MoMLParser |
_parser
The parser used to construct the configuration. |
protected static boolean |
_printPDF
If true, then print to PDF. |
protected boolean |
_run
If true, then -run was specified on the command line. |
protected boolean |
_statistics
If true, then -statistics was specified on the command line. |
protected static boolean |
_test
If true, then auto exit after a few seconds. |
Constructor Summary | |
---|---|
ConfigurationApplication()
Empty constructor for subclasses to use. |
|
ConfigurationApplication(java.lang.String[] args)
Parse the specified command-line arguments, instanting classes and reading files that are specified. |
|
ConfigurationApplication(java.lang.String basePath,
java.lang.String[] args)
Parse the specified command-line arguments, instanting classes and reading files that are specified. |
Method Summary | |
---|---|
protected java.lang.String |
_configurationUsage(java.lang.String commandTemplate,
java.lang.String[][] commandOptions,
java.lang.String[] commandFlags)
Return a string summarizing the command-line arguments, including any configuration directories in a base path, typically "ptolemy/configs". |
protected java.lang.String |
_configurationUsage(java.lang.String commandTemplate,
java.lang.String[][] commandOptions,
java.lang.String[][] commandFlagsWithDescriptions)
Return a string summarizing the command-line arguments, including any configuration directories in a base path, typically "ptolemy/configs". |
protected Configuration |
_createDefaultConfiguration()
Return a default Configuration, or null to do without one. |
protected Configuration |
_createEmptyConfiguration()
Return a default Configuration to use when there are no command-line arguments, or null to do without one. |
protected void |
_initializeApplication()
Perform any application specific initialization. |
protected Tableau |
_openModel(NamedObj entity)
Open the specified Ptolemy II model. |
protected Tableau |
_openModel(java.net.URL base,
java.net.URL in,
java.lang.String identifier)
Open the specified URL. |
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 |
_printPDF()
Print each effigy to the first printer with the string "PDF" in the name. |
protected Configuration |
_readConfiguration(java.net.URL specificationURL)
Deprecated. Use readConfiguration() instead. |
protected java.lang.String |
_usage()
Return a string summarizing the command-line arguments. |
void |
executionError(Manager manager,
java.lang.Throwable throwable)
Reduce the count of executing models by one. |
void |
executionFinished(Manager manager)
Reduce the count of executing models by one. |
static void |
main(java.lang.String[] args)
Create a new instance of this application, passing it the command-line arguments. |
void |
managerStateChanged(Manager manager)
Do nothing. |
java.util.List |
models()
Return a list of the Ptolemy II models that were created by processing the command-line arguments. |
static Configuration |
readConfiguration(java.net.URL specificationURL)
Read a Configuration from the URL given by the specified string. |
void |
runModels()
Start the models running, each in a new thread, then return. |
static java.net.URL |
specToURL(java.lang.String spec)
Given the name of a file or a URL, convert it to a URL. |
static void |
throwArgsException(java.lang.Throwable cause,
java.lang.String[] args)
Throw an exception that includes the elements of the args parameter. |
void |
waitForFinish()
Wait for all executing runs to finish, then return. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String _basePath
protected java.lang.String[][] _commandFlagsWithDescriptions
protected static java.lang.String[][] _commandOptions
protected java.lang.String _commandTemplate
protected Configuration _configuration
protected boolean _exit
protected MoMLParser _parser
protected static boolean _printPDF
protected boolean _run
protected boolean _statistics
protected static boolean _test
private volatile int _activeCount
private boolean _expectingClass
private java.util.List _parameterNames
private java.util.List _parameterValues
private static java.net.URL _initialSpecificationURL
Constructor Detail |
---|
public ConfigurationApplication()
public ConfigurationApplication(java.lang.String[] args) throws java.lang.Exception
args
- The command-line arguments.
java.lang.Exception
- If command line arguments have problems.public ConfigurationApplication(java.lang.String basePath, java.lang.String[] args) throws java.lang.Exception
basePath
- The basePath to look for configurations
in, usually "ptolemy/configs", but other tools might
have other configurations in other directoriesargs
- The command-line arguments.
java.lang.Exception
- If command line arguments have problems.Method Detail |
---|
public void executionError(Manager manager, java.lang.Throwable throwable)
executionError
in interface ExecutionListener
manager
- The manager calling this method.throwable
- The throwable being reported.public void executionFinished(Manager manager)
executionFinished
in interface ExecutionListener
manager
- The manager calling this method.public static void main(java.lang.String[] args)
args
- The command-line arguments.public void managerStateChanged(Manager manager)
managerStateChanged
in interface ExecutionListener
manager
- The manager calling this method.Manager.getState()
public java.util.List models()
public static Configuration readConfiguration(java.net.URL specificationURL) throws java.lang.Exception
If there is an _applicationInitializer parameter, then instantiate the class named by that parameter. The _applicationInitializer parameter contains a string that names a class to be initialized.
If the configuration has already been read in, then the old configuration will be deleted. Note that this may exit the application.
specificationURL
- A string describing a URL.
java.lang.Exception
- If the configuration cannot be opened, or
if the contents of the URL is not a configuration.public void runModels() throws IllegalActionException
IllegalActionException
- If the manager throws it.public static java.net.URL specToURL(java.lang.String spec) throws java.io.IOException
spec
- The specification.
java.io.IOException
- If it cannot convert the specification to
a URL.public static void throwArgsException(java.lang.Throwable cause, java.lang.String[] args) throws java.lang.Exception
cause
- The throwable that caused the problem.args
- An array of Strings.
java.lang.Exception
- Always thrownpublic void waitForFinish()
protected java.lang.String _configurationUsage(java.lang.String commandTemplate, java.lang.String[][] commandOptions, java.lang.String[] commandFlags)
commandTemplate
- The form of the command linecommandOptions
- Command-line options that take arguments.commandFlags
- An array of Strings that list command-line
options that are either present or not.
StringUtilities.usageString(String, String [][], String [])
protected java.lang.String _configurationUsage(java.lang.String commandTemplate, java.lang.String[][] commandOptions, java.lang.String[][] commandFlagsWithDescriptions)
commandTemplate
- The form of the command linecommandOptions
- Command-line options that take arguments.commandFlagsWithDescriptions
- A 2xM array of Strings that list
command-line options that are either present or not and a description
of what the command line option does.
StringUtilities.usageString(String, String [][], String [][])
protected void _initializeApplication()
protected Configuration _createDefaultConfiguration() throws java.lang.Exception
StringUtilities.mergePropertiesFile()
.
Subclasses should call
PtolemyPreferences.setDefaultPreferences(Configuration)
.
java.lang.Exception
- Thrown in derived classes if the default
configuration cannot be opened.protected Configuration _createEmptyConfiguration() throws java.lang.Exception
java.lang.Exception
- Thrown in derived classes if the empty
configuration cannot be opened.protected Tableau _openModel(NamedObj entity) throws IllegalActionException, NameDuplicationException
entity
- The model.
IllegalActionException
- If constructing an effigy or tableau
fails.
NameDuplicationException
- If a name conflict occurs (this
should not be thrown).protected Tableau _openModel(java.net.URL base, java.net.URL in, java.lang.String identifier) throws java.lang.Exception
base
- The base for relative file references, or null if
there are no relative file references.in
- The input URL.identifier
- The identifier that uniquely identifies the model.
java.lang.Exception
- If the URL cannot be read.protected boolean _parseArg(java.lang.String arg) throws java.lang.Exception
arg
- The command-line argument to be parsed.
java.lang.Exception
- If something goes wrong.protected void _parseArgs(java.lang.String[] args) throws java.lang.Exception
args
- The command-line arguments to be parsed.
java.lang.Exception
- If an argument is not understood or triggers
an error.protected void _printPDF() throws java.lang.Exception
java.lang.Exception
- If a printer with the string "PDF"
cannot be found or if the job cannot be set to the PDF print
service or if there is another problem printing.protected Configuration _readConfiguration(java.net.URL specificationURL) throws java.lang.Exception
specificationURL
- A string describing a URL.
java.lang.Exception
- If the configuration cannot be opened, or
if the contents of the URL is not a configuration.protected java.lang.String _usage()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |