org.omegahat.Interfaces.NativeInterface
Class ForeignReference

java.lang.Object
  |
  +--org.omegahat.Interfaces.NativeInterface.ForeignReference
All Implemented Interfaces:
ForeignReferenceInt
Direct Known Subclasses:
RForeignReference

public class ForeignReference
extends java.lang.Object
implements ForeignReferenceInt

An abstract class that implements the basic functionality for converting a foreign reference (i.e. an object exported from R or S) to an appropriate Java object. This contains information identifying the R/S object and the target Java class. If the class does not exist (or is not likely to) the object can be initialized with the names of classes and interfaces which a dynamically generated class should extend and implement, respectively The foreign reference is then converted to an instance of this class so that it can be used appropriately. This new instance implements its methods via calls back to the foreign system and methods for the specified remote object. This is used as a transfer agent between the foreign system and Omegahat/Java. The foreign system creates an object of this class via C routines and then passes this object to the Omegahat system as an argument in a method call.


Field Summary
protected  OmegaInterfaceManager evaluator
           
protected  java.lang.String name
          The identifier of the object in the foreign system.
 
Constructor Summary
ForeignReference(ForeignReference ref)
           
ForeignReference(ForeignReference ref, OmegaInterfaceManager evaluator)
           
ForeignReference(java.lang.String id)
           
ForeignReference(java.lang.String id, OmegaInterfaceManager evaluator)
           
 
Method Summary
 java.lang.Object convertResult(java.lang.Object value, java.lang.String type)
          This is used to convert the object the foreign system (e.g R/S) gives us when we call a function in that system from a dynamically generated Java method (e.g.
 java.lang.Object eval(org.omegahat.Environment.Parser.Parse.List args, java.lang.String methodName, java.lang.String returnClass, java.lang.String[] jsignature)
          The method that performs the callback to the foreign system and arranges to resolve the reference, convert the arguments, invoke the appropriate method identified by methodName, convert the return value, etc.
 OmegaInterfaceManager getEvaluator()
          Accessor for evaluator field.
 java.lang.String getReferenceName()
          Accessor for name field
protected  java.lang.Object processArg(java.lang.Object arg)
          Convert an argument to an anonymous reference, or leave as is.
protected  java.lang.Object[] processArgs(org.omegahat.Environment.Parser.Parse.List args)
          Iterates over the specified arguments and processes each one so it can be passed to the native method which will call the foreign system - R or S - converting non-convertable objects to anonymous references.
protected  int removeTemporaryAnonymousReferences(java.lang.Object[] args, org.omegahat.Environment.Parser.Parse.List l)
          Used to clean up any anonymous references created by processArgs() before the call to the foreign system.
 OmegaInterfaceManager setEvaluator(OmegaInterfaceManager value)
          Accessor for setting evaluator field
 java.lang.String setReferenceName(java.lang.String value)
          Accessor for name field
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The identifier of the object in the foreign system.

evaluator

protected OmegaInterfaceManager evaluator
Constructor Detail

ForeignReference

public ForeignReference(java.lang.String id)

ForeignReference

public ForeignReference(java.lang.String id,
                        OmegaInterfaceManager evaluator)

ForeignReference

public ForeignReference(ForeignReference ref)

ForeignReference

public ForeignReference(ForeignReference ref,
                        OmegaInterfaceManager evaluator)
Method Detail

processArgs

protected java.lang.Object[] processArgs(org.omegahat.Environment.Parser.Parse.List args)
                                  throws java.lang.Exception
Iterates over the specified arguments and processes each one so it can be passed to the native method which will call the foreign system - R or S - converting non-convertable objects to anonymous references.

processArg

protected java.lang.Object processArg(java.lang.Object arg)
                               throws java.lang.Exception
Convert an argument to an anonymous reference, or leave as is.

removeTemporaryAnonymousReferences

protected int removeTemporaryAnonymousReferences(java.lang.Object[] args,
                                                 org.omegahat.Environment.Parser.Parse.List l)
Used to clean up any anonymous references created by processArgs() before the call to the foreign system.

eval

public java.lang.Object eval(org.omegahat.Environment.Parser.Parse.List args,
                             java.lang.String methodName,
                             java.lang.String returnClass,
                             java.lang.String[] jsignature)
                      throws java.lang.Exception
The method that performs the callback to the foreign system and arranges to resolve the reference, convert the arguments, invoke the appropriate method identified by methodName, convert the return value, etc. This is currently implemented as a dummy version that prints its information. It is left up to the sub-classes to perform the actual call to the host system (R or S).
Specified by:
eval in interface ForeignReferenceInt

convertResult

public java.lang.Object convertResult(java.lang.Object value,
                                      java.lang.String type)
                               throws java.lang.Throwable
This is used to convert the object the foreign system (e.g R/S) gives us when we call a function in that system from a dynamically generated Java method (e.g. via the method eval(List, String, String, String[]).

getReferenceName

public java.lang.String getReferenceName()
Accessor for name field
Specified by:
getReferenceName in interface ForeignReferenceInt

setReferenceName

public java.lang.String setReferenceName(java.lang.String value)
Accessor for name field

getEvaluator

public OmegaInterfaceManager getEvaluator()
Accessor for evaluator field. This can now compute its evaluator if it has not been previously set.
See Also:
org.omegahat.Environment.System.Globals#evaluator()

setEvaluator

public OmegaInterfaceManager setEvaluator(OmegaInterfaceManager value)
Accessor for setting evaluator field

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object