use of org.apache.commons.jxpath.ri.compiler.Expression in project collect by openforis.
the class ModelExtensionFunction method computeValue.
@Override
public Object computeValue(EvalContext context) {
Object[] parameters = null;
if (args != null) {
parameters = new Object[args.length];
for (int i = 0; i < args.length; i++) {
Expression expression = args[i];
Iterator<?> computedValues = expression.iterate(context);
parameters[i] = convert(computedValues);
}
}
Object result = invoke(context, parameters);
return result instanceof NodeSet ? new NodeSetContext(context, (NodeSet) result) : result;
}
use of org.apache.commons.jxpath.ri.compiler.Expression in project collect by openforis.
the class ModelJXPathCompiledExpression method getFunctionNames.
public Set<String> getFunctionNames() {
Set<String> names = new HashSet<String>();
Deque<Expression> stack = new LinkedList<Expression>();
stack.push(getExpression());
while (!stack.isEmpty()) {
Expression expression = stack.pop();
if (expression instanceof Operation) {
if (expression instanceof CoreFunction || expression instanceof ModelExtensionFunction) {
String name = expression.toString().replaceAll("\\(.*\\)", "");
names.add(name);
}
Expression[] arguments = ((Operation) expression).getArguments();
if (arguments != null && arguments.length > 0) {
for (Expression arg : arguments) {
stack.push(arg);
}
}
}
}
return names;
}
use of org.apache.commons.jxpath.ri.compiler.Expression in project collect by openforis.
the class ModelJXPathContext method compilePath.
private ModelJXPathCompiledExpression compilePath(String xpath, boolean normalizeNumbers) {
Expression expr = compileExpression(xpath, normalizeNumbers);
ModelJXPathCompiledExpression compiledExpression = new ModelJXPathCompiledExpression(expressionFactory, xpath, expr);
return compiledExpression;
}
use of org.apache.commons.jxpath.ri.compiler.Expression in project collect by openforis.
the class ModelJXPathContext method compileExpression.
@SuppressWarnings("unchecked")
private Expression compileExpression(String xpath, boolean normalizeNumbers) {
Expression expr;
synchronized (compiled) {
if (USE_SOFT_CACHE) {
expr = null;
SoftReference ref = (SoftReference) compiled.get(xpath);
if (ref != null) {
expr = (Expression) ref.get();
}
} else {
expr = (Expression) compiled.get(xpath);
}
}
if (expr != null) {
return expr;
}
expr = (Expression) Parser.parseExpression(xpath, getCompiler(normalizeNumbers));
synchronized (compiled) {
if (USE_SOFT_CACHE) {
if (cleanupCount++ >= CLEANUP_THRESHOLD) {
Iterator it = compiled.entrySet().iterator();
while (it.hasNext()) {
Entry me = (Entry) it.next();
if (((SoftReference) me.getValue()).get() == null) {
it.remove();
}
}
cleanupCount = 0;
}
compiled.put(xpath, new SoftReference(expr));
} else {
compiled.put(xpath, expr);
}
}
return expr;
}
use of org.apache.commons.jxpath.ri.compiler.Expression in project collect by openforis.
the class ReferencedPathEvaluator method determineReferencedPaths.
private Set<String> determineReferencedPaths(org.apache.commons.jxpath.ri.compiler.Path modelLocationPath) {
Set<String> paths = new HashSet<String>();
if (modelLocationPath.getSteps().length > 0) {
paths.add(Path.getAbsolutePath(modelLocationPath.toString()));
StringBuilder predicateBasePathSB = new StringBuilder();
for (Step step : modelLocationPath.getSteps()) {
String stepVal = step.toString();
predicateBasePathSB.append(Path.getAbsolutePath(stepVal)).append(Path.SEPARATOR);
for (Expression predicate : step.getPredicates()) {
Set<String> predicatePaths = determineReferencedPaths(predicate);
for (String predicateReferencePath : predicatePaths) {
if (predicateReferencePath.startsWith(Path.THIS_VARIABLE) || predicateReferencePath.startsWith(Path.CONTEXT_VARIABLE)) {
paths.add(predicateReferencePath);
} else {
paths.add(predicateBasePathSB.toString() + predicateReferencePath);
}
}
}
}
}
return paths;
}
Aggregations