|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gnu.jel.Library
A namespace for JEL expressions.
There are two types of members in the library, those which are stateless (i.e. their value depends only on their arguments, if there are any) and stateful (also called here dynamic). The result of evaluation of stateful members may depend on other factors besides their arguments.
Examples of possible stateless members are : Math.sin(double), Math.PI.
Examples of possible stateful members are : Math.random(), System.currentTimeMillis().
Stateless members of this library are always static members of the classes, which define them. The inverse is generally not true. However, this library goes as far as assuming that static members are stateless, if this assumption does not hold for some of Your members it is possible to mark them as stateful using the markStateDependent() method of this class.
The most crucial difference between the two kind of members of this library is that evaluation of stateless methods is attempted by JEL at a compile time during the constants folding phase.
Field Summary | |
java.util.Hashtable |
cnmap
|
DVResolver |
resolver
|
Constructor Summary | |
Library(java.lang.Class[] staticLib,
java.lang.Class[] dynamicLib)
Creates a library for JEL. |
|
Library(java.lang.Class[] staticLib,
java.lang.Class[] dynamicLib,
java.lang.Class[] dotClasses)
|
|
Library(java.lang.Class[] staticLib,
java.lang.Class[] dynamicLib,
java.lang.Class[] dotClasses,
DVResolver resolver)
|
|
Library(java.lang.Class[] staticLib,
java.lang.Class[] dynamicLib,
java.lang.Class[] dotClasses,
DVResolver resolver,
java.util.Hashtable cnmap)
Creates a library for JEL. |
Method Summary | |
protected static java.lang.String |
describe(java.lang.String name,
java.lang.Class[] params)
|
java.lang.Class |
getClassByName(java.lang.String name)
|
int |
getDynamicMethodClassID(Member m)
Returns ID(position in the object array) of the dynamic Method. |
Member |
getMember(java.lang.Class container,
java.lang.String name,
java.lang.Class[] params)
Finds the member of a given class by name. |
Member |
getMember(java.lang.String name,
java.lang.Class[] params)
Used to search library for method or field. |
boolean |
isStateless(Member 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 method marks a static member 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 |
Field Detail |
public DVResolver resolver
public java.util.Hashtable cnmap
Constructor Detail |
public Library(java.lang.Class[] staticLib, java.lang.Class[] dynamicLib)
See the three argument constructor for more info.
staticLib
- is the array of classes, whose public static
methods are exported.dynamicLib
- is the array of classes, whose public virutal
methods are exported.public Library(java.lang.Class[] staticLib, java.lang.Class[] dynamicLib, java.lang.Class[] dotClasses)
public Library(java.lang.Class[] staticLib, java.lang.Class[] dynamicLib, java.lang.Class[] dotClasses, DVResolver resolver)
public Library(java.lang.Class[] staticLib, java.lang.Class[] dynamicLib, java.lang.Class[] dotClasses, DVResolver resolver, java.util.Hashtable cnmap)
The following should be kept in mind when constructing a library:
The array (dotClasses), which is the third argument of this constructor determines how (and whether) to compile the dot operators encountered in expressions. These operators are of the form
Method Detail |
public void markStateDependent(java.lang.String name, java.lang.Class[] params) throws CompilationException
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.
name
- is the function name.params
- are the possible invocation parameters of the function.CompilationException
- if the method can't be resolvedpublic boolean isStateless(Member o)
m
- is method or field to check.public java.lang.Class getClassByName(java.lang.String name)
public Member getMember(java.lang.String name, java.lang.Class[] params) throws CompilationException
The method with the same name, and closest (convertible) parameter
types is returned. If there are several methods the most specific one
is used.
Ambiguities are detected. Example of detectable ambiguity:
You want to call : someName(int, int)
There are two applicable methods : someName(int, double),
someName(double, int) , requirements to parameter types of each
of those can be satisfied by _widening_ conversions.
Those methods are same specific, there is no most specific method in
terms of Java Language Specification (15.11.2.2). Thus there is ambiguity
and null will be returned.
Java compiler normally would not allow to define such ambiguous methods in the same class. However, as this library is assembled from several Java classes such ambiguities can happen, and should be detected.
name
- is the name of the method to find.params
- are the types of formal parameters in the method invocation.CompilationException
- if the method can't be resolvedpublic Member getMember(java.lang.Class container, java.lang.String name, java.lang.Class[] params) throws CompilationException
This method is used in compiling the dot ('.') operators. It does all necessary security checks and wraps the result into one of JEL's reflection classes.
container
- the class to search the method within.name
- is the name of the method to find.params
- are the types of formal parameters in the method invocation.CompilationException
- if the method can't be resolvedprotected static java.lang.String describe(java.lang.String name, java.lang.Class[] params)
public int getDynamicMethodClassID(Member m)
ID's are used to locate the pointers to the objects, implementing dynamic methods, in the array, argument of evaluate(Object[]) function.
m
- method to get an ID of.NullPointerException
- if method is not a dynamic method of
this library.public static void main(java.lang.String[] args)
args
- ignored.public static void test(Tester t)
Used if all package is being tested and not just codegen.
t
- Tester to report test results.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |