org.omegahat.Interfaces.NativeInterface
Class OmegaInterfaceManager

java.lang.Object
  |
  +--org.omegahat.Environment.Interpreter.BasicEvaluator
        |
        +--org.omegahat.Environment.Interpreter.UtilityEvaluator
              |
              +--org.omegahat.Environment.Interpreter.UserClassEvaluator
                    |
                    +--org.omegahat.Environment.Interpreter.InteractiveEvaluator
                          |
                          +--org.omegahat.Interfaces.NativeInterface.OmegaInterfaceManager
All Implemented Interfaces:
org.omegahat.Environment.Databases.DatabaseCustomer, org.omegahat.Environment.Interpreter.Evaluator, org.omegahat.Environment.IO.InputConsumer, org.omegahat.Environment.Interpreter.ManagedEvaluatorInt, org.omegahat.Environment.IO.PromptSource, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
ROmegahatInterpreter

public class OmegaInterfaceManager
extends org.omegahat.Environment.Interpreter.InteractiveEvaluator

An extension of the interactive evaluator which can be used to embedded Omegahat within foreign systems such as S or R for brokering object creation and method invocation. This handles exporting named and anonymous references to the foreign system, and understands which types of objects can be converted from one system to the other. It also provides several additional convenience methods that simplify actions in the foreign system.

See Also:
Serialized Form

Field Summary
protected  org.omegahat.Environment.Databases.Database anonymousDatabase
          The database used to store the objects which are not explicitly named in a call from another system across JNI, and each is thus given an arbitrary name which is returned to the caller.
protected  ConvertibleClassifierInt converterFactory
           
protected  long count
           
protected  org.omegahat.Environment.Databases.Database db
          The default database in which objects that are exported as named references are stored.
protected  int debug
          Flag controlling whether debugging information is displayed.
static boolean PublicFlag
           
 
Fields inherited from class org.omegahat.Environment.Interpreter.InteractiveEvaluator
continuation, continuationPrompt, interrupt, notify_listeners, pendingInput, promptExpression
 
Fields inherited from class org.omegahat.Environment.Interpreter.UserClassEvaluator
classManager
 
Fields inherited from class org.omegahat.Environment.Interpreter.BasicEvaluator
allowUnrestrictedAccess, class_lists, currentExpression, data, databases, debugger, DefaultAttachIndex, defaultDatabase, dynamicClassLoader, errorHandler, evaluationEvent, evaluationListeners, initialized, internalFunctionTables, internalPrimitiveClassNames, internalPrimitiveClassTable, lexer, localClasses, manager, options, output, parser, primitive_classes, primitiveClasses, PrimitiveClassNames, primitiveTypeNames, primitiveTypes, reversePrimitiveTypes, ShowMultipleClasses, sourceStack, stderr, stdout, SubEvaluationListeners, taskHistory, toplevelExpression, warningMessages
 
Fields inherited from interface org.omegahat.Environment.Interpreter.Evaluator
ThisVariableName
 
Constructor Summary
OmegaInterfaceManager()
          Default constructor that creates its own databases for storing the named and anonymous references and registers itself as the default evaluator, creates basic variables for referencing the evaluator and manager (one and the same) from R/S.
OmegaInterfaceManager(boolean register)
          Default constructor that creates its own databases for storing the named and anonymous references and registers itself as the default evaluator
OmegaInterfaceManager(java.io.File f)
          Create the manager, reading the Options from the specified file.
OmegaInterfaceManager(java.io.InputStream stream)
          Create the manager, reading the Options name-value pairs from the specified stream.
OmegaInterfaceManager(java.lang.String name)
          Create the manager, reading the properties specifying the Options from the file identified by name or contained in the text of name if it does not refer to a file.
 
