murlen.util.fscript
Class FSReflectionExtension

java.lang.Object
  extended bymurlen.util.fscript.FSReflectionExtension
All Implemented Interfaces:
FSArrayExtension, FSExtension, FSFunctionExtension, FSParserExtension, FSVarExtension

public class FSReflectionExtension
extends java.lang.Object
implements FSParserExtension

ReflectionExtension - general extension for object access where either the class handles the processing (if it implements FSExtension), or reflection is used.

Copyright (C) 2002-2003

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA

Author:
Joachim Van der Auwera, murlen modifications by Joachim Van der Auwera 05.08.2002 started (Joachim) 08.09.2002 major changes to allow overloading of params for methods/fields and use of static methods/fields. (murlen) 08-10.10.2002 use Velocity introspection code for better handling of native types and improved speed 18.11.2002 imporved exception handling 28.01.2003 fixed problem with return handling on objectMethod() 15.03.2003 pluggable exception handling 28.02.2004 make nulls typed

Nested Class Summary
static interface FSReflectionExtension.ExceptionHandler
           
 class FSReflectionExtension.FSReflectionException
           
 
Constructor Summary
FSReflectionExtension()
           
 
Method Summary
 java.lang.Object callFunction(java.lang.String name, java.util.ArrayList params)
          callFunction is called whenever a function call is made in FScript to a function not defined withing hte script itself
protected  java.lang.Object getObjectVar(java.lang.Object o, java.lang.String name)
           
 java.lang.Object getVar(java.lang.String name)
          getVar is called whenever a variable is read in FScript that has not been defined within the script iteslf
 java.lang.Object getVar(java.lang.String name, java.lang.Object index)
          getVar is called whenever a variable is read in FScript that has not been defined within the script iteslf
protected  java.lang.Object objectMethod(java.lang.Object target, java.lang.String methodName, java.lang.Object[] params)
           
 void setExceptionHandler(FSReflectionExtension.ExceptionHandler eh)
          set the exception handler routine which should be called for all exceptions caused by the referenced getter and setter methods (not the exceptions while trying to call, but only the exceptions thrown by the called code).
protected  void setObjectVar(java.lang.Object o, java.lang.String name, java.lang.Object value)
           
 void setParser(murlen.util.fscript.Parser parser)
          set the parser which is used to parse the executed Fscript code
 void setVar(java.lang.String name, java.lang.Object value)
          setVar is called whenever a variable is written to in FScript that has not been defined within the script itself
 void setVar(java.lang.String name, java.lang.Object index, java.lang.Object value)
          setVar is called whenever a variable is written to in FScript that has not been defined within the script itself
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSReflectionExtension

public FSReflectionExtension()
Method Detail

setParser

public void setParser(murlen.util.fscript.Parser parser)
Description copied from interface: FSParserExtension
set the parser which is used to parse the executed Fscript code

Specified by:
setParser in interface FSParserExtension
Parameters:
parser -

getVar

public java.lang.Object getVar(java.lang.String name)
                        throws FSException
Description copied from interface: FSVarExtension

getVar is called whenever a variable is read in FScript that has not been defined within the script iteslf

Specified by:
getVar in interface FSVarExtension
Parameters:
name - the variable name
Returns:
the value of the variable (as one of FScript's supported object types)
Throws:
FSException

setVar

public void setVar(java.lang.String name,
                   java.lang.Object value)
            throws FSException
Description copied from interface: FSVarExtension

setVar is called whenever a variable is written to in FScript that has not been defined within the script itself

Specified by:
setVar in interface FSVarExtension
Parameters:
name - the variable name
value - the value to assign to the variable
Throws:
FSException

getVar

public java.lang.Object getVar(java.lang.String name,
                               java.lang.Object index)
                        throws FSException
Description copied from interface: FSArrayExtension

getVar is called whenever a variable is read in FScript that has not been defined within the script iteslf

This version allows an index variable to be supplied for array like access

Specified by:
getVar in interface FSArrayExtension
Parameters:
name - the variable name
index - the index
Returns:
the value of the variable (as one of FScript's supported object types)
Throws:
FSException

setVar

public void setVar(java.lang.String name,
                   java.lang.Object index,
                   java.lang.Object value)
            throws FSException
Description copied from interface: FSArrayExtension

setVar is called whenever a variable is written to in FScript that has not been defined within the script itself

This version allows an index variable to be supplied for array like access

Specified by:
setVar in interface FSArrayExtension
Parameters:
name - the variable name
index - the index
value - the value to assign to the variable
Throws:
FSException

callFunction

public java.lang.Object callFunction(java.lang.String name,
                                     java.util.ArrayList params)
                              throws FSException
Description copied from interface: FSFunctionExtension

callFunction is called whenever a function call is made in FScript to a function not defined withing hte script itself

Specified by:
callFunction in interface FSFunctionExtension
Parameters:
name - the name of the function
params - an array list of parameters passed to the function
Returns:
the return value (Object) of the call
Throws:
FSException

objectMethod

protected java.lang.Object objectMethod(java.lang.Object target,
                                        java.lang.String methodName,
                                        java.lang.Object[] params)
                                 throws FSException
Throws:
FSException

setObjectVar

protected void setObjectVar(java.lang.Object o,
                            java.lang.String name,
                            java.lang.Object value)
                     throws FSException
Throws:
FSException

getObjectVar

protected java.lang.Object getObjectVar(java.lang.Object o,
                                        java.lang.String name)
                                 throws FSException
Throws:
FSException

setExceptionHandler

public void setExceptionHandler(FSReflectionExtension.ExceptionHandler eh)
set the exception handler routine which should be called for all exceptions caused by the referenced getter and setter methods (not the exceptions while trying to call, but only the exceptions thrown by the called code).

Parameters:
eh - the exception handler which should be used