use of org.apache.commons.jxpath.ri.model.VariablePointer in project collect by openforis.
the class AbstractExpression method findNode.
protected Node<?> findNode(Node<?> contextNode, Node<?> thisNode, Predicate<Node<?>> predicate) throws InvalidExpressionException {
try {
JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
Iterator<?> pointers = compiledExpression.iteratePointers(jxPathContext);
while (pointers.hasNext()) {
Object item = pointers.next();
if (item instanceof ModelNodePointer) {
ModelNodePointer modelNodePointer = (ModelNodePointer) item;
Object ptrNode = modelNodePointer.getNode();
if (ptrNode != null && ptrNode instanceof Node) {
Node<?> node = (Node<?>) ptrNode;
if (predicate.evaluate(node)) {
return node;
}
}
} else if (item instanceof VariablePointer && ((VariablePointer) item).getName().equals(THIS)) {
if (predicate.evaluate(thisNode)) {
return thisNode;
}
}
// ignore node pointer if it's a NullPointer
}
return null;
} catch (IllegalArgumentException e) {
throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
} catch (JXPathInvalidSyntaxException e) {
throw new InvalidExpressionException(e.getMessage());
}
}
use of org.apache.commons.jxpath.ri.model.VariablePointer in project collect by openforis.
the class AbstractExpression method iterateMultiple.
protected void iterateMultiple(Node<?> contextNode, Node<?> thisNode, NodeVisitor visitor) throws InvalidExpressionException {
try {
JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
Iterator<?> pointers = compiledExpression.iteratePointers(jxPathContext);
while (pointers.hasNext()) {
Object item = pointers.next();
if (item instanceof ModelNodePointer) {
ModelNodePointer modelNodePointer = (ModelNodePointer) item;
Object ptrNode = modelNodePointer.getNode();
if (ptrNode != null && ptrNode instanceof Node) {
Node<?> node = (Node<?>) ptrNode;
visitor.visit(node, node.getIndex());
}
} else if (item instanceof VariablePointer && ((VariablePointer) item).getName().equals(THIS)) {
visitor.visit(thisNode, thisNode.getIndex());
}
// ignore node pointer if it's a NullPointer
}
} catch (IllegalArgumentException e) {
throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
} catch (JXPathInvalidSyntaxException e) {
throw new InvalidExpressionException(e.getMessage());
}
}
use of org.apache.commons.jxpath.ri.model.VariablePointer in project collect by openforis.
the class ModelRelationalExpression method getValue.
private Object getValue(Object object) {
if (object instanceof Number || object instanceof NumericRange || object instanceof String) {
return object;
}
if (object instanceof Boolean) {
return ((Boolean) object).booleanValue() ? 0.0 : 1.0;
} else if (object instanceof Value) {
return AttributeValueUtils.extractMainFieldValue((Value) object, normalizeNumbers);
}
if (object instanceof NodePointer) {
if (object instanceof VariablePointer && normalizeNumbers) {
ModelNodePointer valuePointer = (ModelNodePointer) ((NodePointer) object).getValuePointer();
valuePointer.setNormalizeNumbers(true);
}
return getValue(((NodePointer) object).getValue());
}
if (object instanceof EvalContext) {
EvalContext ctx = (EvalContext) object;
Pointer ptr = ctx.getSingleNodePointer();
return ptr == null ? Double.NaN : getValue(ptr);
}
return null;
}
Aggregations