simkin
Class ExecutableRoot

java.lang.Object
  |
  +--simkin.ExecutableRoot
All Implemented Interfaces:
Executable
Direct Known Subclasses:
Interpreter, TreeNodeObject, XMLElementObject

public class ExecutableRoot
extends java.lang.Object
implements Executable

This class provides an implementation of the Executable interface which can be conveniently extended

The class implements some commonly used methods via the method function:

  • the method "toString" which coerces the parameter to a string
  • the method "toInt" which coerces the parameter to an integer
  • the method "toFloat" which coerces the parameter to a floating point value
  • the method "toChar" which coerces the parameter to a character
  • the method "toBool" which coerces the parameter to a boolean

    It also implements all the methods of the Executable interface which means that derived classes need only implement the methods they need to override.

    The class uses the Interpreter's reflection methods to look for public fields and method names which match those being accessed by the Simkin script.


    Constructor Summary
    ExecutableRoot()
               
     
    Method Summary
     ExecutableIterator createIterator()
              Returns null - by default can't be iterated over
     ExecutableIterator createIterator(java.lang.String qualifier)
              Returns null - by default can't be iterated over
     java.util.Hashtable getAttributes()
              This method returns the attributes for this object.
     java.util.Hashtable getInstanceVariables()
              This method returns the instance variables for this object.
     java.lang.String getSource(java.lang.String location)
              This method returns the source for a scripted method described by the location.
     java.lang.Object getValue(java.lang.String field_name, java.lang.String attrib, ExecutableContext ctxt)
              This method calls the Interpreter's reflectiveGetValue method
     java.lang.Object getValueAt(java.lang.Object array_index, java.lang.String attrib, ExecutableContext ctxt)
              This method does nothing at this level
     java.lang.Object method(java.lang.String method_name, java.lang.Object[] arguments, ExecutableContext ctxt)
              The following methods are supported directly by this class:
     void setValue(java.lang.String field_name, java.lang.String attrib, java.lang.Object value, ExecutableContext ctxt)
              This method calls the Interpreter's reflectiveSetValue method
     void setValueAt(java.lang.Object array_index, java.lang.String attrib, java.lang.Object value, ExecutableContext ctxt)
              This method does nothing at this level
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    ExecutableRoot

    public ExecutableRoot()
    Method Detail

    setValue

    public void setValue(java.lang.String field_name,
                         java.lang.String attrib,
                         java.lang.Object value,
                         ExecutableContext ctxt)
                  throws java.lang.RuntimeException,
                         FieldNotSupportedException
    This method calls the Interpreter's reflectiveSetValue method

    Specified by:
    setValue in interface Executable
    Parameters:
    field_name - the name of the field
    attrib - the name of the attribute to be set (can be null)
    value - the value to be set
    ctxt - the context the function is called within
    Throws:
    java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
    FieldNotSupportedException - - if the field could not be found

    setValueAt

    public void setValueAt(java.lang.Object array_index,
                           java.lang.String attrib,
                           java.lang.Object value,
                           ExecutableContext ctxt)
                    throws java.lang.RuntimeException
    This method does nothing at this level

    Specified by:
    setValueAt in interface Executable
    Parameters:
    array_index - an object whose value indicates the index of the item in the collection
    attrib - the name of the attribute to be set (can be null)
    value - the value to be set
    ctxt - the context the function is called within
    Throws:
    java.lang.RuntimeException - - if there was a problem running the script

    getValue

    public java.lang.Object getValue(java.lang.String field_name,
                                     java.lang.String attrib,
                                     ExecutableContext ctxt)
                              throws java.lang.RuntimeException,
                                     FieldNotSupportedException
    This method calls the Interpreter's reflectiveGetValue method

    Specified by:
    getValue in interface Executable
    Parameters:
    field_name - the name of the field
    attrib - attribute name (null if no attribute specified)
    ctxt - the context the function is called within
    Returns:
    the value of the field (or null, if the field is not supported)
    Throws:
    java.lang.RuntimeException - - if there was a problem running the script (such as not having permission to access a field)
    FieldNotSupportedException - - if the field could not be found

    getValueAt

    public java.lang.Object getValueAt(java.lang.Object array_index,
                                       java.lang.String attrib,
                                       ExecutableContext ctxt)
                                throws java.lang.RuntimeException
    This method does nothing at this level

    Specified by:
    getValueAt in interface Executable
    Parameters:
    array_index - an object whose value indicates the index of the item in the collection
    attrib - attribute name (null if no attribute specified)
    ctxt - the context the function is called within
    Returns:
    the value of the object (null if not present)
    Throws:
    java.lang.RuntimeException - - if there was a problem running the script

    method

    public java.lang.Object method(java.lang.String method_name,
                                   java.lang.Object[] arguments,
                                   ExecutableContext ctxt)
                            throws ParseException,
                                   java.lang.RuntimeException,
                                   MethodNotSupportedException
    The following methods are supported directly by this class:

    trace(a) - sends a message to the trace output, takes a variable number of arguments

    isObject(a) - returns true if a is an object (as opposed to an integer or string)

    length(a) - returns the length of a (taken as a string)

    charAt(str,index) - returns the character at the given index within the string

    If the method is not one of these, the Interpreter's reflectiveMethodCall method is called

    Specified by:
    method in interface Executable
    Parameters:
    method_name - the name of the method
    arguments - an array of arguments passed to the method
    ctxt - the context the function is called within
    Returns:
    true if the method is found
    Throws:
    java.lang.RuntimeException - - if there was a problem running the script (such as divide by zero)
    ParseException
    MethodNotSupportedException

    createIterator

    public ExecutableIterator createIterator()
    Returns null - by default can't be iterated over

    Specified by:
    createIterator in interface Executable
    Returns:
    a new iterator object, or null if this object cannot be iterated

    createIterator

    public ExecutableIterator createIterator(java.lang.String qualifier)
    Returns null - by default can't be iterated over

    Specified by:
    createIterator in interface Executable
    Parameters:
    qualifier - - a string that can be used to qualify the iteration in any way
    Returns:
    a new iterator object, or null if this object cannot be iterated

    getSource

    public java.lang.String getSource(java.lang.String location)
    This method returns the source for a scripted method described by the location. At this level it returns a blank string.

    Specified by:
    getSource in interface Executable
    Parameters:
    location - the location of the method - in the format passed to the execute functions in the Interpreter
    Returns:
    the source for the method

    getInstanceVariables

    public java.util.Hashtable getInstanceVariables()
    This method returns the instance variables for this object. At this level it returns null.

    Specified by:
    getInstanceVariables in interface Executable
    Returns:
    table a table to filled with references to the instance variables. Each entry in the table maps a name to an object

    getAttributes

    public java.util.Hashtable getAttributes()
    This method returns the attributes for this object. At this level it returns null.

    Specified by:
    getAttributes in interface Executable
    Returns:
    table a table filled with the attribute values. Each entry in the table maps an attribute name to a value