public class RestrictedJavaScriptInterface
extends java.lang.Object
JavaScript
actor.
An instance of this class provides limited access to the JavaScript actor
specified in the constructor, given access only to methods that an untrusted
script can safely execute.Constructor and Description |
---|
RestrictedJavaScriptInterface(JavaScript actor)
Construct a restricted interface to the specified JavaScript actor.
|
Modifier and Type | Method and Description |
---|---|
protected JavaScript |
_getActor()
Return the actor that this wraps.
|
void |
author(java.lang.String author)
Specify author information to appear in the documentation for this actor.
|
void |
clearInterval(java.lang.Integer handle)
Clear the interval with the specified handle, if it has not already executed.
|
void |
clearTimeout(java.lang.Integer handle)
Clear the timeout with the specified handle, if it has not already executed.
|
double |
currentTime()
Return the current time.
|
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)
Delegate to the associated JavaScript actor to report an error.
|
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.
|
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 options)
Create a new input port if it does not already exist.
|
boolean |
isRestricted()
Return true.
|
void |
log(java.lang.String message)
Delegate to the associated JavaScript actor to log a message.
|
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 options)
Create a new parameter if it does not already exist.
|
java.lang.Object |
setInterval(java.lang.Runnable function,
java.lang.Double millisecond)
Invoke the specified function after the specified interval and
periodically after that.
|
java.lang.Object |
setTimeout(java.lang.Runnable function,
java.lang.Double millisecond)
Invoke the specified function after the specified amount of time.
|
void |
stopEnclosingModel()
Stop execution of the enclosing model.
|
void |
version(java.lang.String version)
Specify version information to appear in the documentation for this actor.
|
public RestrictedJavaScriptInterface(JavaScript actor)
actor
- The actor.public void author(java.lang.String author)
author
- Author information to appear in documentation.public void clearInterval(java.lang.Integer handle)
handle
- The interval handle.public void clearTimeout(java.lang.Integer handle)
handle
- The timeout handle.public double currentTime()
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) throws IllegalActionException
message
- The messageIllegalActionException
- If the error cannot be handled.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
JavaScript.getResource(String, Object...)
.
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 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 options) throws IllegalActionException, NameDuplicationException
name
- The name of the port.options
- The options, or null to accept the defaults.IllegalActionException
- If no name is given.NameDuplicationException
- If the name is a reserved word.public boolean isRestricted()
public void log(java.lang.String message)
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.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 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 java.lang.Object setInterval(java.lang.Runnable function, java.lang.Double millisecond) throws IllegalActionException
function
- The function to invoke.millisecond
- The number of milliseconds in the future to invoke it
and the period thereafter.IllegalActionException
- If the director cannot respect the request.public java.lang.Object setTimeout(java.lang.Runnable function, java.lang.Double millisecond) throws IllegalActionException
function
- The function to invoke.millisecond
- The number of milliseconds in the future to invoke it.IllegalActionException
- If the director cannot respect the request.public void stopEnclosingModel()
public void version(java.lang.String version)
version
- Version information to appear in documentation.protected JavaScript _getActor()