gnu.jel
Class Library

java.lang.Object
  |
  +--gnu.jel.Library

public class Library
extends java.lang.Object

A Library of the methods, callable from compiled expressions.

There are following constraints on the functions in the library classes:


Constructor Summary
Library(java.lang.Class[] staticLib, java.lang.Class[] dynamicLib)
          Creates a library for JEL.
 
Method Summary
 boolean isStateless(java.lang.Object o)
          Used to check if the given method is stateless.
static void main(java.lang.String[] args)
          Performs unitary test of the library.
 void markStateDependent(java.lang.String name, java.lang.Class[] params)
          This function is itended for marking static function as having the internal state.
static void test(Tester t)
          Performs unitary test of the library.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Library

public Library(java.lang.Class[] staticLib,
               java.lang.Class[] dynamicLib)
Creates a library for JEL.

The following should be kept in mind when constructing a library:

  1. This constructor may throw IllegalArgumentException if it does not like something in Your library. The requirements to the method names are somewhat more strict, than in Java as the class.method(..) syntax is not used.
  2. When calling the CompiledExpression.evaluate(Object[] dynalib) of the expression, using dynamic library methods it is needed to pass as dynalib parameter the array of objects, of the classes _exactly_ in the same order as they are appearing in the dynamicLib parameter of this constructor. If You do not allow to call dynamic methods (there is no sense, then, to use a compiler) it is possible to pass null istead of dynalib.
  3. Generally speaking, this class should not let You to create wrong libraries. It's methods will throw exceptions, return false's , ignore Your actions,... ;)
If methods in the library classes conflict with each other, the last conflicting method will be skipped. You will not get any messages unless debugging is ON (see gnu.jel.debug.Debug.enabled). This is done to avoid unnecessary error messages in the production code of the compiler.
Parameters:
staticLib - is the array of classes, whose public static methods are exported.
dynamicLib - is the array of classes, whose public virutal methods are exported.
Method Detail

markStateDependent

public void markStateDependent(java.lang.String name,
                               java.lang.Class[] params)
                        throws java.lang.NoSuchMethodException
This function is itended for marking static function as having the internal state.

If You include java.lang.Math into the library it is necessary to mark java.lang.random() as having the state. This can be done by calling markStateDependent("random",null)

Please specify parameters as close as possible, otherwise You can accidentally mark another function.

Parameters:
name - is the function name.
params - are the possible invocation parameters of the function.
Throws:
java.lang.NoSuchMethodException - if the method can't be resolved

isStateless

public boolean isStateless(java.lang.Object o)
Used to check if the given method is stateless.
Parameters:
m - is method or field to check.
Returns:
true if the method is stateless and can be invoked at compile time.

main

public static void main(java.lang.String[] args)
Performs unitary test of the library.
Parameters:
args - ignored.

test

public static void test(Tester t)
Performs unitary test of the library.

Used if all package is being tested and not just codegen.

Parameters:
t - Tester to report test results.