Class RNetscape

java.lang.Object
  |
  +--netscape.plugin.Plugin
        |
        +--RNetscape
Direct Known Subclasses:
RGraphicsPlugin

public class RNetscape
extends netscape.plugin.Plugin

A LiveConnect class that connects an embedded R interpreter/engine acting as a Plugin for Netscape with JavaScript and other plugins, allowing JavaScript code to call S functions and evaluate S expressions and for S to evaluate JavaScript code.


Field Summary
protected  boolean debug
          A flag controlling whether to display debugging information.
static boolean DefaultDebug
          This is the default setting for the debug flag that each instance of RNetscape picks up when it is created.
 
Constructor Summary
RNetscape()
          This class is never constructed via a direct call to this default constructor, but is instead instantiated in C code by the Netscape JRI directly, having obtained this class by asking the Plugin for its associated Java class.
 
Method Summary
 java.lang.Object call(java.lang.String functionName)
          This is the version of the call() function that takes no arguments, and only the name of the S function to be invoked.
 java.lang.Object call(java.lang.String functionName, netscape.javascript.JSObject jsobj)
          This is the method that is called from JavaScript when we wrapup a list of arguments there and invoke the call() method in the R interpreter object.
 java.lang.Object call(java.lang.String functionName, netscape.javascript.JSObject arg1, netscape.javascript.JSObject arg2)
          A simple and specific version of the call method that calls an S function with two arguments, both of which are JavaScript objects (i.e.
 java.lang.Object call(java.lang.String functionName, java.lang.Number arg1)
           
 java.lang.Object call(java.lang.String functionName, java.lang.Number arg1, java.lang.Number arg2)
          A simple and specific version of the call method that calls an S function with two arguments all of which are numbers (integers or reals).
 java.lang.Object call(java.lang.String functionName, java.lang.Number arg1, java.lang.Number arg2, java.lang.Number arg3)
          A simple and specific version of the call method that calls an S function with three arguments all of which are numbers (integers or reals).
 java.lang.Object call(java.lang.String functionName, java.lang.Object args)
          The generic version of the call method that determines to which of the other call methods to dispatch this invocation based on the type of the args argument.
 java.lang.Object call(java.lang.String functionName, java.lang.Object[] args)
          This is the heart of the mechanism by which JavaScript can invoke S functions, taking an arbitrary number of arguments in the form of an array.
 java.lang.Object call(java.lang.String functionName, java.lang.Object arg1, java.lang.Object arg2)
          A simple and specific version of the call method that calls an S function with two arguments which can be of any type.
 java.lang.Object call(java.lang.String functionName, java.lang.String arg1)
          A simple version of the call method that calls an S function with a single argument which is a String.
 java.lang.Object call(java.lang.String functionName, java.lang.String arg1, java.lang.Boolean arg2)
          A simple and specific version of the call method that calls an S function with two arguments which must be a String and a boolean.
 java.lang.Object call1ArgStringFunction(java.lang.String functionName, java.lang.String arg)
          This is default version of the native call1ArgString method that provides the default value (false) for the ignore argument.
 java.lang.Object call1ArgStringFunction(java.lang.String functionName, java.lang.String arg, boolean ignore)
          Native method that calls an S function with a single argument which is a string.
protected static java.lang.Object[] convertArray(netscape.javascript.JSObject jsobj)
           
 java.lang.Object eval(java.lang.String cmd)
          This allows JavaScript users to evaluate an S expression that is provided in the form of a string.
 java.lang.Object eval(java.lang.String cmd, int print)
          Calls netscapeEval() with both arguments allowing the user to control the form of the output, i.e.
 java.lang.Object evalPrint(java.lang.String cmd)
          This evaluates the specified S expression and traps any output generated (via the S functions cat() and print()) in a string and returns that.
 boolean exists(java.lang.String name)
          This is the JavaScript callable version of the S exists() function.
 boolean get(java.lang.String name)
          This retrieves the S object bound to the variable named name.
 boolean getDebug()
          Query the current setting of the debug flag.
 netscape.javascript.JSObject getDummyJSObject()
          This is a method used by the C code for the S-Netscape plugin when it is converting an S obejct to a JavaScript object and needs create a new JavaScript object instance.
 void init()
          This is called by Netscape after it has created the instance of this class for a particular page/window.
 java.lang.Object library(java.lang.String name)
          Simple access to the library function in S that allows one to specify just the name of the library to load.
 java.lang.Object namedArgCall(java.lang.String funcName, netscape.javascript.JSObject obj)
          Call to an S function identified by funcName using the members of the given obj as named arguments.
 java.lang.Object namedArgCall(java.lang.String funcName, netscape.javascript.JSObject argNames, netscape.javascript.JSObject args)
          Call an S function with named arguments, with the names in the first array and the corresponding values in the second array.
 java.lang.Object namedArgCall(java.lang.String funcName, java.lang.Object[] argNames, java.lang.Object[] args)
          Invokes the specified S function using the named arguments identified by the parallel arrays of names and values.
 void remove(java.lang.String name)
          This is the JavaScript-callable version of the S function remove().
 void setDebug(boolean val)
          Set the value of the debugging flag to control whether debugging information is displayed during the execution of the methods.
 boolean source(java.lang.String name)
          Calls the S function source() and discards the result.
 
Methods inherited from class netscape.plugin.Plugin
destroy, getPeer, getWindow, isActive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug
A flag controlling whether to display debugging information. This output will appear in the Java Console, not on the usual standard error.

DefaultDebug

public static boolean DefaultDebug
This is the default setting for the debug flag that each instance of RNetscape picks up when it is created.
Constructor Detail

RNetscape

public RNetscape()
This class is never constructed via a direct call to this default constructor, but is instead instantiated in C code by the Netscape JRI directly, having obtained this class by asking the Plugin for its associated Java class.
Method Detail

eval

public java.lang.Object eval(java.lang.String cmd)
This allows JavaScript users to evaluate an S expression that is provided in the form of a string. The argument can be a multi-expression string. The result is converted to JavaScript and returned. While this is often convenient, it is less flexible than the call(java.lang.String, java.lang.Object[]) method.
Parameters:
cmd - the S expression to be evaluated.
Returns:
the result of evaluating the S expression, converted to the corresponding JavaScript type.

eval

public java.lang.Object eval(java.lang.String cmd,
                             int print)
Calls netscapeEval() with both arguments allowing the user to control the form of the output, i.e. whether the value is printed and returned as a string or not.

evalPrint

public java.lang.Object evalPrint(java.lang.String cmd)
This evaluates the specified S expression and traps any output generated (via the S functions cat() and print()) in a string and returns that. This allows one to get the output from an S expression as it would appear in a regular S session on the console.
Parameters:
cmd - the S expression(s) to be evaluated.
Returns:
the string containing the output from evaluating the expression(s)

init

public void init()
This is called by Netscape after it has created the instance of this class for a particular page/window.
Overrides:
init in class netscape.plugin.Plugin

exists

public boolean exists(java.lang.String name)
This is the JavaScript callable version of the S exists() function. It determines whether there is an R object bound to this variable name.

library

public java.lang.Object library(java.lang.String name)
Simple access to the library function in S that allows one to specify just the name of the library to load.
Parameters:
name - the name of the library to load

source

public boolean source(java.lang.String name)
Calls the S function source() and discards the result. Currently, there is no direct way to determine if this succeeded.

remove

public void remove(java.lang.String name)
This is the JavaScript-callable version of the S function remove(). It discards the object associated with the specified variable name.

get

public boolean get(java.lang.String name)
This retrieves the S object bound to the variable named name. It is the JavaScript-callable version of the S function get().

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Object[] args)
This is the heart of the mechanism by which JavaScript can invoke S functions, taking an arbitrary number of arguments in the form of an array.
Parameters:
functionName - the name of the S function to be invoked
args - an array containing the arguments to the S function.