Method Summary
 java.lang.Object anonymousAssign(java.lang.Object val)
          Assign the value to the anonymous database (anonymousDatabase) using the next available counter as the key/variable name for the object.
 org.omegahat.Environment.Databases.Database anonymousDatabase()
          Retrieve a reference to the database in which the anonymous references are stored.
 org.omegahat.Environment.Databases.Database anonymousDatabase(org.omegahat.Environment.Databases.Database db)
          Set/replace the database which stores the anonymous references.
 org.omegahat.Environment.Parser.Parse.List argsToList(java.lang.String[] names)
          Construct an object that will convert the names to objects by looking up the databases.
 int arrayLength(java.lang.Object o)
           
 int assignArguments(java.lang.Object[] args, java.lang.String[] argNames)
          Iterates over the names (if there are any) and for non-empty strings, assigns the corresponding element in the object vector to that name.
 java.lang.Object assignResult(java.lang.String resultKey, java.lang.Object val)
          High-level method that determines how to process the result of a Java call (constructor, method or field access, Omegahat expression).
 java.lang.Object assignResult(java.lang.String resultKey, java.lang.Object val, boolean convert)
          If the caller allows us to convert (convert == true), then check if we can convert this object.
 java.lang.Object callConstructor(java.lang.String className, java.lang.Object[] args, java.lang.String[] argumentKeys, java.lang.String resultKey, boolean convert)
          Creates a new object of the specified class, invoking the constructor with the given arguments having assigned any with a permanent name to the regular database for future use.
 boolean clearReference(java.lang.String id, boolean named)
          Removes the specified reference identified by name in either the named or anonymous database of references.
 int clearReferences(boolean named)
          Convenience method for clearing all the references from either the named or anonymous database.
 boolean convertable(java.lang.Class c)
          Determines whether the specified object can be converted to an object in the caller's own system, or whether it should be returned as a reference to the Java object.
 boolean convertable(java.lang.Object value)
          Determines whether the specified object can be converted to an object in the caller's own system based on the class of the object.
 java.lang.Object createArray(java.lang.Class type, int[] dims)
           
 java.lang.Object createArray(java.lang.String className, int dims)
           
 java.lang.Object createArray(java.lang.String className, int[] dims)
           
 org.omegahat.Environment.Databases.Database createCallFrame(java.lang.Object[] args, java.lang.String[] argNames)
          Used when evaluating an \OMega{} expression in the manager with arguments specified in a frame like a substitute() function call in S.
 org.omegahat.Environment.Databases.Database database()
          Get a reference to the named reference database.
 org.omegahat.Environment.Databases.Database database(org.omegahat.Environment.Databases.Database d)
          Set the default database for storing named references.
 boolean debug()
          Query whether debug information is displayed.
 boolean debug(boolean d)
          Specify whether debug information is displayed.
 boolean debug(int level)
          Set the level at which debugging information should be displayed.
 boolean displayTask(org.omegahat.Environment.Interpreter.Task task)
          Consumes the output of the task, hiding it from view.
protected  java.lang.String eval(java.lang.String resultName, org.omegahat.Environment.Parser.Parse.ExpressionInt expr)
          An internal method for evaluating an expression and assigning the value to the specified name in the named database.
 java.lang.String evalConstructor(java.lang.String className, java.lang.Object[] args, java.lang.String[] argumentKeys, java.lang.String resultKey)
           
 java.lang.String evalConstructor(java.lang.String className, java.lang.String[] argumentKeys, java.lang.String resultKey)
           
 java.lang.String evalMethod(java.lang.String objKey, java.lang.String methodName, java.lang.String[] argumentKeys, java.lang.String resultKey)
           
 java.lang.Object evaluate(java.lang.String expression, java.lang.Object[] args, java.lang.String[] argNames, java.lang.String returnName, boolean convert)
          Evaluation of an Omegahat expression.
 java.lang.String expandClassName(java.lang.String name, boolean forJNI)
          A convenience method that takes the partially qualified name of a class and returns the fully qualfied name of the class to which it resolves.
 java.lang.Object genericCallMethod(org.omegahat.Environment.Language.Evaluable qualifier, java.lang.String methodName, java.lang.Object[] args, java.lang.String[] names, java.lang.String returnName, boolean convert)
          This version evaluates the target object on which the method or field access is being performed and then passes this to the the regular evaluation.
 java.lang.Object genericCallMethod(org.omegahat.Environment.Parser.Parse.MethodCall call, java.lang.String returnName, boolean convert)
           
 java.lang.Object genericCallMethod(java.lang.Object qualifier, java.lang.String methodName, java.lang.Object[] args, java.lang.String[] names, java.lang.String returnName, boolean convert)
          Invoke the method identified by methodName on the specified object - be it a expression or regular object - passing it the args as arguments.
 java.lang.Object genericCallMethod(java.lang.String[] qualifier, java.lang.Object[] args, java.lang.String[] names, java.lang.String returnName, boolean convert)
          Work horse method for the interface manager.
 java.lang.Object genericCallMethod(java.lang.String qualifier, java.lang.String methodName, java.lang.Object[] args, java.lang.String[] names, java.lang.String returnName, boolean convert)
           
 java.lang.Class[][] getAllClasses()
           
