jsint
Class JavaMethod

java.lang.Object
  |
  +--jsint.Procedure
        |
        +--jsint.Reflector
              |
              +--jsint.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
canAccessPrivateData, 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 canAccessPrivateData)
          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.
 boolean isStatic()
           
 java.lang.Object[] makeArgArray(java.lang.Object[] code, 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)
           
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, 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 canAccessPrivateData)
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 Symbol.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

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));
Overrides:
apply in class Procedure

makeArgArray

public java.lang.Object[] makeArgArray(java.lang.Object[] code,
                                       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)
Overrides:
makeArgArray in class Procedure