use of org.javarosa.core.model.condition.pivot.UnpivotableExpressionException in project javarosa by opendatakit.
the class XPathExpression method pivot.
public final List<Object> pivot(DataInstance model, EvaluationContext evalContext) throws UnpivotableExpressionException {
try {
List<Object> pivots = new ArrayList<Object>();
this.pivot(model, evalContext, pivots, evalContext.getContextRef());
return pivots;
} catch (UnpivotableExpressionException uee) {
// Rethrow unpivotable (expected)
throw uee;
} catch (Exception e) {
// Pivots aren't critical, if there was a problem getting one, log the exception
// so we can fix it, and then just report that.
Logger.exception(e);
throw new UnpivotableExpressionException(e.getMessage());
}
}
use of org.javarosa.core.model.condition.pivot.UnpivotableExpressionException in project javarosa by opendatakit.
the class XPathFuncExpr method pivot.
@Override
public Object pivot(DataInstance model, EvaluationContext evalContext, List<Object> pivots, Object sentinal) throws UnpivotableExpressionException {
String name = id.toString();
// for now we'll assume that all that functions do is return the composition of their components
Object[] argVals = new Object[args.length];
// Identify whether this function is an identity: IE: can reflect back the pivot sentinal with no modification
String[] identities = new String[] { "string-length" };
boolean id = false;
for (String identity : identities) {
if (identity.equals(name)) {
id = true;
}
}
// get each argument's pivot
for (int i = 0; i < args.length; i++) {
argVals[i] = args[i].pivot(model, evalContext, pivots, sentinal);
}
boolean pivoted = false;
// evaluate the pivots
for (Object argVal : argVals) {
if (argVal == null) {
// one of our arguments contained pivots,
pivoted = true;
} else if (sentinal.equals(argVal)) {
// one of our arguments is the sentinal, return the sentinal if possible
if (id) {
return sentinal;
} else {
// the pivot.
throw new UnpivotableExpressionException();
}
}
}
if (pivoted) {
if (id) {
return null;
} else {
// the pivot.
throw new UnpivotableExpressionException();
}
}
// TODO: Inner eval here with eval'd args to improve speed
return eval(model, evalContext);
}
Aggregations