uk.ac.starlink.ttools.jel
Class JELUtils

java.lang.Object
  extended by uk.ac.starlink.ttools.jel.JELUtils

public class JELUtils
extends Object

This class provides some utility methods for use with the JEL expression compiler.

Since:
11 Feb 2005
Author:
Mark Taylor (Starlink)

Field Summary
static String CLASSES_PROPERTY
          System property name for adding colon-separated list of additional classnames containing static methods.
 
Constructor Summary
JELUtils()
           
 
Method Summary
static void checkExpressionType(gnu.jel.Library lib, uk.ac.starlink.table.StarTable table, String expr, Class clazz)
          Checks that an expression is legal and returns a particular class.
static gnu.jel.CompiledExpression compile(gnu.jel.Library lib, uk.ac.starlink.table.StarTable table, String expr)
          Compiles an expression in the context of a given table.
static gnu.jel.CompiledExpression compile(gnu.jel.Library lib, uk.ac.starlink.table.StarTable table, String expr, Class clazz)
          Compiles an expression in the context of a given table with a required type for the result.
static Class getExpressionType(gnu.jel.Library lib, uk.ac.starlink.table.StarTable table, String expr)
          Gives the return type of an expression.
static gnu.jel.Library getLibrary(JELRowReader reader)
          Returns a JEL Library suitable for expression evaluation.
static List getStaticClasses()
          Returns the list of classes whose static methods will be mapped into the JEL evaluation namespace.
static Class getWrapperType(Class clazz)
          Returns a non-primitive version of a given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSES_PROPERTY

public static final String CLASSES_PROPERTY
System property name for adding colon-separated list of additional classnames containing static methods.

See Also:
Constant Field Values
Constructor Detail

JELUtils

public JELUtils()
Method Detail

getLibrary

public static gnu.jel.Library getLibrary(JELRowReader reader)
Returns a JEL Library suitable for expression evaluation.

Parameters:
reader - object which can read rows from the table to be used for expression evaluation
Returns:
a JEL library

getStaticClasses

public static List getStaticClasses()
Returns the list of classes whose static methods will be mapped into the JEL evaluation namespace. This may be modified.

Returns:
list of classes with static methods

getExpressionType

public static Class getExpressionType(gnu.jel.Library lib,
                                      uk.ac.starlink.table.StarTable table,
                                      String expr)
                               throws gnu.jel.CompilationException
Gives the return type of an expression. This also has the effect of testing that an expression is legal.

Parameters:
lib - JEL library
table - context table
expr - string representation of the expression
Returns:
class which evaluation of expr using lib will return
Throws:
CompilationExpression - if expr cannot be compiled
gnu.jel.CompilationException

checkExpressionType

public static void checkExpressionType(gnu.jel.Library lib,
                                       uk.ac.starlink.table.StarTable table,
                                       String expr,
                                       Class clazz)
                                throws gnu.jel.CompilationException
Checks that an expression is legal and returns a particular class.

Parameters:
lib - JEL library
table - context table
expr - string representation of the expression
clazz - return type required from expr
Throws:
gnu.jel.CompilationException - if expr cannot be compiled or will return a type other than clazz (or one of its subtypes)

compile

public static gnu.jel.CompiledExpression compile(gnu.jel.Library lib,
                                                 uk.ac.starlink.table.StarTable table,
                                                 String expr,
                                                 Class clazz)
                                          throws gnu.jel.CompilationException
Compiles an expression in the context of a given table with a required type for the result. Additional to the behaviour of Evaluator.compile this also checks for expressions which exactly match table column names, even if they are not syntactically legal identifiers.

Parameters:
lib - JEL library
table - context table
expr - expression string
clazz - required class of resulting expression
Returns:
compiled expression
Throws:
gnu.jel.CompilationException

compile

public static gnu.jel.CompiledExpression compile(gnu.jel.Library lib,
                                                 uk.ac.starlink.table.StarTable table,
                                                 String expr)
                                          throws gnu.jel.CompilationException
Compiles an expression in the context of a given table. Additional to the behaviour of Evaluator.compile this also checks for expressions which exactly match table column names, even if they are not syntactically legal identifiers.

Parameters:
lib - JEL library
table - context table
expr - expression string
Returns:
compiled expression
Throws:
gnu.jel.CompilationException

getWrapperType

public static Class getWrapperType(Class clazz)
Returns a non-primitive version of a given class. If clazz is a non-primitive type, it will be returned, otherwise the wrapper class corresponding to the primitive type of clazz will be returned (e.g. Integer for int).

Parameters:
clazz - input class
Returns:
non-primitive class matching clazz


Copyright © 2009 Central Laboratory of the Research Councils. All Rights Reserved.