static java.lang.Class[] getArrayClasses()
           
 java.lang.Object getArrayElement(java.lang.Object o, int index)
           
 java.lang.Object getArrayElement(java.lang.Object o, int[] dims)
          Get an element from an array, possibly a multi-dimensional array
 java.lang.Object getArrayElements(java.lang.Object o, int[] indices)
          Get one or more elements from the specified array, treating the indices as entries in the top-level of the array rather than as a sequence of entries within a multi-level array that identifies a single recursive entry.
 java.lang.reflect.Constructor[] getConstructors(java.lang.Class c)
          Method to allow R calls to determine the constructors offered by a particular class.
 java.lang.reflect.Constructor[] getConstructors(java.lang.String name)
          Method to allow R calls to determine the constructors offered by a particular class which is identified by name.
 java.lang.String[] getConvertibleClasses()
          Retrieves a description (the name) of all the classes that the current ConvertibleClassifierInt considers convertible.
 ConvertibleClassifierInt getConvertibleClassifier()
          Accessor for converterFactory field
 java.lang.String getDatabaseID()
           
static java.lang.String getDataType(java.lang.Object o)
          Returns the class name of the specified object or null if the object is itself null.
 java.lang.Object getMethod(java.lang.Class c, java.lang.String methodName)
          This finds all the methods with the specified name in the given class.
 java.lang.Object getMethod(java.lang.String className, java.lang.String methodName)
          This finds all the methods with the specified name in the class identified by the (partially qualified) class name className.
 java.lang.reflect.Method[] getMethods(java.lang.Class c)
           
 java.lang.reflect.Method[] getMethods(java.lang.String className)
          Another form of the getMethods() method for use by the foreign system to discover the methods it might call on an object.
static java.lang.Class[] getPrimitiveClasses()
           
 InterfaceReference[] getReferences(boolean named)
          Method that can be easily called from R/S to retrieve a list of all the references in either the named or anonymous database.
 InterfaceReference[] getReferences(org.omegahat.Environment.Databases.Database db, boolean named)
          This is the method that computes the array of references for the elements within the specified database
 java.lang.Object getReferenceValue(java.lang.Object obj)
          Motivated by need to resolve a reference in native C code from R when creating an R-Java graphics device.
 java.lang.Object getReferenceValue(java.lang.String name, boolean anonymous)
           
static java.lang.Class[] getWrapperClasses()
           
 java.lang.Object identity(java.lang.Object o)
          A method for allowing an object in the database to be returned to the R side with a simple call as well as allowing the object to be printed here for debugging purposes.
 java.lang.Object identity(java.lang.Object o, boolean print)
           
 boolean is(java.lang.Object obj, java.lang.Class klass, boolean isInstance)
           
 boolean is(java.lang.Object obj, java.lang.String klass, boolean isInstance)
           
static boolean nativeSetup(OmegaInterfaceManager This, java.lang.Object Null)
           
 java.lang.String[] objects(boolean named)
           
 boolean remove(AnonymousReference r)
          Remove the specified reference from the anonymous database.
 boolean remove(NamedReference r)
          Remove the named reference from the named database.
 boolean remove(java.lang.Object o)
          Generic remove method that can handle an argument which is a String or a Named or Anonymous reference.
 boolean remove(java.lang.String name)
          Remove the variable from one of the evaluator manager's database.
 boolean remove(java.lang.String key, org.omegahat.Environment.Databases.Database db)
          Remove the specified variable from the given database
 void setArrayElement(java.lang.Object o, int[] dims, java.lang.Object value)
           
 void setArrayElement(java.lang.Object o, int index, java.lang.Object value)
           
 void setConvertible(java.lang.Class klass, int match, boolean ok)
           
 void setConvertible(java.lang.String className, int match, boolean ok)
           
 void setConvertibleClassifier()
           
 void setConvertibleClassifier(ConvertibleClassifierInt f)
          Accessor for converterFactory field
 boolean setDebug(int level)
          Set the level of debugging so that code segments surrounded by a call to debug(n) will only be executed if level is greater than n.
 boolean[][] testBooleanArray()
           
 boolean[][][] testBooleanArrays()
           
 double[][] testDoubleArray()
           
 int[][] testIntArray()
           
 java.lang.String[] testStringArray()
           
 java.lang.String[] testStringArray(java.lang.String[] vals)
           
 