call

public java.lang.Object call(java.lang.String functionName)
This is the version of the call() function that takes no arguments, and only the name of the S function to be invoked.

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Object args)
The generic version of the call method that determines to which of the other call methods to dispatch this invocation based on the type of the args argument.
Parameters:
functionName - the name of the S function to invoke.
args -  

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.String arg1)
A simple version of the call method that calls an S function with a single argument which is a String.
Parameters:
functionName - the name of the S function to invoke.

call

public java.lang.Object call(java.lang.String functionName,
                             netscape.javascript.JSObject jsobj)
This is the method that is called from JavaScript when we wrapup a list of arguments there and invoke the call() method in the R interpreter object. This converts the argument list to a regular Java Object array and then calls the call(java.lang.String,java.lang.Object[])

call

public java.lang.Object call(java.lang.String functionName,
                             netscape.javascript.JSObject arg1,
                             netscape.javascript.JSObject arg2)
A simple and specific version of the call method that calls an S function with two arguments, both of which are JavaScript objects (i.e. not JavaScript primitives).
Parameters:
functionName - the name of the S function to invoke.

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Number arg1,
                             java.lang.Number arg2)
A simple and specific version of the call method that calls an S function with two arguments all of which are numbers (integers or reals).
Parameters:
functionName - the name of the S function to invoke.

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Number arg1)

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Number arg1,
                             java.lang.Number arg2,
                             java.lang.Number arg3)
