Interface ILcdEvaluatorFunction
- All Known Subinterfaces:
ILcdSpatialEvaluatorFunction
This interface represents the logic to evaluate an extension of the standard filtering functionality.
The OGC Filter specification defines an extension mechanism that allows the servers to declare their own specific functions. It is this interface that is responsible for evaluating such a specific function. Instances of this interface must be registered to an evaluator, which will delegate the evaluation of the custom function to this interface.
Adding global support for a custom function
When support for the custom function is needed throughout the whole JVM (for example in a WFS server),
custom functions can be registered by using the static TLcdOGCFilterEvaluator.registerDefaultFunction(TLcdXMLName, ILcdEvaluatorFunction)
method.
//At the start of the application
TLcdXMLName customFunctionName = ...;
ILcdEvaluatorFunction customFunction = ...;
TLcdOGCFilterEvaluator.registerDefaultFunction(customFunctionName, customFunction);
//...
//Later on in the application
ILcdOGCCondition condition = ...;
TLcdOGCFilter ogcFilter = new TLcdOGCFilter(condition);
//This evaluator will support the custom function registered at the start of the application
TLcdOGCFilterEvaluator evaluator = new TLcdOGCFilterEvaluator();
ILcdFilter filter = evaluator.buildFilter(ogcFilter, new TLcdOGCFilterContext());
Object toEvaluate = ...;
boolean accepted = filter.accept(toEvaluate);
Adding support for a custom function to a specific evaluator
When a custom function should only be supported by a specific TLcdOGCFilterEvaluator
,
the function needs to be registered on that instance.
This is achieved with the TLcdOGCFilterEvaluator.registerFunction(TLcdXMLName, ILcdEvaluatorFunction)
method.
ILcdOGCCondition condition = ...;
TLcdOGCFilter ogcFilter = new TLcdOGCFilter(condition);
TLcdOGCFilterEvaluator evaluator = new TLcdOGCFilterEvaluator();
//register the custom function on the evaluator
TLcdXMLName customFunctionName = ...;
ILcdEvaluatorFunction customFunction = ...;
evaluator.registerFunction(customFunctionName, customFunction);
//The evaluation of the filter is identical as without custom functions
ILcdFilter filter = evaluator.buildFilter(ogcFilter, new TLcdOGCFilterContext());
Object toEvaluate = ...;
boolean accepted = filter.accept(toEvaluate);
Example of a custom function
The following example represents a custom function which can convert a string to upper case.
ILcdEvaluatorFunction toUpperCaseFunction = new ILcdEvaluatorFunction() {
@Override
public Object apply(Object[] aArguments, Object aCurrentObject, TLcdOGCFilterContext aOGCFilterContext) {
return aArguments.length == 1 && aArguments[0] != null ?
aArguments[0].toString().toUpperCase() : null;
}
@Override
public int getArgumentCount() {
return 1;
}
};
-
Method Summary
Modifier and TypeMethodDescriptionapply
(Object[] aArguments, Object aCurrentObject, TLcdOGCFilterContext aOGCFilterContext) This method will be called each time the function is invoked in a filter.int
The number of arguments that the function will accept.
-
Method Details
-
apply
This method will be called each time the function is invoked in a filter. This method must support concurrent calls.
For example, when implementing a custom function which converts a single argument to upper-case (the example from the class javadoc), the XML version of the filter could look like this:
<ogc:Filter> <ogc:PropertyIsEqualTo> <ogc:Function name="UPPER"> <ogc:PropertyName>CONTINENT</ogc:PropertyName> </ogc:Function> <ogc:Literal>EUROPE</ogc:Literal> </ogc:PropertyIsEqualTo> </ogc:Filter>
In this case, the
apply
method of the "UPPER" function would be called with:aArguments
: a one-element array containing the value of the "CONTINENT" property of the domain object which is being evaluated. This means theapply
method does not receive theTLcdOGCPropertyName
instance, but the evaluated version of the property name.aCurrentObject
: the domain object which is being evaluated.
- Parameters:
aArguments
- the evaluated version of the arguments passed to the function.aCurrentObject
- the object that was passed to the top level filter to be evaluated.aOGCFilterContext
- the context in which this function is evaluated.- Returns:
- the result of the function invocation.
-
getArgumentCount
int getArgumentCount()The number of arguments that the function will accept. This information is used in the filter capabilities.- Returns:
- the number of arguments.
-