Methods inherited from class org.omegahat.Environment.Interpreter.InteractiveEvaluator
currentExpression, deserialize, deserialize, deserialize, deserialize, deserialize, deserialize, evaluate, inputReady, inputReady, interrupt, notify_listeners, notify_listeners, notifyListeners, parserError, prompt, promptExpression, promptExpression, promptExpression, serialize, serialize, serialize, serialize
 
Methods inherited from class org.omegahat.Environment.Interpreter.UserClassEvaluator
addMethod, classManager, classManager, createInstance, createInstance, createInstance, defineClass, defineClass, defineClass, defineClass, defineClass, defineClass, DefineUserClass, DefineUserClass, DefineUserClass, findUserClass, findUserClass, parseClass, parser
 
Methods inherited from class org.omegahat.Environment.Interpreter.UtilityEvaluator
evaluator, exec, exec, findFile, getEvaluator, setProperty, setProperty
 
Methods inherited from class org.omegahat.Environment.Interpreter.BasicEvaluator
addEvaluationListener, addFunctionTable, addFunctionTable, addSourceInput, addToHistory, allowUnrestrictedAccess, allowUnrestrictedAccess, asObject, asObject, asObject, asObjectName, asPrimitiveClass, assign, assign, assign, asWriter, attach, attach, attach, attach, attach, attach, attach, classInit, classLists, classLists, classPath, classPath, commandLine, convertPrimitive, copy, copy, copyByConstructor, copyBySerialization, createClassLists, currentExpression, data, data, database, database, Debug, Debug, Debug, Debug, Debug, debugger, debugger, defaultDatabase, defaultDatabase, defaultDatabase, defaultErrorHandler, detach, detach, displayTask, displayWarnings, displayWarnings, dynamicClassLoader, dynamicClassLoader, endSource, endSource, endSource, endTaskEvaluation, error, error, errorHandler, errorHandler, evaluate, evaluate, evaluate, evaluationError, evaluationListeners, evaluationListeners, evaluationListeners, exists, exit, exit, expandClassName, expandedClassPathElement, find, findAsField, findClass, findClass, findClass, findClass, findFunction, findFunctionOrMethod, functionTableList, get, get, get, get, get, get, get, get, get, getBaseURL, getEvaluationEvent, getEvaluationListeners, getField, getSubEvaluationListeners, help, Import, Import, Import, init, initialize, initTaskEvaluation, internalFunctionTables, isPrimitive, isPrimitive, javaVersion, lexer, lexer, lexer, localClasses, localClasses, manager, manager, newDatabase, newDatabase, notifyListeners, objects, objects, objects, options, options, output, output, output, parse, parse, parse, parse, primitiveClass, q, q, remove, removeFunctionTable, run, same, searchForClass, searchPath, searchPath, searchPath, searchPath, setEvaluationEvent, setEvaluationListeners, setSubEvaluationListeners, show, show, show, source, source, source, source, source, source, source, source, source, sourceStack, stderr, stderr, stdout, stdout, taskHistory, taskHistory, toplevelExpression, toplevelExpression, useLazyEvaluation, warning, warning, warning, warnings, warnings, where, which, which
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PublicFlag

public static boolean PublicFlag

anonymousDatabase

protected org.omegahat.Environment.Databases.Database anonymousDatabase
The database used to store the objects which are not explicitly named in a call from another system across JNI, and each is thus given an arbitrary name which is returned to the caller.

db

protected org.omegahat.Environment.Databases.Database db
The default database in which objects that are exported as named references are stored. This is attach as the value of defaultDatabase().

debug

protected int debug
Flag controlling whether debugging information is displayed.

count

protected long count

converterFactory

protected ConvertibleClassifierInt converterFactory
Constructor Detail

OmegaInterfaceManager

public OmegaInterfaceManager()
Default constructor that creates its own databases for storing the named and anonymous references and registers itself as the default evaluator, creates basic variables for referencing the evaluator and manager (one and the same) from R/S. This also sets the output stream of the evaluator to null, just like disablin standard output since this is being run as an embedded Omegahat/Java evaluator inside R.

OmegaInterfaceManager

public OmegaInterfaceManager(boolean register)
Default constructor that creates its own databases for storing the named and anonymous references and registers itself as the default evaluator

OmegaInterfaceManager

public OmegaInterfaceManager(java.io.InputStream stream)
Create the manager, reading the Options name-value pairs from the specified stream.
Parameters:
stream - input stream containing the name-value property values parameterizing the manager and its options.

OmegaInterfaceManager

