jsint
Class JavaMethod

java.lang.Object
  extended byjsint.Procedure
      extended byjsint.Reflector
          extended byjsint.JavaMethod
All Implemented Interfaces:
java.lang.Runnable, SchemeProcedure, java.io.Serializable

public class JavaMethod
extends Reflector

This class allows you to call any Java method, just by naming it, and doing the dispatch at runtime.

Author:
Peter Norvig, Copyright 1998, peter@norvig.com, license subsequently modified by Jscheme project members licensed under zlib licence (see license.txt)
See Also:
Serialized Form

Field Summary
static java.lang.Object[] ZERO_ARGS
           
 
Fields inherited from class jsint.Reflector
isPrivileged, reflectors
 
Fields inherited from class jsint.Procedure
maxArgs, minArgs, name
 
Constructor Summary
JavaMethod(java.lang.String name, java.lang.Class c)
           
JavaMethod(java.lang.String name, java.lang.Class c, boolean isStatic)
           
JavaMethod(java.lang.String name, java.lang.Class c, boolean isStatic, boolean isPrivileged)
          If the method is static then Class c is not null.
 
Method Summary
 java.lang.Object apply(java.lang.Object[] args)
          For a static method, args is an Object[] of arguments.
 java.lang.Object[] instanceMethodTable(java.lang.Class c)
           
 boolean isStatic()
           
 java.lang.Object[] makeArgArray(java.lang.Object[] code, Evaluator eval, LexicalEnvironment lexenv)
          Take the code that represents a call, evaluate arguments in the calling lexical environment and put results into an argument array.
 java.lang.Object[] makeArgArray(Pair args)
          Convert a list of arguments into an array expected by the procedure.
protected  void reset()
          Reset your classpath dependent state.
 
Methods inherited from class jsint.Reflector
readResolve, resetAll
 
Methods inherited from class jsint.Procedure
apply, apply, catching, getName, nParms, run, setName, stripExceptionWrapper, synchronize, throwObject, throwRuntimeException, toString, toStringArgs, tryCatch, tryFinally
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO_ARGS

public static final java.lang.Object[] ZERO_ARGS
Constructor Detail

JavaMethod

public JavaMethod(java.lang.String name,
                  java.lang.Class c,
                  boolean isStatic,
                  boolean isPrivileged)
If the method is static then Class c is not null. For instance methods, if Class c is not null, then it is used at construction time to create a method table. Otherwise, the class of the method is determined at call time from the target, and the method table is constructed then and cached. Examples (see DynamicVariable.java):
      new JavaMethod("getProperties", System.class, true) - static method
      new JavaMethod("put", Hashtable.class,false)        - specific instance method.
      new JavaMethod("put", null, false)                  - unspecified instance method
      


JavaMethod

public JavaMethod(java.lang.String name,
                  java.lang.Class c,
                  boolean isStatic)

JavaMethod

public JavaMethod(java.lang.String name,
                  java.lang.Class c)
Method Detail

isStatic

public boolean isStatic()

reset

protected void reset()
Description copied from class: Reflector
Reset your classpath dependent state. This method can't be abstract.

Overrides:
reset in class Reflector

instanceMethodTable

public java.lang.Object[] instanceMethodTable(java.lang.Class c)

apply

public java.lang.Object apply(java.lang.Object[] args)
For a static method, args is an Object[] of arguments. For an instance method, args is (vector target (vector arguments));

Specified by:
apply in interface SchemeProcedure
Specified by:
apply in class Procedure

makeArgArray

public java.lang.Object[] makeArgArray(java.lang.Object[] code,
                                       Evaluator eval,
                                       LexicalEnvironment lexenv)
Description copied from class: Procedure
Take the code that represents a call, evaluate arguments in the calling lexical environment and put results into an argument array. Note that code[0] is the procedure, not an argument. For example, (p 1 2 3 (+ 2 2)) turns into the code {p, 1, 2, 3, {+, 2, 2}}, and if p has the parameter list (x y . z) then p.makeArgArray(code, lexenv) would return {1, 2, (3 4)}.

Overrides:
makeArgArray in class Procedure

makeArgArray

public java.lang.Object[] makeArgArray(Pair args)
Description copied from class: Procedure
Convert a list of arguments into an array expected by the procedure. (See apply for an explanation of what is expected.)

Overrides:
makeArgArray in class Procedure