public class FunctionLibrary
extends java.lang.Object
When created, a FunctionLibrary is empty. There are two ways to populate it, described below. Once the FunctionLibrary has been created and populated, it should be used to create a ClauseFactory, which can then be given to the CEEvaluator for use in parsing.
The most straightforward is to pass an instance of each ServerSideFunction class to the add() method. If you have a large number of ServerSideFunctions, or if you want to have choose class names for your functions independent of the actual function name, this is the approach to use.
A second, more complex method resolves server-side function names at runtime. The function library automatically looks for a class whose name matches the name requested (if a prefix is set, it will look for a class whose name is prefix + name requested). If such a class exists, and it implements the ServerSideFunction interface, a new instance of the class is created using the default constructor, added to the list of available functions, and returned to the caller.This is not quite as complicated as it sounds. For instance, say the FunctionLibrary's prefix is set to "opendap.servers.test.SSF". Then the first time the server gets a constraint expression containing the function "dummy()", the FunctionLibrary will automatically load the class "opendap.servers.test.SSFdummy", and return a new instance using the class's default constructor.
This avoids the need to hardcode a list of server-side functions, and allows you to create new functions at any time. For instance to create a function "newfn()" you can simply create the class "opendap.servers.test.SSFnewfn" and put it somewhere in the server's classpath . Then the first CE containing this function will cause that class to be automatically loaded, just the like the dummy() function was.
Modifier and Type | Field and Description |
---|---|
protected java.util.Map |
boolFunctions |
protected java.util.Map |
btFunctions |
protected java.lang.String |
prefix |
Constructor and Description |
---|
FunctionLibrary()
Creates a new FunctionLibrary with no prefix set.
|
FunctionLibrary(java.lang.String prefix)
Creates a new FunctionLibrary.
|
Modifier and Type | Method and Description |
---|---|
void |
add(ServerSideFunction function)
Adds a function to the library.
|
BoolFunction |
getBoolFunction(java.lang.String name)
Retrieves a boolean function from the library.
|
BTFunction |
getBTFunction(java.lang.String name)
Retrieves a BaseType function from the library.
|
java.lang.String |
getPrefix()
Returns the prefix being used for classname lookup.
|
protected void |
loadNewFunction(java.lang.String name)
Tries to load a function with the given name.
|
void |
setPrefix(java.lang.String prefix)
Sets the prefix to use for classname lookup.
|
protected java.util.Map boolFunctions
protected java.util.Map btFunctions
protected java.lang.String prefix
public FunctionLibrary()
public FunctionLibrary(java.lang.String prefix)
prefix
- A string that will be prepended to function names in order
to create a classname for that function. For example,public void setPrefix(java.lang.String prefix)
public java.lang.String getPrefix()
public void add(ServerSideFunction function)
public BoolFunction getBoolFunction(java.lang.String name) throws NoSuchFunctionException
name
- The name of the function being requested.NoSuchFunctionException
public BTFunction getBTFunction(java.lang.String name) throws NoSuchFunctionException
name
- The name of the function being requested.NoSuchFunctionException
protected void loadNewFunction(java.lang.String name)