org.omegahat.Environment.Language
Class Method

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.omegahat.Environment.Language.Method
All Implemented Interfaces:
java.lang.Cloneable, Evaluable, java.util.Map, java.io.Serializable
Direct Known Subclasses:
UserClassMethod

public class Method
extends java.util.Hashtable
implements Evaluable, java.io.Serializable

Container for one or more functions with same name that are to be treated as a collection with calls being dispatched to the appropriate element whose signature "matches" the call. We use the Java method dispatching to implement this notion of matching and implement it by dynamically generating a class with a method for each of the functions in the table that simply identifies which function to invoke.

See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  java.lang.Class dispatchClass
          Reference to the class used to perform the identification and dispatching to the appropriate method within the table.
protected  java.util.Vector lazyArgs
          Stores a list of which arguments we know to be lazy for each of the methods.
protected  DynamicClassLoader loader
          Class loader that is capable of reading a class definition that is created on the fly via this byte compilation.
protected  java.lang.String name
          The name by which all the methods in this table are known.
protected  int version
          The version of the internal class which is incremented each time we re-define this class when methods are added or removed.
 
Constructor Summary
Method()
           
Method(Function f)
          Initialize the collection with a single function.
Method(Method m)
          Copy the contents of the given collection into this one.
Method(java.lang.String name, Function f)
          Initialize the collection with a single function and specify the name by which these functions can be called.
 
Method Summary
 void addElement(java.lang.Object obj)
           
 java.lang.Class compile()
          Define/compile the internal class used for dispatching calls to the appropriate method in the table, providing the name as the single name used for grouping all the methods in the table and the current version number which is incremented each time we add or remove a method.
 java.lang.Class createDispatchClass(java.lang.String name)
           
protected  int createJavaMethods(jas.ClassEnv env)
          Iterates over all of the methods currently stored in the table and defines a Java method corresponding to each arranging to evaluate that function when it is called.
 java.lang.Class dispatchClass()
          Retrieve the class used to perform the dispatching to the different methods, creating it if it has not been defines by this point.
 java.lang.Class dispatchClass(boolean force)
          Retrieve the internal class used for identifying the appropriate method for a call, compiling it if has not yet been defined and force is true.
 java.lang.Class dispatchClass(java.lang.Class c)
          Store the specified class definition as the internal class used for disptaching calls to the appropriate method in this table, removing any previously defined class from the loader.
 java.lang.Object eval(Evaluator evaluator)
           
 java.lang.Object eval(Function f, List args, java.lang.Object This, Evaluator evaluator)
           
 java.lang.Object eval(List args, Evaluator evaluator)
           
 java.lang.Object eval(java.lang.Object[] args, Evaluator evaluator)
           
 java.lang.Object eval(java.lang.String which, List args, java.lang.Object This, Evaluator evaluator)
           
 TypedDatabase frame(List args, Evaluator evaluator, java.lang.Class[] classes, java.util.Vector ordered)
           
 java.lang.String functionKey(Function f)
           
protected  jas.CodeAttr jasBody(java.lang.String id, int numArgs)
          Construct the body of the internal class' method that returns the key into the function table which identifies which function to invoke for the given call.
 void jasDefaultConstructor(jas.ClassEnv env)
          Create a public constructor that takes no arguments and just calls the corresponding default constructor for the class Object.
protected  jas.Method jasMethod(Function f, java.lang.String key, jas.ClassEnv env)
           
 java.util.Vector jasSignature(Function f)
          Construct the collection of signatures for the different functions stored in this method table.
protected  java.lang.Class load(java.lang.String name, jas.ClassEnv env)
          Load the class defined in the env object by writing it to a buffer and loading it via the DynamicClassLoader referring to it by the given name.
 DynamicClassLoader loader()
          Retrieve the current value of the loader field, instantiating an appropriate object if it is null.
 Function locateMethod(Database db, java.lang.Class[] classes, java.util.Vector orderedArgs, Evaluator evaluator)
           
 java.lang.Object lookupAndDispatch(List args, Evaluator evaluator)
           
 java.lang.String name()
          Return the value of the name field.
