public class JavaScript extends AbstractPlaceableActor implements AccessorOrchestrator
The script defines one or more functions that configure this actor with ports and parameters, initialize the actor, perform runtime functions such as reacting to inputs and producing outputs, and perform finalization (wrapup) functions. The script may be provided as the textual value of the script parameter, or as an input on the script port. You can add to the script or modify function definitions on each firing.
To use this actor, specify a script. Define an exports.setup() function that declares inputs, outputs, and parameters.
Your script can define zero or more of the following functions:
exports.setup = function() { this.input('foo', {'type':'string'}); }will create an input port named "foo" (if one does not already exist), and set its type to "string", possibly overriding any previously set data type. The methods that are particularly useful to use in setup are input, output, parameter, instantiate, and connect.
exports.fire = function () {... function body ...};Alternatively, you can do
var fire = function() {... function body ...}; exports.fire = fire;When these functions are invoked, 'this' will be bound to the accessor instance.
Your script may also register input handler functions by invoking
var handle = this.addInputHandler(portName, function);
Normally you would do this in initialize(). The returned handle can be used to call this.removeInputHandler(). Handlers will be automatically unregistered upon wrapup(), so unless you want to cancel a handler earlier, you do not need to explicitly unregister a handler.
The function specified as the input handler will be invoked whenever the port receives a new input. Note that the fire() function, if defined, will also be invoked (after the specified function) and will see the same input. If the specified function is null, then only the fire() function will be invoked. If the portName is null, then the handler will be invoked whenever a new input arrives on any input, after which the fire function will be invoked, if it exists.
Often you can leave the types of input and output ports unspecified. Sometimes, however, you will need to explicitly set the types of the output ports. You can do this by specifying a 'type' option to the input() function in setup(). This implementation extends the accessor interface definition by allowing any Ptolemy II type to be specified. Keep in mind, however, that if you specify Ptolemy II types that are not also accessor types, then your script will likely not work in some other accessor host.
You may also need to set the type of input ports. Usually, forward type inference will work, and the type of the input port will be based on the source of data. However, if the input comes from an output port whose output is undefined, such as JSONToToken, then you may want to enable backward type inference, and specify here the type of input that your script requires. Again, you do this with a 'type' option to the input() function in setup().
The accessor instance (the value of 'this' inside setup(), initialize(), fire(), and wrapup()) has the following functions, at least:
Note that get() may be called within a JavaScript callback function. In that case, if the callback function is invoked during the firing of this actor, then the get() will return immediately. Otherwise, the get() method will request a firing of this actor at the current time and block the JavaScript thread until this actor is in that firing. This way, this actor ensures that get() reads a proper input. Note that although blocking JavaScript functions is not normally done, this actor has its own JavaScript engine, so no other JavaScript anywhere in the model will be affected. Those JavaScript threads are not blocked.
The following example script calculates the factorial of the input.
exports.setup = function() { this.input('input', {'type':'int'}); this.output('output', {'type':'int'}); } exports.fire = function() { var value = this.get('input'); if (value < 0) { error("Input must be greater than or equal to 0."); } else { var total = 1; while (value > 1) { total *= value; value--; } this.send('output', total); } }
Your script may also store values from one firing to the next, or from initialization to firing. For example,
exports.setup = function() { this.output('output', {'type':'int'}); } var init; exports.initialize() = function() { init = 0; } exports.fire = function() { init = init + 1; this.send('output', init); }
will send a count of firings to the output named "output".
In addition, the symbols "actor" and "accessor" are defined to be the instance of this actor. In JavaScript, you can invoke methods on it. (Note that in an accessor, which is implemented by a subclass of this JavaScript actor, invocation of these functions is blocked for security reasons.) For example, the JavaScript
actor.toplevel().getName();
will return the name of the top-level composite actor containing this actor.
This actor can be used in any Ptolemy II model and can interact with native Ptolemy II actors through its ports. However, not all Ptolemy II data types translate naturally to JavaScript types. Simple types will "just work." This actor converts Ptolemy types int, double, string, and boolean to and from equivalent JavaScript types when sending and getting to and from ports. In addition, arrays at input ports are converted to native JavaScript arrays. When sending a JavaScript array to an output port, it will be converted into a Ptolemy II array, but keep in mind that Ptolemy II arrays have a single element type, namely a type that every element can be converted to. So, for example, sending the JavaScript array [1, 2, "foo"] to an output port will result in the Ptolemy II array {"1", "2", "foo"}, an array of strings. If you wish to send a JavaScript array (or any other JavaScript object) without modifying it, wrap it in an ObjectToken, as in this example:
var ObjectToken = Java.type('ptolemy.data.ObjectToken'); exports.fire = function() { var token = new ObjectToken([1, 2, 'foo']); this.send('output', token); }
The type of the output port will need to be set to object or general. If you send this to another JavaScript actor, that actor can retrieve the original JavaScript object as follows:
var ObjectToken = Java.type('ptolemy.data.ObjectToken'); exports.fire = function() { var token = this.get('input'); var array = token.getValue(); ... operate on array, which is the original [1, 2, 'foo'] ... }
Ptolemy II records are also converted into JavaScript objects, and JavaScript objects with enumerable properties into records. When converting a JavaScript object to a record, each enumerable property (own or inherited) is included as a field in the resulting record, with the value of the field is converted in the same manner. To send a JavaScript object without any conversion, wrap it in an ObjectToken as with the array example above.
These automatic conversions do not cover all cases of interest. For example, if you provide inputs to this JavaScript actor that cannot be converted, the script will see the corresponding Token object. For example, if you send a number of type long to an input of a JavaScript actor, the script (inside a fire() function):
var value = this.get('input'); print(value.getClass().toString());
will print on standard out the string
"class ptolemy.data.LongToken"
JavaScript does not have a long data type (as of this writing), so instead the get() call returns a JavaScript Object wrapping the Ptolemy II LongToken object. You can then invoke methods on that token, such as getClass(), as done above.
When sending tokens using send(), you can explicitly prevent any conversions from occurring by creating a Ptolemy II token explicitly and sending that. For example, the JavaScript nested array [[1, 2], [3, 4]] will be automatically converted into a Ptolemy II array of arrays {{1,2}, {3,4}}. If instead you want to send a Ptolemy II integer matrix [1,2;3,4], you can do this:
var IntMatrixToken = Java.type('ptolemy.data.IntMatrixToken'); exports.fire = function() { var token = new IntMatrixToken([[1, 2], [3, 4]]); this.send('output', token); }
Scripts can instantiate Java classes and invoke methods on them. For example, the following script will build a simple Ptolemy II model and execute it each time this JavaScript actor fires.
var Ramp = Java.type('ptolemy.actor.lib.Ramp'); var FileWriter = Java.type('ptolemy.actor.lib.FileWriter'); var SDFDirector = Java.type('ptolemy.domains.sdf.kernel.SDFDirector'); var TypedCompositeActor = Java.type('ptolemy.actor.TypedCompositeActor'); var Manager = Java.type('ptolemy.actor.Manager'); var toplevel = new TypedCompositeActor(); var ramp = new Ramp(toplevel, "ramp"); var writer = new FileWriter(toplevel, "writer"); toplevel.connect(ramp.output, writer.input); var director = new SDFDirector(toplevel, "SDFDirector"); director.getAttribute('iterations').setExpression("10"); var manager = new Manager(); toplevel.setManager(manager); exports.fire = function() { manager.execute(); }
You can even send this model out on an output port. For example,
exports.fire = function() { this.send('output', toplevel); }where "output" is the name of the output port. Note that the manager does not get included with the model, so the recipient will need to associate a new manager to be able to execute the model. Note further that you may want to declare the type of the output to be 'actor', a Ptolemy II type.
Subclasses of this actor may put it in "restricted" mode, which limits the functionality as follows:
For debugging, it can be useful to right click on this actor and select Listen to Actor. Refer to https://accessors.org for a complete definition of the available functionality. For example, it is explained there how to create composite accessors, which instantiate and connect multiple subaccessors within this one.
Modifier and Type | Class and Description |
---|---|
class |
JavaScript.DeferredSend
Runnable object intended to be run inside of the fire method to
send out a token that was attempted to be send out at an earlier
time, asynchronous with fire.
|
class |
JavaScript.PortOrParameterProxy
Proxy for a port or parameter.
|
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected static java.lang.Object[] |
_EMPTY_ARGS
Empty argument list for JavaScript function invocation.
|
protected javax.script.ScriptEngine |
_engine
JavaScript engine, shared among all instances of this class.
|
protected boolean |
_executing
True while the model is executing (between initialize() and
wrapup(), including the initialize() but not wrapup().
|
protected java.lang.Object |
_exports
The exports object defined in the script that is evaluated.
|
protected static StringToken |
_INITIAL_SCRIPT
Initial script as a token.
|
protected java.lang.Object |
_instance
The instance returned when evaluating the script.
|
protected static java.lang.String[] |
_JAVASCRIPT_KEYWORDS
JavaScript keywords.
|
protected static java.util.Set<java.lang.String> |
_KEYWORDS
Keywords as a Set.
|
protected boolean |
_restricted
If set to true in the constructor of a base class, then put
this actor in "restricted" mode.
|
protected boolean |
_running
True while the model is running (past initialize() and before
wrapup()).
|
TypedIOPort |
error
Output port on which to produce a message when an error occurs
when executing this actor.
|
PortParameter |
script
The script defining the behavior of this actor.
|
_frame, _paneSize, _windowClosingAdapter, _windowProperties
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
JavaScript(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_addPort(TypedIOPort port)
Override the base class so that the name of any port added is shown.
|
protected void |
_checkValidity(java.lang.String name)
Check the validity of a name.
|
protected java.util.Set<Inequality> |
_defaultTypeConstraints()
Return null, because the default type constraints, where output
types are greater than or equal to all input types, make no sense
for this actor.
|
protected void |
_invokeMethodInContext(java.lang.Object context,
java.lang.String methodName,
java.lang.Object... args)
Invoke the specified method in the context of the exports object.
|
protected void |
_setPortDescription(NamedObj portOrParameter,
java.lang.String description)
Set the description of a port or parameter.
|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute, and if the attribute is the
script parameter, and the script parameter possibly contains a
'setup' function, then evaluate that function.
|
void |
author(java.lang.String author)
Specify author information to appear in the documentation for this actor.
|
void |
clearInterval(java.lang.Object handle)
Clear the interval with the specified handle, if it
has not already executed.
|
void |
clearTimeout(java.lang.Object handle)
Clear the timeout with the specified handle, if it
has not already executed.
|
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace.
|
static javax.script.ScriptEngine |
createEngine(JavaScript actor,
boolean debugging,
boolean restricted)
Create a script engine and initialize it.
|
double |
currentTime()
Return the current time as a number (in seconds).
|
void |
declareDelayDependency()
Declare that any output that is marked as spontanous does does
not depend on the input in a firing.
|
void |
description(java.lang.String description)
Specify a description to appear in the documentation for this actor.
|
void |
description(java.lang.String description,
java.lang.String type)
Specify a description to appear in the documentation for this actor.
|
void |
error(java.lang.String message)
If the model is executing and the error port is connected, then send the
message to the error port; otherwise, use the MessageHandler to display the
error.
|
void |
error(java.lang.String message,
java.lang.Throwable throwable)
If the model is executing and the error port is connected, then send the
message to the error port; otherwise, use the MessageHandler to display the
error.
|
java.lang.String |
escapeForJavaScript(java.lang.String unescapedString)
Escape a string for use within JavaScript.
|
void |
fire()
Produce any pending outputs specified by send() since the last firing,
invoke any timer tasks that match the current time, and invoke the
fire function.
|
javax.script.ScriptEngine |
getEngine()
If this actor has been initialized, return the JavaScript engine,
otherwise return null.
|
static java.lang.String |
getFileFromClasspathAsString(java.lang.String path)
Return the string contents of the file from the classpath.
|
JavaScript.PortOrParameterProxy |
getPortOrParameterProxy(java.lang.String name)
Get the proxy for a port or parameter with the specified name.
|
java.lang.Object |
getResource(java.lang.String uri,
java.lang.Object... arguments)
Get a resource, which may be a file name or a URL, and return the
value of the resource as a string.
|
void |
initialize()
Create a new JavaScript engine, load the default functions, and
register the ports so that send() and get() can work.
|
Token |
input(java.lang.String name)
Create a new input port if it does not already exist.
|
Token |
input(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> options)
Create a new input port if it does not already exist.
|
void |
invokeCallback(java.lang.Runnable function)
Invoke the specified function in the fire() method as soon as possible.
|
boolean |
isExecuting()
Return true if the model is executing (between initialize() and
wrapup(), including initialize() but not wrapup()).
|
static boolean |
isJavaScriptKeyword(java.lang.String identifier)
Return true if the specified string is a JavaScript keyword.
|
boolean |
isRestricted()
Return true if this actor is restricted.
|
static boolean |
isValidIdentifier(java.lang.String identifier)
Return true if the specified string is not a JavaScript keyword
and is a valid JavaScript identifier.
|
java.lang.String |
localHostAddress()
Return the local host IP address as a string.
|
void |
log(java.lang.String message)
If debugging is turned on, then send the specified message to the
_debug() method, and otherwise send it out to stdout.
|
void |
output(java.lang.String name)
Create a new output port if it does not already exist.
|
void |
output(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> options)
Create a new output port if it does not already exist.
|
Token |
parameter(java.lang.String name)
Create a new parameter if it does not already exist.
|
Token |
parameter(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> options)
Create a new parameter if it does not already exist.
|
void |
place(java.awt.Container container)
Place the interface for this actor in the specified container.
|
void |
preinitialize()
Create a new JavaScript engine, load the default functions,
and evaluate the script parameter.
|
static java.lang.String |
readFromInputStream(java.io.InputStream stream)
Deprecated.
Invoke FileUtilities.readFromInputStream() directly.
|
java.lang.Object |
setInterval(java.lang.Runnable function,
long milliseconds)
Invoke the specified function after the specified amount of time and again
at multiples of that time.
|
java.lang.Object |
setTimeout(java.lang.Runnable function,
long milliseconds)
Invoke the specified function after the specified amount of time.
|
void |
stopEnclosingModel()
Stop execution of the enclosing model.
|
java.lang.Object |
toJSArray(java.lang.Object[] array)
Convert the specified array into a native JavaScript array.
|
void |
version(java.lang.String version)
Specify version information to appear in the documentation for this actor.
|
void |
wrapup()
Execute the wrapup function, if it is defined, and exit the context for this thread.
|
_exportMoMLContents, cleanUp, setFrame
_containedTypeConstraints, _customTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_description, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, removeInitializable
getDerivedLevel, getDerivedList, propagateValue
public TypedIOPort error
public PortParameter script
protected static final java.lang.Object[] _EMPTY_ARGS
protected javax.script.ScriptEngine _engine
protected boolean _executing
protected java.lang.Object _exports
protected static final StringToken _INITIAL_SCRIPT
protected java.lang.Object _instance
protected static final java.lang.String[] _JAVASCRIPT_KEYWORDS
protected static final java.util.Set<java.lang.String> _KEYWORDS
protected boolean _restricted
protected boolean _running
public JavaScript(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.IllegalActionException
- If the actor cannot be contained
by the proposed container.NameDuplicationException
- If the container already has an
actor with this name.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.IllegalActionException
- If evaluating the script fails.public void author(java.lang.String author)
author
- Author information to appear in documentation.public void clearInterval(java.lang.Object handle)
clearInterval
in interface AccessorOrchestrator
handle
- The timeout handle.setTimeout(Runnable, long)
,
setInterval(Runnable, long)
public void clearTimeout(java.lang.Object handle)
clearTimeout
in interface AccessorOrchestrator
handle
- The timeout handle.setTimeout(Runnable, long)
,
setInterval(Runnable, long)
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class AbstractPlaceableActor
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.Object.clone()
public static javax.script.ScriptEngine createEngine(JavaScript actor, boolean debugging, boolean restricted) throws IllegalActionException
actor
- The JavaScript actor that is to use the script
engine. If the actor parameter is null, then the restricted
parameter must be false. The actor parameter is also used for
exception handling. The JavaScriptApplication class typically passes
a null value for this parameter.debugging
- True if the _debug JavaScript variable should be set to true.restricted
- True if script engine should be restricted
so that it can execute unrusted code. The default is typically false.IllegalActionException
- If the "nashorn" JavaScript
engine cannot be found. The Nashorn engine is only present in
JDK 1.8 and later.public double currentTime()
public void declareDelayDependency() throws IllegalActionException
declareDelayDependency
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the causality interface
cannot be computed.AtomicActor.getCausalityInterface()
,
AtomicActor._declareDelayDependency(IOPort, IOPort, double)
public void description(java.lang.String description)
description
- A description to appear in documentation.public void description(java.lang.String description, java.lang.String type)
description
- A description to appear in documentation.type
- The type, which should be one of "text/html" (the default if null
is given), "text/markdown", or "text/plain".public void error(java.lang.String message)
error
in interface AccessorOrchestrator
message
- The messagepublic void error(java.lang.String message, java.lang.Throwable throwable)
message
- The messagethrowable
- The throwablepublic java.lang.String escapeForJavaScript(java.lang.String unescapedString) throws IllegalActionException
unescapedString
- The unescaped string to be escaped for use in JavaScript.IllegalActionException
- If the string cannot be escaped.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If calling send() or super.fire()
throws it.public static java.lang.String getFileFromClasspathAsString(java.lang.String path) throws java.io.IOException
path
- The location. This is used in localFunctions.js.
The path should be a relative path.java.io.IOException
- If the file cannot be read.public javax.script.ScriptEngine getEngine()
public JavaScript.PortOrParameterProxy getPortOrParameterProxy(java.lang.String name)
name
- The name of the port or parameter.public java.lang.Object getResource(java.lang.String uri, java.lang.Object... arguments) throws IllegalActionException
uri
- A specification for the resource.arguments
- A variable number of arguments, where the
first optional argument is an Object that can be a String (the
encoding), an integer (the timeout) or a JSON object with
encoding and timeout fields, See above.
The second optional argument is a callback, the first argument to
the callback is the error, if any, the second element is the data, if any.IllegalActionException
- If the uri specifies any protocol other
than "http" or "https", or if the uri contains any "../", or if the uri
begins with "/".public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If a port name is either a
a JavaScript keyword or not a valid identifier, if loading the
default JavaScript files fails, or if the superclass throws it.public Token input(java.lang.String name) throws IllegalActionException, NameDuplicationException
name
- The name of the port.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word.public Token input(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> options) throws IllegalActionException, NameDuplicationException
name
- The name of the port.options
- The options, or null to accept the defaults.
To give options, this argument must implement the Map interface.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word.public void invokeCallback(java.lang.Runnable function) throws IllegalActionException
invokeCallback
in interface AccessorOrchestrator
function
- The function to invoke.IllegalActionException
- If the director cannot respect the request.public boolean isExecuting()
public static boolean isJavaScriptKeyword(java.lang.String identifier)
identifier
- The identifier name.public boolean isRestricted()
public static boolean isValidIdentifier(java.lang.String identifier)
identifier
- The proposed name.public java.lang.String localHostAddress() throws java.net.UnknownHostException, java.lang.SecurityException
java.net.UnknownHostException
- If the local host is not known.java.lang.SecurityException
- If this actor is in restricted mode.public void log(java.lang.String message)
log
in interface AccessorOrchestrator
message
- The messagepublic void output(java.lang.String name) throws IllegalActionException, NameDuplicationException
name
- The name of the port.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word.public void output(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> options) throws IllegalActionException, NameDuplicationException
name
- The name of the port.options
- The options, or null to accept the defaults.
To give options, this argument must implement the Map interface.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word.public Token parameter(java.lang.String name) throws IllegalActionException, NameDuplicationException
name
- The name of the parameter.IllegalActionException
- If no name is given, or if the
model is executing.NameDuplicationException
- If the name is a reserved word, or if an attribute
already exists with the name and is not a parameter.public Token parameter(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> options) throws IllegalActionException, NameDuplicationException
name
- The name of the parameter.options
- The options, or null to accept the defaults.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word, or if an attribute
already exists with the name and is not a parameter.public void place(java.awt.Container container)
place
in interface Placeable
place
in class AbstractPlaceableActor
container
- The container.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If a port name is either a
a JavaScript keyword or not a valid identifier, if loading the
default JavaScript files fails, or if the superclass throws it.@Deprecated public static java.lang.String readFromInputStream(java.io.InputStream stream) throws java.io.IOException
stream
- The stream.java.io.IOException
- If the stream cannot be read.public java.lang.Object setInterval(java.lang.Runnable function, long milliseconds) throws IllegalActionException
setInterval
in interface AccessorOrchestrator
function
- The function to invoke.milliseconds
- The number of milliseconds in the future to invoke it.IllegalActionException
- If the director cannot respect the request.clearTimeout(Object)
public java.lang.Object setTimeout(java.lang.Runnable function, long milliseconds) throws IllegalActionException
setTimeout
in interface AccessorOrchestrator
function
- The function to invoke.milliseconds
- The number of milliseconds in the future to invoke it.IllegalActionException
- If the director cannot respect the request.clearTimeout(Object)
public void stopEnclosingModel()
public java.lang.Object toJSArray(java.lang.Object[] array) throws IllegalActionException
array
- The array to convert.IllegalActionException
- If the conversion fails.public void version(java.lang.String version)
version
- Version information to appear in documentation.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in interface AccessorOrchestrator
wrapup
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the parent class throws it.protected void _addPort(TypedIOPort port) throws IllegalActionException, NameDuplicationException
_addPort
in class Entity<TypedIOPort>
port
- The port to add to this entity.IllegalActionException
- If the superclass throws it.NameDuplicationException
- If the superclass throws it.protected void _checkValidity(java.lang.String name) throws IllegalActionException
name
- The name to check.IllegalActionException
- If the name is either not a valid
identifier or is a keyword.protected java.util.Set<Inequality> _defaultTypeConstraints()
_defaultTypeConstraints
in class TypedAtomicActor
protected void _invokeMethodInContext(java.lang.Object context, java.lang.String methodName, java.lang.Object... args) throws IllegalActionException
context
- The context.methodName
- The method name.args
- Arguments to pass to the function.IllegalActionException
- If the method does not exist in either
context, or if an error occurs invoking the method.protected void _setPortDescription(NamedObj portOrParameter, java.lang.String description)
portOrParameter
- The port.description
- The description.