Search in sources :

Example 1 with CustomFunctions

use of org.openforis.idm.model.expression.internal.CustomFunctions in project collect by openforis.

the class ExpressionFactory method registerFunctions.

private void registerFunctions(CustomFunctions... functionsLibrary) {
    jxPathContext = (ModelJXPathContext) JXPathContext.newContext(null);
    FunctionLibrary library = new FunctionLibrary();
    for (CustomFunctions functions : functionsLibrary) {
        library.addFunctions(functions);
        String namespace = functions.getNamespace();
        if (customFunctionsByNamespace.containsKey(namespace)) {
            throw new IllegalStateException(String.format("Functions for namespace %s already registered", namespace));
        }
        customFunctionsByNamespace.put(namespace, functions);
    }
    jxPathContext.setFunctions(library);
}
Also used : FunctionLibrary(org.apache.commons.jxpath.FunctionLibrary) CustomFunctions(org.openforis.idm.model.expression.internal.CustomFunctions)

Example 2 with CustomFunctions

use of org.openforis.idm.model.expression.internal.CustomFunctions in project collect by openforis.

the class ExpressionFactory method isValidFunction.

public boolean isValidFunction(String namespace, String functionName) {
    boolean inDefaultNamespace = StringUtils.isBlank(namespace);
    if (inDefaultNamespace) {
        return CORE_FUNCTION_NAMES.contains(functionName);
    }
    CustomFunctions functions = customFunctionsByNamespace.get(namespace);
    return functions != null && functions.containsFunction(functionName);
}
Also used : CustomFunctions(org.openforis.idm.model.expression.internal.CustomFunctions)

Example 3 with CustomFunctions

use of org.openforis.idm.model.expression.internal.CustomFunctions in project collect by openforis.

the class ExpressionFactory method lookupFunction.

public CustomFunction lookupFunction(ModelExtensionFunction modelExtensionFunction) {
    String namespace = modelExtensionFunction.getPrefix();
    CustomFunctions customFunctions = customFunctionsByNamespace.get(namespace);
    return (CustomFunction) customFunctions.getFunction(namespace, modelExtensionFunction.getName(), modelExtensionFunction.getArguments());
}
Also used : CustomFunction(org.openforis.idm.model.expression.internal.CustomFunction) CustomFunctions(org.openforis.idm.model.expression.internal.CustomFunctions)

Aggregations

CustomFunctions (org.openforis.idm.model.expression.internal.CustomFunctions)3 FunctionLibrary (org.apache.commons.jxpath.FunctionLibrary)1 CustomFunction (org.openforis.idm.model.expression.internal.CustomFunction)1