All Packages Class Hierarchy This Package Previous Next Index
Class gnu.jel.Library
java.lang.Object
|
+----gnu.jel.Library
- public class Library
- extends Object
A Library of the methods, callable from compiled expressions.
There are following constraints on the functions in the library
classes:
- Functions can not return objects which are changeable by other
functions in the library. The best is if the functions do not return
mutable objects at all.
- If a static function has the internal state it should be explicitly
marked as such (see markStateDependent(String name,Class[] params)).
Evaluation of stateless functions of the constant arguments will be
performed at compile time. All static library functions are initially
assumed to be state independent. The example of the function which will
certainly have to be made state dependent is java.lang.Math.random
-
Library(Class[], Class[])
- Creates a library for JEL.
-
isStateless(Method)
- Used to check if the given method is stateless.
-
main(String[])
- Performs unitary test of the library.
-
markStateDependent(String, Class[])
- This function is itended for marking static function as having the internal state.
-
test(Tester)
- Performs unitary test of the library.
Library
public Library(Class staticLib[],
Class dynamicLib[])
- Creates a library for JEL.
The following should be kept in mind when constructing a library:
- 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.
- 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.
- 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.
markStateDependent
public void markStateDependent(String name,
Class params[]) throws 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: NoSuchMethodException
- if the method can't be resolved
isStateless
public boolean isStateless(Method m)
- Used to check if the given method is stateless.
- Parameters:
- m - is the method to check.
- Returns:
- true if the method is stateless and can be invoked at
compile time.
main
public static void main(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.
All Packages Class Hierarchy This Package Previous Next Index