org.hecl.java
Class Reflector

java.lang.Object
  extended by org.hecl.java.Reflector

public class Reflector
extends java.lang.Object

The Reflector class maps between Java types and Hecl types in order to make it possible to call Java methods from Hecl.

Version:
1.0
Author:
David N. Welton

Constructor Summary
Reflector(java.lang.String classname)
          Creates a new Reflector instance.
 
Method Summary
 Thing constructors()
          The constructors method returns a Hecl list of types that would work as constructors for this object type.
 Thing evaluate(java.lang.Object o, java.lang.String cmd, Thing[] argv)
          The evaluate method takes a target object to operate on, a methodname, and some Hecl values, and attempts to find and call a Java method with the supplied values.
 Thing getConstField(java.lang.String name)
          getConstField fetches a constant field value.
 Thing getField(java.lang.Object target, java.lang.String name)
          The getField method returns the value of an instance's field.
 boolean heclTypeToJavaType(java.lang.Object[] retval, java.lang.Class rtype, Thing heclparm)
          The heclTypeToJavaType method takes a Class and a Hecl Thing, turns the Thing into an Object based on the Class type, and returns the Object.
 Thing instantiate(Thing[] argv)
          The instantiate method is called to create an instance of a class (new, in other words).
 Thing javaTypeToHeclType(java.lang.Class rtype, java.lang.Object o)
          The javaTypeToHeclType method takes a Java type, and a Java Object, and returns a Thing.
protected  boolean mapParams(java.lang.Object[] retval, java.lang.Class[] outparams, Thing[] argv, int offset)
          The mapParams method is where a series of Hecl types/values are mapped onto Java types/values.
 Thing methods()
          The methods method returns a Hecl list of method signatures in the form methodName type type type.
 void setField(java.lang.Object target, java.lang.String name, Thing newvalue)
          The setField method takes an object, a field name, and a new Thing value, and sets the object's field to the value of Thing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflector

public Reflector(java.lang.String classname)
          throws HeclException
Creates a new Reflector instance.

Parameters:
classname - a String value describing the full name (including package) of a Java class.
Throws:
HeclException - if an error occurs
Method Detail

instantiate

public Thing instantiate(Thing[] argv)
                  throws HeclException
The instantiate method is called to create an instance of a class (new, in other words).

Parameters:
argv - a Thing value that is mapped onto Java parameters and passed to the appropriate constructor for the class.
Returns:
a Thing value
Throws:
HeclException - if an error occurs

getField

public Thing getField(java.lang.Object target,
                      java.lang.String name)
               throws HeclException
The getField method returns the value of an instance's field.

Parameters:
target - an Object value
name - a String value
Returns:
a Thing value
Throws:
HeclException - if an error occurs

setField

public void setField(java.lang.Object target,
                     java.lang.String name,
                     Thing newvalue)
              throws HeclException
The setField method takes an object, a field name, and a new Thing value, and sets the object's field to the value of Thing.

Parameters:
target - an Object value
name - a String value
newvalue - a Thing value
Throws:
HeclException - if an error occurs

getConstField

public Thing getConstField(java.lang.String name)
                    throws HeclException
getConstField fetches a constant field value.

Parameters:
name - a String value
Returns:
a Thing value
Throws:
HeclException - if an error occurs

evaluate

public Thing evaluate(java.lang.Object o,
                      java.lang.String cmd,
                      Thing[] argv)
               throws HeclException
The evaluate method takes a target object to operate on, a methodname, and some Hecl values, and attempts to find and call a Java method with the supplied values.

Parameters:
o - an Object value
cmd - a String value
argv - a Thing value
Returns:
a Thing value
Throws:
HeclException - if an error occurs

mapParams

protected boolean mapParams(java.lang.Object[] retval,
                            java.lang.Class[] outparams,
                            Thing[] argv,
                            int offset)
                     throws HeclException
The mapParams method is where a series of Hecl types/values are mapped onto Java types/values.

Parameters:
retval - an Object value
outparams - a Class value
argv - a Thing value
offset - an int value - where to start looking in argv.
Returns:
an Object[] value
Throws:
HeclException - if an error occurs

heclTypeToJavaType

public boolean heclTypeToJavaType(java.lang.Object[] retval,
                                  java.lang.Class rtype,
                                  Thing heclparm)
                           throws HeclException
The heclTypeToJavaType method takes a Class and a Hecl Thing, turns the Thing into an Object based on the Class type, and returns the Object.

Parameters:
retval - an Object value
rtype - a Class value
heclparm - a Thing value
Returns:
an Object value
Throws:
HeclException - if an error occurs

javaTypeToHeclType

public Thing javaTypeToHeclType(java.lang.Class rtype,
                                java.lang.Object o)
The javaTypeToHeclType method takes a Java type, and a Java Object, and returns a Thing.

Parameters:
rtype - a Class value
o - an Object value
Returns:
a Thing value

methods

public Thing methods()
              throws HeclException
The methods method returns a Hecl list of method signatures in the form methodName type type type.

Returns:
a Thing value
Throws:
HeclException - if an error occurs

constructors

public Thing constructors()
The constructors method returns a Hecl list of types that would work as constructors for this object type.

Returns:
a Thing value