The BooleanEval Component
The BooleanEval component provides a convenience API for evaluating boolean expressions in xADL documents. The BooleanEval component provides 2 functions specified by IBooleanEval:
The eval
method is responsible for evaluating a boolean
expression based on the symbol table passed in. For more information on
the symbol table, go here. If a variable in the expression is not defined (no value in the symbol table), it will evaluate the
expression as much as possible (taking advantage of short-circuiting). Its Javadoc is shown
here:
evalpublic ObjRef eval( ObjRef exp, SymbolTable symTable) throws MissingElementException, NoSuchTypeException, TypeMismatchException;
|
A call to this function looks like this:
/* Now in implementation... extract the boolean expression from Boolean Guards
and store it into an ObjRef called boolExp, also a instance of SymbolTable
called symTab*/
/* Obtain a reference to the boolean eval component... (in the EBI wrapper C2
component)*/
For example, if symbol table contained:
IBooleanEval boolEval = ( IBooleanEval )EBIWrapperUtils.addExternalService(
this, topIface, IBooleanEval.class );
...
ObjRef result = boolEval.eval( boolExp, symTab );
a = 1
b = 2
The the following expressions would return expressions containing:
b >= a --> TRUE
a == 1 && z > 0 --> z > 0
a != 1 && z > 0 --> FALSE
a == 1 || z > 0 --> TRUE
a != 1 || z > 0 --> z > 0
The boolValue
method provides a simple way to extract the
boolean value of a boolean value represented by an ObjRef (ie. ObjRef to an
IBool). Its Javadoc is shown here:
boolValuepublic boolean boolValue( ObjRef bool ) throws MissingElementException, TypeMismatchException;
|
This function is can be used to determine the results of the evaluation:
/* Now in implementation... extract the boolean expression from Boolean Guards
and store it into an ObjRef called boolExp, also a instance of SymbolTable
called symTab*/
// code from above repeated for convenience
/* Obtain a reference to the boolean eval component... (in the EBI wrapper C2
component)*/
IBooleanEval boolEval = ( IBooleanEval )EBIWrapperUtils.addExternalService(
this, topIface, IBooleanEval.class );
...
ObjRef result = boolEval.eval( boolExp, symTab );
ObjRef bool = ( ObjRef )xArch.get( result, "Bool" );
// check to see if it could be evaluated
if( bool != null )
{
// was true
if( boolEval.boolValue( bool )
{
...
}
// was false
else
{
...
}
}
// partial eval
else
{
...
}
Additional questions about the BooleanEval should be sent to Ping H. Chen.