public OmegaInterfaceManager(java.io.File f)
Create the manager, reading the Options from the specified file.
Parameters:
f - the file containing the name-value properties parameterizing the manager and its different options.

OmegaInterfaceManager

public OmegaInterfaceManager(java.lang.String name)
                      throws java.lang.Throwable
Create the manager, reading the properties specifying the Options from the file identified by name or contained in the text of name if it does not refer to a file.
Method Detail

getWrapperClasses

public static java.lang.Class[] getWrapperClasses()

getPrimitiveClasses

public static java.lang.Class[] getPrimitiveClasses()

getArrayClasses

public static java.lang.Class[] getArrayClasses()

getAllClasses

public java.lang.Class[][] getAllClasses()

debug

public boolean debug()
Query whether debug information is displayed.

debug

public boolean debug(int level)
Set the level at which debugging information should be displayed. One can conditionally execute code at different levels of debugging such as
if(debug(3)) {
// execute some code
}
which allows the user to skip over code by setting the debug level to exclude that level and higher.

debug

public boolean debug(boolean d)
Specify whether debug information is displayed.

setDebug

public boolean setDebug(int level)
Set the level of debugging so that code segments surrounded by a call to debug(n) will only be executed if level is greater than n.
Parameters:
level - the value above which debugging output is not displayed

eval

protected java.lang.String eval(java.lang.String resultName,
                                org.omegahat.Environment.Parser.Parse.ExpressionInt expr)
                         throws java.lang.Throwable
An internal method for evaluating an expression and assigning the value to the specified name in the named database. This is called by other methods that take the expression formulation from R/S as a string and convert it to an expression.
See Also:
evalConstructor(String,String[],String)

callConstructor

public java.lang.Object callConstructor(java.lang.String className,
                                        java.lang.Object[] args,
                                        java.lang.String[] argumentKeys,
                                        java.lang.String resultKey,
                                        boolean convert)
                                 throws java.lang.Throwable
Creates a new object of the specified class, invoking the constructor with the given arguments having assigned any with a permanent name to the regular database for future use. The usual "conversion" mechanism is employed to provide the return value. See assignResult

This is usually invoked by the calling interface from S or R.

Parameters:
className - the partially qualified name of a Java class sufficient to identify the appropriate class using the class lookup mechanism of Omegahat.
args - an array of arguments which are passed to the appropriate constructor of the specified class.
argumentKeys - either null or an array of names parallel to the args array in which any non-trivial values cause that value to be "permanently" assigned as Omegahat variables in the default database associated with this manager.
resultKey - the name of the Omegahat variable to which the result should be assigned, or null or "" to cause it be anonyomized or converted.

evalConstructor

public java.lang.String evalConstructor(java.lang.String className,
                                        java.lang.String[] argumentKeys,
                                        java.lang.String resultKey)
                                 throws java.lang.Throwable

evalConstructor

public java.lang.String evalConstructor(java.lang.String className,
                                        java.lang.Object[] args,
                                        java.lang.String[] argumentKeys,
                                        java.lang.String resultKey)

evalMethod

public java.lang.String evalMethod(java.lang.String objKey,
                                   java.lang.String methodName,
                                   java.lang.String[] argumentKeys,
                                   java.lang.String resultKey)
                            throws java.lang.Throwable

argsToList

public org.omegahat.Environment.Parser.Parse.List argsToList(java.lang.String[] names)
Construct an object that will convert the names to objects by looking up the databases.

anonymousAssign

public java.lang.Object anonymousAssign(java.lang.Object val)
                                 throws java.lang.Exception
Assign the value to the anonymous database (anonymousDatabase) using the next available counter as the key/variable name for the object.
Returns:
the name used as the variable in the database for storing this value. This is guaranteed to be unique (up to a very large number of objects being added!)

remove

public boolean remove(java.lang.String name)
Remove the variable from one of the evaluator manager's database. This calls the standard remove method from Evaluator and if this fails (because there is no such variable there), then we look in the anonymous database and attempt to do the same.
Overrides:
remove in class org.omegahat.Environment.Interpreter.BasicEvaluator
See Also:
clearReference(String,boolean)

remove

public boolean remove(java.lang.Object o)
               throws java.lang.Exception
Generic remove method that can handle an argument which is a String or a Named or Anonymous reference.

remove

public boolean remove(NamedReference r)
Remove the named reference from the named database.

remove

public boolean remove(AnonymousReference r)
Remove the specified reference from the anonymous database.

remove

public boolean remove(java.lang.String key,
                      org.omegahat.Environment.Databases.Database db)
Remove the specified variable from the given database
Overrides:
remove in class org.omegahat.Environment.Interpreter.BasicEvaluator
Returns:
true if the database has a variable with the given name (and it was removed).

getReferenceValue

public java.lang.Object getReferenceValue(java.lang.Object obj)
                                   throws java.lang.Throwable
Motivated by need to resolve a reference in native C code from R when creating an R-Java graphics device.

getReferenceValue

public java.lang.Object getReferenceValue(java.lang.String name,
                                          boolean anonymous)

genericCallMethod

public java.lang.Object genericCallMethod(java.lang.String[] qualifier,
                                          java.lang.Object[] args,
                                          java.lang.String[] names,
                                          java.lang.String returnName,
                                          boolean convert)
Work horse method for the interface manager. Handles field access and method calls for instance and static calls.

genericCallMethod

public java.lang.Object genericCallMethod(java.lang.String qualifier,
                                          java.lang.String methodName,
                                          java.lang.Object[] args,
                                          java.lang.String[] names,
                                          java.lang.String returnName,
                                          boolean convert)

genericCallMethod

public java.lang.Object genericCallMethod(java.lang.Object qualifier,
                                          java.lang.String methodName,
                                          java.lang.Object[] args,
                                          java.lang.String[] names,
                                          java.lang.String returnName,
                                          boolean convert)
                                   throws java.lang.Throwable
Invoke the method identified by methodName on the specified object - be it a expression or regular object - passing it the args as arguments. This is called from the native C routines that form the bridge between R/S and Omegahat. The names argument specifies which of the arguments are to be stored in the regular named database for use in future calls from the foreign system.
Parameters:
qualifier - an object from which we derive the actual object whose method is to be invoked. This object becomes the this in the method call. The argument can be an actual object or an expression which is evaluated to produce the target object.
the - name of the method in the qualfier object's class that is to be invoked. The types of the arguments allow Omegahat to determine the appropriate method with this name even with method overloading.
args - the collection of arguments to be passed to the method call that is being invoked here.
returnName - if this is non-null, the return value from the method call is stored in the named database and no attempt to convert to the foreign system is made. A reference to the object is passed to that foreign system. This naming mechanism allows one to store an intermediate object that is to be used in future calls from the foreign system.
convert - whether to attempt to convert the return value of the method call when passing it back to the foreign system. If this is false, we just assign it to the anonymous database and return a reference to it. Otherwise, Omegahat determines whether the object is convertible and if so passes it to the C routines that perform the conversion to an object in the foreign system.

genericCallMethod

public java.lang.Object genericCallMethod(org.omegahat.Environment.Language.Evaluable qualifier,
                                          java.lang.String methodName,
                                          java.lang.Object[] args,
                                          java.lang.String[] names,
                                          java.lang.String returnName,
                                          boolean convert)
                                   throws java.lang.Throwable
This version evaluates the target object on which the method or field access is being performed and then passes this to the the regular evaluation.

genericCallMethod

public java.lang.Object genericCallMethod(org.omegahat.Environment.Parser.Parse.MethodCall call,
                                          java.lang.String returnName,
                                          boolean convert)

assignArguments

public int assignArguments(java.lang.Object[] args,
                           java.lang.String[] argNames)
Iterates over the names (if there are any) and for non-empty strings, assigns the corresponding element in the object vector to that name. This is used to make arguments \OMega{} variables that are available in future calls.

evaluate

public java.lang.Object evaluate(java.lang.String expression,
                                 java.lang.Object[] args,
                                 java.lang.String[] argNames,
                                 java.lang.String returnName,
                                 boolean convert)
Evaluation of an Omegahat expression. Additional variables are provided in the @args array and are referenced in the expression by the names provided in the @argNames argument.

createCallFrame

public org.omegahat.Environment.Databases.Database createCallFrame(java.lang.Object[] args,
                                                                   java.lang.String[] argNames)
Used when evaluating an \OMega{} expression in the manager with arguments specified in a frame like a substitute() function call in S. The arguments are reference by name in the expression, converted from user-level objects to Java objects and stored in this frame.

database

public org.omegahat.Environment.Databases.Database database()
Get a reference to the named reference database.
Overrides:
database in class org.omegahat.Environment.Interpreter.BasicEvaluator

database

public org.omegahat.Environment.Databases.Database database(org.omegahat.Environment.Databases.Database d)
Set the default database for storing named references.

anonymousDatabase