protected  java.lang.String name(java.lang.String n)
          Set and return the value of the {name field.
 void put(Function f)
           
 void put(Method m)
          Add all the functions from the other Method object specified as the argument into this table.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lazyArgs

protected java.util.Vector lazyArgs
Stores a list of which arguments we know to be lazy for each of the methods. In theory we can avoid evaluating these when determining a method if we know that all of the methods treat these as lazy.

version

protected int version
The version of the internal class which is incremented each time we re-define this class when methods are added or removed.

name

protected java.lang.String name
The name by which all the methods in this table are known. This is used as the base name for the internal class used for the method dispatching with the current count

dispatchClass

protected java.lang.Class dispatchClass
Reference to the class used to perform the identification and dispatching to the appropriate method within the table.

loader

protected transient DynamicClassLoader loader
Class loader that is capable of reading a class definition that is created on the fly via this byte compilation.
Constructor Detail

Method

public Method(Function f)
Initialize the collection with a single function.

Method

public Method(java.lang.String name,
              Function f)
Initialize the collection with a single function and specify the name by which these functions can be called.

Method

public Method()

Method

public Method(Method m)
Copy the contents of the given collection into this one. This is a shallow copy.
Method Detail

eval

public java.lang.Object eval(Evaluator evaluator)
                      throws java.lang.Throwable
Specified by:
eval in interface Evaluable

eval

public java.lang.Object eval(java.lang.Object[] args,
                             Evaluator evaluator)
                      throws java.lang.Throwable
Specified by:
eval in interface Evaluable

eval

public java.lang.Object eval(List args,
                             Evaluator evaluator)
                      throws java.lang.Throwable

eval

public java.lang.Object eval(java.lang.String which,
                             List args,
                             java.lang.Object This,
                             Evaluator evaluator)
                      throws java.lang.Throwable

eval

public java.lang.Object eval(Function f,
                             List args,
                             java.lang.Object This,
                             Evaluator evaluator)
                      throws java.lang.Throwable

addElement

public void addElement(java.lang.Object obj)

put

public void put(Function f)

put

public void put(Method m)
Add all the functions from the other Method object specified as the argument into this table.

frame

public TypedDatabase frame(List args,
                           Evaluator evaluator,
                           java.lang.Class[] classes,
                           java.util.Vector ordered)
                    throws java.lang.Throwable

lookupAndDispatch

public java.lang.Object lookupAndDispatch(List args,
                                          Evaluator evaluator)
                                   throws java.lang.Throwable

locateMethod

public Function locateMethod(Database db,
                             java.lang.Class[] classes,
                             java.util.Vector orderedArgs,
                             Evaluator evaluator)
                      throws java.lang.Exception

functionKey

public java.lang.String functionKey(Function f)

compile

public java.lang.Class compile()
Define/compile the internal class used for dispatching calls to the appropriate method in the table, providing the name as the single name used for grouping all the methods in the table and the current version number which is incremented each time we add or remove a method.

createDispatchClass

public java.lang.Class createDispatchClass(java.lang.String name)
                                    throws jas.jasError

createJavaMethods

protected int createJavaMethods(jas.ClassEnv env)
                         throws jas.jasError
Iterates over all of the methods currently stored in the table and defines a Java method corresponding to each arranging to evaluate that function when it is called.

jasMethod

protected jas.Method jasMethod(Function f,
                               java.lang.String key,
                               jas.ClassEnv env)
                        throws jas.jasError

jasBody

protected jas.CodeAttr jasBody(java.lang.String id,
                               int numArgs)
                        throws jas.jasError
Construct the body of the internal class' method that returns the key into the function table which identifies which function to invoke for the given call.

jasSignature

public java.util.Vector jasSignature(Function f)
Construct the collection of signatures for the different functions stored in this method table. Each element is a String suitable for use in the Jas byte compiler for defining a method.

jasDefaultConstructor

public void jasDefaultConstructor(jas.ClassEnv env)
                           throws jas.jasError
Create a public constructor that takes no arguments and just calls the corresponding default constructor for the class Object.

load

protected java.lang.Class load(java.lang.String name,
                               jas.ClassEnv env)
Load the class defined in the env object by writing it to a buffer and loading it via the DynamicClassLoader referring to it by the given name.

name

public java.lang.String name()
Return the value of the name field.

name

protected java.lang.String name(java.lang.String n)
Set and return the value of the {name field.

dispatchClass

public java.lang.Class dispatchClass()
Retrieve the class used to perform the dispatching to the different methods, creating it if it has not been defines by this point.

dispatchClass

public java.lang.Class dispatchClass(boolean force)
Retrieve the internal class used for identifying the appropriate method for a call, compiling it if has not yet been defined and force is true.

dispatchClass

public java.lang.Class dispatchClass(java.lang.Class c)
Store the specified class definition as the internal class used for disptaching calls to the appropriate method in this table, removing any previously defined class from the loader.

loader

public DynamicClassLoader loader()
Retrieve the current value of the loader field, instantiating an appropriate object if it is null.