A simple and specific version of the call method that calls an S function with three arguments all of which are numbers (integers or reals).
Parameters:
functionName - the name of the S function to invoke.

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.String arg1,
                             java.lang.Boolean arg2)
A simple and specific version of the call method that calls an S function with two arguments which must be a String and a boolean.
Parameters:
functionName - the name of the S function to invoke.

call

public java.lang.Object call(java.lang.String functionName,
                             java.lang.Object arg1,
                             java.lang.Object arg2)
A simple and specific version of the call method that calls an S function with two arguments which can be of any type.
Parameters:
functionName - the name of the S function to invoke.

namedArgCall

public java.lang.Object namedArgCall(java.lang.String funcName,
                                     java.lang.Object[] argNames,
                                     java.lang.Object[] args)
Invokes the specified S function using the named arguments identified by the parallel arrays of names and values.

namedArgCall

public java.lang.Object namedArgCall(java.lang.String funcName,
                                     netscape.javascript.JSObject argNames,
                                     netscape.javascript.JSObject args)
Call an S function with named arguments, with the names in the first array and the corresponding values in the second array. Example:
args = new Array(myData, "X label", "Y label");
argNames = new Array("", "xlab", "ylab");
R.namedArgCall("hist", argNames, args);

namedArgCall

public java.lang.Object namedArgCall(java.lang.String funcName,
                                     netscape.javascript.JSObject obj)
Call to an S function identified by funcName using the members of the given obj as named arguments. Example: args = new Object(); args.[0] = myData; args.xlab = "X label"; args.ylab = "Y label"; R.namedArgCall("hist", args);

getDummyJSObject

public netscape.javascript.JSObject getDummyJSObject()
This is a method used by the C code for the S-Netscape plugin when it is converting an S obejct to a JavaScript object and needs create a new JavaScript object instance.

call1ArgStringFunction

public java.lang.Object call1ArgStringFunction(java.lang.String functionName,
                                               java.lang.String arg,
                                               boolean ignore)
Native method that calls an S function with a single argument which is a string.
Parameters:
functionName - the name of the S function to be invoked
arg - the argument to the S function
ignore - indicates whether we should discard the return value or not.

call1ArgStringFunction

public java.lang.Object call1ArgStringFunction(java.lang.String functionName,
                                               java.lang.String arg)
This is default version of the native call1ArgString method that provides the default value (false) for the ignore argument.
Parameters:
functionName - the name of the S function to be invoked
arg - the argument to the S function

convertArray

protected static java.lang.Object[] convertArray(netscape.javascript.JSObject jsobj)

getDebug

public boolean getDebug()
Query the current setting of the debug flag.

setDebug

public void setDebug(boolean val)
Set the value of the debugging flag to control whether debugging information is displayed during the execution of the methods.