public org.omegahat.Environment.Databases.Database anonymousDatabase()
Retrieve a reference to the database in which the anonymous references are stored.

anonymousDatabase

public org.omegahat.Environment.Databases.Database anonymousDatabase(org.omegahat.Environment.Databases.Database db)
Set/replace the database which stores the anonymous references.

getConvertibleClassifier

public ConvertibleClassifierInt getConvertibleClassifier()
Accessor for converterFactory field

setConvertibleClassifier

public void setConvertibleClassifier(ConvertibleClassifierInt f)
Accessor for converterFactory field

setConvertibleClassifier

public void setConvertibleClassifier()

convertable

public boolean convertable(java.lang.Object value)
Determines whether the specified object can be converted to an object in the caller's own system based on the class of the object.
Returns:
logical indicating whether the object is convertible or not.
See Also:
#convertTable(java.lang.Class)

convertable

public boolean convertable(java.lang.Class c)
Determines whether the specified object can be converted to an object in the caller's own system, or whether it should be returned as a reference to the Java object.

This is based on the set of primitives known to the interface at compile time. At present this knows about the S/R and Java primitives. We can extend this to maintain a collection of additional Java and target-classes between which objects can be converted and the factory which can perform such conversions.


assignResult

public java.lang.Object assignResult(java.lang.String resultKey,
                                     java.lang.Object val)
High-level method that determines how to process the result of a Java call (constructor, method or field access, Omegahat expression). If the value val is convertible to a primitive type, then we simply return it. Otherwise, if the name to be used to store the value (resultKey) is non-trivial (i.e. is not null or ""), then we assign the value to the default database and create and return a NamedReference object. Otherwise, we create an AnonymousReference object, having assigned the value to the anonymousDatabase and return the reference.
Parameters:
resultKey - the name of the Omegahat variable to which the value should be assigned in the regular database, or null or "" indicating that we do not want it considered as an Omegahat variable.
val - the result of a Java call which is to be "returned" to the caller across the interface.
Returns:
either the object itself, if it is a "primitive" that can be converted to an object in the callers language, or a specific instance of InterfaceReference.
See Also:
#convertable().

assignResult

public java.lang.Object assignResult(java.lang.String resultKey,
                                     java.lang.Object val,
                                     boolean convert)
If the caller allows us to convert (convert == true), then check if we can convert this object. Otherwise, we claim it is not convertable and create a reference. If resultKey is non-null (or ""), then we create a named reference. Otherwise, an anonymous reference.
See Also:
convertable(Object)

getDatabaseID

public java.lang.String getDatabaseID()

getDataType

public static java.lang.String getDataType(java.lang.Object o)
Returns the class name of the specified object or null if the object is itself null. This is used in the C code communicating with the manager, although it may not be used anymore since we do not perform the recursive copies.

getMethod

public java.lang.Object getMethod(java.lang.String className,
                                  java.lang.String methodName)
                           throws java.lang.ClassNotFoundException
This finds all the methods with the specified name in the class identified by the (partially qualified) class name className.
Parameters:
className - the partially qualified name of a class which is resolved by this evaluator using findClass().
methodName - the name of the method(s) of interest.
Returns:
either a Method object or an array of these objects.
See Also:
getMethod(Class,String)

getMethod

public java.lang.Object getMethod(java.lang.Class c,
                                  java.lang.String methodName)
This finds all the methods with the specified name in the given class.
Parameters:
c - the class in which to look for the methods with the name methodName
methodName - the name of the method(s) of interest.
Returns:
either a Method object or an array of these objects.
See Also:
getMethod(Class,String)

getMethods

public java.lang.reflect.Method[] getMethods(java.lang.String className)
                                      throws java.lang.ClassNotFoundException
Another form of the getMethods() method for use by the foreign system to discover the methods it might call on an object.

getMethods

public java.lang.reflect.Method[] getMethods(java.lang.Class c)

getConstructors

public java.lang.reflect.Constructor[] getConstructors(java.lang.String name)
                                                throws java.lang.ClassNotFoundException
Method to allow R calls to determine the constructors offered by a particular class which is identified by name.
See Also:
getConstructors(Class)

getConstructors

public java.lang.reflect.Constructor[] getConstructors(java.lang.Class c)
Method to allow R calls to determine the constructors offered by a particular class.

getReferences

public InterfaceReference[] getReferences(boolean named)
Method that can be easily called from R/S to retrieve a list of all the references in either the named or anonymous database. The internal default converters handle creating R objects from the Java references returned.
See Also:
getReferences(Database, boolean)

