public class RexxCompiledScript
extends javax.script.CompiledScript
implements javax.script.Invocable
javax.script.CompiledScript
class and implements
the javax.script.Invocable
interface as this only makes sense in this
class for T getInterface(Class clasz)
. Therefore the author
(Rony G. Flatscher) who served on the JSR-223 specification committee) thinkgs that the documentation
in javax.script.Invocable
is false, as it states that Invocable
gets implemented by a
ScriptEngine
, somehow indicating it has to operate on some "state" of the script engine.
ScriptEngine
sharing as much code between
the tow (and caching compiled scripts for invoking the aforementioned method in a sensible way.Modifier and Type | Field and Description |
---|---|
(package private) boolean |
bSupplyBSFExceptionObject
The value of this field controls whether
createScriptException(Exception exc) supplies
the BSFException object or not. |
(package private) java.lang.String |
editedScriptSource
The source code of the Rexx script that was compiled (tokenized).
|
(package private) java.lang.String |
filename
The filename used for evaluating (executing) the script or invoking functions or methods from the script
|
(package private) RexxProxy |
rexxPackageObject
A
RexxProxy representing the script's package (a Rexx package object). |
(package private) RexxProxy |
rexxScriptObject
The
RexxProxy representing the compiled (tokenized) script (a Rexx routine object). |
(package private) RexxScriptEngine |
rse
Field that refers to the RexxScriptEngine instance which created this RexxCompiledScript.
|
(package private) java.lang.String |
scriptSource
The source code of the Rexx script that was compiled (tokenized).
|
Constructor and Description |
---|
RexxCompiledScript(RexxScriptEngine scriptEngine,
java.lang.String scriptSource,
java.lang.String filename,
boolean bSupplyBSFExceptionObject,
RexxProxy scriptRexxProxy,
RexxProxy scriptRexxPackage)
Constructor for a compiled (tokenized) Rexx script.
|
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.Object[] |
createArgV(java.lang.Object[] args,
javax.script.ScriptContext sc,
RexxScriptEngine rse,
RexxCompiledScript rcs)
Creates and returns the argument array, append ScriptContext sc as last argument
for the Rexx script to be able to fetch it.
|
(package private) java.lang.String |
createRexxLikeConditionMessage(RexxProxy rco)
Utility method that creates the Rexx like condition message from the ooRexx condition object.
|
(package private) javax.script.ScriptException |
createScriptException(java.lang.Exception exc)
Utility method that creates a
ScriptException from the supplied Exception
object. |
java.lang.Object |
eval(javax.script.ScriptContext sc)
Evaluates (executes, runs) the Rexx program stored in this
RexxCompiledScript object. |
java.lang.String |
getEditedScriptSource()
Getter for the Rexx edited script source code which got compiled (tokenized), it will have
injected code, if any of the Rexx script annotations @GET, @GET("attribute list") or
|
RexxScriptEngine |
getEngine()
Returns the
ScriptEngine whose compile method created this CompiledScript. |
java.lang.String |
getFilename()
Getter method to return the current value of
filename . |
<T> T |
getInterface(java.lang.Class<T> clasz)
Returns an implementation of a Java interface where the Java method invocations will be carried
out by the public Rexx routines in the script.
|
<T> T |
getInterface(java.lang.Object thiz,
java.lang.Class<T> clasz)
Returns an implementation of a Java interface where the Java method invocations will be implemented
by the methods of the supplied Rexx object (a
RexxProxy . |
RexxProxy |
getPackageObject()
Getter for the
RexxProxy representing the Rexx routine object the script got compiled (tokenized) into. |
RexxScriptEngine |
getRexxScriptEngine()
Getter to retrieve the RexxScriptEngine used to create this compiled script.
|
RexxProxy |
getScriptObject()
Getter for the
RexxProxy representing the Rexx routine object the script got compiled (tokenized) to. |
java.lang.String |
getScriptSource()
Getter for the Rexx script source code.
|
boolean |
getSupplyBSFExceptionObject()
Getter for the Rexx script which got compiled (tokenized).
|
java.lang.Object |
invokeFunction(java.lang.String name,
java.lang.Object... args)
Invokes (calls) a public Rexx routine defined in this compiled script.
|
java.lang.Object |
invokeMethod(java.lang.Object thiz,
java.lang.String name,
java.lang.Object... args)
Sends a Rexx message to the Rexx object contained in the addressed
RexxProxy object. |
void |
setSupplyBSFExceptionObject(boolean newValue)
Setter for the Rexx script which got compiled (tokenized).
|
RexxScriptEngine rse
boolean bSupplyBSFExceptionObject
createScriptException(Exception exc)
supplies
the BSFException
object or not.
If set to true
the BSFException
(may contain a
RexxException
as cause) will be used to create and throw the ScriptException
.
If set to false
the (Rexx formatted) message and the line number, if available, are used
to create and throw the ScriptException
.java.lang.String filename
java.lang.String scriptSource
java.lang.String editedScriptSource
RexxProxy rexxScriptObject
RexxProxy
representing the compiled (tokenized) script (a Rexx routine object).RexxProxy rexxPackageObject
RexxProxy
representing the script's package (a Rexx package object).RexxCompiledScript(RexxScriptEngine scriptEngine, java.lang.String scriptSource, java.lang.String filename, boolean bSupplyBSFExceptionObject, RexxProxy scriptRexxProxy, RexxProxy scriptRexxPackage)
scriptSource
- - The string representing the Rexx source code.bSupplyBSFExceptionObject
- - The value that controls whether a ScriptException
.scriptRexxProxy
- - The RexxProxy
representing the Rexx routine object.scriptRexxPackage
- - The RexxProxy
representing the Rexx package object from
the scriptRexxProxy
.public RexxScriptEngine getRexxScriptEngine()
public boolean getSupplyBSFExceptionObject()
bSupplyBSFExceptionObject
public void setSupplyBSFExceptionObject(boolean newValue)
the
- value to be used for the field bSupplyBSFExceptionObject
public java.lang.String getFilename()
filename
.filename
public java.lang.String getScriptSource()
editedScriptSource
.
.public java.lang.String getEditedScriptSource()
public RexxProxy getScriptObject()
RexxProxy
representing the Rexx routine object the script got compiled (tokenized) to.RexxProxy
representing the Rexx routine objectpublic RexxProxy getPackageObject()
RexxProxy
representing the Rexx routine object the script got compiled (tokenized) into.RexxProxy
representing the Rexx package object of this compiled scriptpublic java.lang.Object eval(javax.script.ScriptContext sc) throws javax.script.ScriptException
RexxCompiledScript
object. The sc
parameter will always be passed on to the Rexx routine by storing it in a RexxDirectory
under
the index "SCRIPTCONTEXT"
and appending it as the last argument to the Rexx script.
This way any Rexx routine is able to access and manipulate the ScriptContext
.eval
in class javax.script.CompiledScript
sc
- - A ScriptContext
object, which will be supplied to the Rexx routine in a
RexxDirectory
under the index "SCRIPTCONTEXT"
, by appending
it to the Rexx argument list. (Hint: one can always access this object from Rexx code
with the statement scriptcontext=arg('A')~lastItem~scriptContext
).)
If this parameter contains a ScriptEngine.ARGV
(the String
"javax.script.argv"
) entry (a Java Object
array),
then these objects are used as arguments for the Rexx routine in the supplied order.
Java null
values will be represented as ooRexx .nil
values.
Note: If any argument is of type RexxProxy
, then the Rexx routine will
receive the contained Rexx object instead.
Note # 2: This method will append an additional Rexx directory object argument with an entry named
If this parameter contains a ScriptEngine.FILENAME
(the String
"javax.script.filename"
) entry (a string), then this is used
as the filename for the Rexx routine to execute and can be fetched from Rexx with
the statement parse source . . thisFilename
.
RexxProxy
. Supplying a RexxProxy
as an
argument to a Rexx routine will cause the contained Rexx object to be used in Rexx instead.
RexxProxy
by sending
it messages from Java using its sendMessage
methods.javax.script.ScriptException
public RexxScriptEngine getEngine()
ScriptEngine
whose compile method created this CompiledScript.getEngine
in class javax.script.CompiledScript
public <T> T getInterface(java.lang.Class<T> clasz)
Hint: when an interface method gets invoked, the Rexx routine gets all its arguments in the
same order supplied to, plus an appended RexxDirectory
"slot directory
object, which contains information about this particular method invocation. This slot directory
will also contain an entry, named "SCRIPTCONTEXT"
, which allows the
Rexx routine to fully interact with the ScriptContext
used for its invocation.
(Hint: one can always access this object from Rexx code with the statement
scriptcontext=arg('A')~lastItem~scriptContext
).)
getInterface
in interface javax.script.Invocable
clasz
- - The Java interface class object <T>
, whose methods are implemented as public Rexx routines.<T>
public <T> T getInterface(java.lang.Object thiz, java.lang.Class<T> clasz)
RexxProxy
.
Note: Uses the implementation in RexxScriptEngine.getInterface(Object thiz, Class
.
Hint #1: the external BSF4ooRexx
external Rexx function BSFCreateRexxProxy(...)
is much more versatile and among other things allows for implementing multiple Java interface
classes in a single Rexx class.
Hint #2: when an interface method gets invoked, the Rexx method routine gets all its arguments in the
same order supplied to, plus an appended RexxDirectory
"slot directory
object, which contains information about this particular method invocation. This slot directory
will also contain an entry, named "SCRIPTCONTEXT"
, which allows the
Rexx routine to fully interact with the ScriptContext
used for its invocation.
(Hint: one can always access this object from Rexx code with the statement
scriptcontext=arg('A')~lastItem~scriptContext
).)
getInterface
in interface javax.script.Invocable
thiz
- - The Java object (must be a clasz
- - The Java interface class object <T>
, whose methods are implemented in the
thiz
object<T>
public java.lang.Object invokeFunction(java.lang.String name, java.lang.Object... args) throws javax.script.ScriptException, java.lang.NoSuchMethodException
invokeFunction
in interface javax.script.Invocable
name
- - The name of the public routine to invoke.args
- - The arguments (a Java array of type Object
) for the routine.
Note # 1: If any argument is of type RexxProxy
, then the Rexx routine will
receive the contained Rexx object instead.
Note # 2: This method will append an additional Rexx directory object argument with an entry named
"SCRIPTCONTEXT"
, which allows the Rexx routine to fully interact
with the ScriptContext
used for its invocation.
(Hint: one can always access this object from Rexx code with the statement
scriptcontext=arg('A')~lastItem~scriptContext
).)
RexxProxy
. Supplying a RexxProxy
as an
argument to a Rexx routine will cause the contained Rexx object to be used in Rexx instead.
RexxProxy
by sending
it messages from Java using its sendMessage
methods or the
invokeMethod(Object thiz, String name, Object... args
method.javax.script.ScriptException
java.lang.NoSuchMethodException
public java.lang.Object invokeMethod(java.lang.Object thiz, java.lang.String name, java.lang.Object... args) throws javax.script.ScriptException, java.lang.NoSuchMethodException
RexxProxy
object.
Note: Uses the implementation in RexxScriptEngine.invokeMethod(Object thiz, String name, Object... args)
where this method belongs to.
invokeMethod
in interface javax.script.Invocable
thiz
- - The wrapped (as a name
- - The Rexx message (method) name.args
- - The arguments (a Java array of type Object
) for the Rexx method.
Note # 1: If any argument is of type RexxProxy
, then the Rexx routine will
receive the contained Rexx object instead.
Note # 2: This method will append an additional Rexx directory object argument with an entry named
"SCRIPTCONTEXT"
, which allows the Rexx routine to fully interact
with the ScriptContext
used for its invocation.
(Hint: one can always access this object from Rexx code with the statement
scriptcontext=arg('A')~lastItem~scriptContext
).)
RexxProxy
. Supplying a RexxProxy
as an
argument to a Rexx routine will cause the contained Rexx object to be used in Rexx instead.
RexxProxy
by sending
it messages from Java using its sendMessage
methods or the
invokeMethod(Object thiz, String name, Object... args
method.javax.script.ScriptException
java.lang.NoSuchMethodException
javax.script.ScriptException createScriptException(java.lang.Exception exc)
ScriptException
from the supplied Exception
object.exc
- - The Exception
object to process.ScriptException
object that either contains the supplied Exception
object as its cause. If however bSupplyBSFExceptionObject
is set to false
then a Rexx like message with a line number, if available, gets created and used for the
ScriptException
object to be returned.java.lang.String createRexxLikeConditionMessage(RexxProxy rco)
BSF4ooRexx.cc
's RgfCreateRexxlikeErrorInfo
function.)rco
- a Rexx proxy allowing access to the Rexx condition object (a Rexx directory)String
static java.lang.Object[] createArgV(java.lang.Object[] args, javax.script.ScriptContext sc, RexxScriptEngine rse, RexxCompiledScript rcs) throws javax.script.ScriptException, org.apache.bsf.BSFException
RexxCompiledScript
)
or "REXXSCRIPTENGINE" (if invoked by a RexxScriptEngine
).
Note: As of ooRexx 4.2.0 the routine's CALLWITH
method sends a MAKEARRAY
message which will compact the Java array by removing null
values (behaviour of ArrayWrapper
to mimickry the ooRexx Array MAKEARRAY
behaviour
as close as possible
(ooRexx arrays are capapble of distinguishing whether an entry is empty or is explicitly set
to .nil
). To keep the argument array intact when there are Java array entries with the
value null
a RexxProxy
for the ooRexx .nil
object is used for replacement.
the Rexx code fetching such an argument needs to unwrap the contained ooRexx .nil
object using
the external BSF function BsfRexxProxy(rexxProxy,"ooRexxObject")
.
args
- Object array with arguments to be supplied to the Rexx scriptsc
- ScriptContext to be appended to the arguments for the Rexx scriptjavax.script.ScriptException
org.apache.bsf.BSFException