getReferences

public InterfaceReference[] getReferences(org.omegahat.Environment.Databases.Database db,
                                          boolean named)
This is the method that computes the array of references for the elements within the specified database

clearReferences

public int clearReferences(boolean named)
Convenience method for clearing all the references from either the named or anonymous database. This can be called directly from R/S as
.Java(NULL, "clearReferences",T)
.Java(NULL, "clearReferences",F)

clearReference

public boolean clearReference(java.lang.String id,
                              boolean named)
Removes the specified reference identified by name in either the named or anonymous database of references. This is very similar to remove(String). It differs in that it supports specification of which reference database the reference resides. It can be called directly from R/S as
.Java(NULL, "clearReferences", "b", T)

displayTask

public boolean displayTask(org.omegahat.Environment.Interpreter.Task task)
Consumes the output of the task, hiding it from view.
Overrides:
displayTask in class org.omegahat.Environment.Interpreter.BasicEvaluator

expandClassName

public java.lang.String expandClassName(java.lang.String name,
                                        boolean forJNI)
A convenience method that takes the partially qualified name of a class and returns the fully qualfied name of the class to which it resolves.
Parameters:
name - the partially qualified name of the class of interest.
forJNI - whether the resulting fully-qualified class name should be given as a dot-separated (.) or slash-separated (/). The former is the regular Java style. The latter allows the resulting name to be used directly by native code such as JNI (and also in the Jas byte-code compiler classes).

setConvertible

public void setConvertible(java.lang.String className,
                           int match,
                           boolean ok)
                    throws java.lang.ClassNotFoundException
See Also:
ConvertibleClassifier.setConvertible(Class, int, boolean), setConvertible(String,int,boolean)

setConvertible

public void setConvertible(java.lang.Class klass,
                           int match,
                           boolean ok)

getConvertibleClasses

public java.lang.String[] getConvertibleClasses()
Retrieves a description (the name) of all the classes that the current ConvertibleClassifierInt considers convertible.
See Also:
#convertibleClassifier

createArray

public java.lang.Object createArray(java.lang.String className,
                                    int dims)
                             throws java.lang.ClassNotFoundException

createArray

public java.lang.Object createArray(java.lang.String className,
                                    int[] dims)
                             throws java.lang.ClassNotFoundException

createArray

public java.lang.Object createArray(java.lang.Class type,
                                    int[] dims)
                             throws java.lang.ClassNotFoundException

getArrayElement

public java.lang.Object getArrayElement(java.lang.Object o,
                                        int index)

getArrayElement

public java.lang.Object getArrayElement(java.lang.Object o,
                                        int[] dims)
Get an element from an array, possibly a multi-dimensional array

getArrayElements

public java.lang.Object getArrayElements(java.lang.Object o,
                                         int[] indices)
                                  throws java.lang.Throwable
Get one or more elements from the specified array, treating the indices as entries in the top-level of the array rather than as a sequence of entries within a multi-level array that identifies a single recursive entry.

setArrayElement

public void setArrayElement(java.lang.Object o,
                            int index,
                            java.lang.Object value)

setArrayElement

public void setArrayElement(java.lang.Object o,
                            int[] dims,
                            java.lang.Object value)

arrayLength

public int arrayLength(java.lang.Object o)

testStringArray

public java.lang.String[] testStringArray()

testStringArray

public java.lang.String[] testStringArray(java.lang.String[] vals)

objects

public java.lang.String[] objects(boolean named)

is

public boolean is(java.lang.Object obj,
                  java.lang.String klass,
                  boolean isInstance)
           throws java.lang.ClassNotFoundException

is

public boolean is(java.lang.Object obj,
                  java.lang.Class klass,
                  boolean isInstance)

identity

public java.lang.Object identity(java.lang.Object o)
A method for allowing an object in the database to be returned to the R side with a simple call as well as allowing the object to be printed here for debugging purposes. From R, this can be called something like
.Java(NULL, "identity", ref, .convert=F)

identity

public java.lang.Object identity(java.lang.Object o,
                                 boolean print)

nativeSetup

public static boolean nativeSetup(OmegaInterfaceManager This,
                                  java.lang.Object Null)

testIntArray

public int[][] testIntArray()

testBooleanArray

public boolean[][] testBooleanArray()

testDoubleArray

public double[][] testDoubleArray()

testBooleanArrays

public boolean[][][] testBooleanArrays()