public class XPathFuncExpr extends XPathExpression
Modifier and Type | Field and Description |
---|---|
XPathExpression[] |
args |
XPathQName |
id |
indent
Constructor and Description |
---|
XPathFuncExpr() |
XPathFuncExpr(XPathQName id,
XPathExpression[] args) |
Modifier and Type | Method and Description |
---|---|
private static void |
assertArgsCount(java.lang.String name,
java.lang.Object[] args,
int count) |
static java.lang.Boolean |
boolNot(java.lang.Object o) |
static java.lang.Boolean |
boolStr(java.lang.Object o) |
static java.lang.Boolean |
checklist(java.lang.Object oMin,
java.lang.Object oMax,
java.lang.Object[] factors)
perform a 'checklist' computation, enabling expressions like 'if there are at least 3 risk
factors active'
|
static java.lang.Boolean |
checklistWeighted(java.lang.Object oMin,
java.lang.Object oMax,
java.lang.Object[] flags,
java.lang.Object[] weights)
very similar to checklist, only each factor is assigned a real-number 'weight'.
|
static java.lang.Double |
count(java.lang.Object o)
count the number of nodes in a nodeset
|
static java.lang.Double |
countSelected(java.lang.Object o)
return the number of choices in a multi-select answer
|
static java.lang.String |
dateStr(java.lang.Object od,
java.lang.Object of,
boolean preserveTime) |
boolean |
equals(java.lang.Object o) |
java.lang.Object |
eval(FormInstance model,
EvaluationContext evalContext)
Evaluate the function call.
|
private static java.lang.Object |
evalCustomFunction(IFunctionHandler handler,
java.lang.Object[] args,
EvaluationContext ec)
Given a handler registered to handle the function, try to coerce the function arguments into
one of the prototypes defined by the handler.
|
static java.lang.Object |
ifThenElse(FormInstance model,
EvaluationContext ec,
XPathExpression[] args,
java.lang.Object[] argVals) |
static java.lang.Object |
indexedRepeat(FormInstance model,
EvaluationContext ec,
XPathExpression[] args,
java.lang.Object[] argVals)
This provides a method of indexing fields stored in prior repeat groups.
|
static boolean |
isNull(java.lang.Object o)
HANDLERS FOR BUILT-IN FUNCTIONS ********
the functions below are the handlers for the built-in xpath function suite
if you add a function to the suite, it should adhere to the following pattern:
* the function takes in its arguments as objects (DO NOT cast the arguments when calling
the handler up in eval() (i.e., return stringLength((String)argVals[0]) <--- NO!)
* the function converts the generic argument(s) to the desired type using the built-in
xpath type conversion functions (toBoolean(), toNumeric(), toString(), toDate())
* the function MUST return an object of type Boolean, Double, String, or Date; it may
never return null (instead return the empty string or NaN)
* the function may throw exceptions, but should try as hard as possible not to, and if
it must, strive to make it an XPathException
|
static java.lang.String |
join(java.lang.Object oSep,
java.lang.Object[] argVals)
concatenate an abritrary-length argument list of string values together
|
private static java.lang.Object[] |
matchPrototype(java.lang.Object[] args,
java.lang.Class[] prototype)
Given a prototype defined by the function handler, attempt to coerce the function arguments
to match that prototype (checking # args, type conversion, etc.).
|
private static java.lang.Object |
max(java.lang.Object[] argVals)
Identify the largest value from the list of provided values.
|
private static java.lang.Object |
min(java.lang.Object[] argVals) |
static java.lang.Boolean |
multiSelected(java.lang.Object o1,
java.lang.Object o2,
java.lang.String functionName)
return whether a particular choice of a multi-select is selected
|
java.lang.Object |
pivot(FormInstance model,
EvaluationContext evalContext,
java.util.List<java.lang.Object> pivots,
java.lang.Object sentinal)
Pivot this expression, returning values if appropriate, and adding any pivots to the list.
|
private java.lang.Double |
position(TreeReference refAt) |
void |
readExternal(java.io.DataInputStream in,
PrototypeFactory pf) |
static java.lang.Boolean |
regex(java.lang.Object o1,
java.lang.Object o2)
determine if a string matches a regular expression.
|
private static java.lang.Double |
round(double num,
double numDecim)
round function like in Excel.
|
static java.lang.String |
selectedAt(java.lang.Object o1,
java.lang.Object o2)
Get the Nth item in a selected list
|
static java.lang.Double |
stringLength(java.lang.Object o) |
private static java.lang.Object[] |
subsetArgList(java.lang.Object[] args,
int start) |
private static java.lang.Object[] |
subsetArgList(java.lang.Object[] args,
int start,
int skip)
return a subset of an argument list as a new arguments list
|
static java.lang.String |
substring(java.lang.Object o1,
java.lang.Object o2,
java.lang.Object o3) |
static java.lang.Double |
sum(java.lang.Object[] argVals)
sum the values in a nodeset; each element is coerced to a numeric value
|
static java.lang.Boolean |
toBoolean(java.lang.Object o)
convert a value to a boolean using xpath's type conversion rules
|
static java.lang.Object |
toDate(java.lang.Object o,
boolean preserveTime)
convert a value to a date.
|
static java.lang.Object |
toDecimalDateTime(java.lang.Object o,
boolean keepDate) |
static java.lang.Double |
toDouble(java.lang.Object o) |
static java.lang.Double |
toInt(java.lang.Object o)
convert a number to an integer by truncating the fractional part.
|
static java.lang.Double |
toNumeric(java.lang.Object o)
convert a value to a number using xpath's type conversion rules (note that xpath itself makes
no distinction between integer and floating point numbers)
|
java.lang.String |
toString() |
static java.lang.String |
toString(java.lang.Object o)
convert a value to a string using xpath's type conversion rules
|
static java.lang.Object |
unpack(java.lang.Object o) |
void |
writeExternal(java.io.DataOutputStream out) |
eval, hashCode, pivot, print, printParseTree
public XPathQName id
public XPathExpression[] args
public XPathFuncExpr()
public XPathFuncExpr(XPathQName id, XPathExpression[] args)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public void readExternal(java.io.DataInputStream in, PrototypeFactory pf) throws java.io.IOException, DeserializationException
java.io.IOException
DeserializationException
public void writeExternal(java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public java.lang.Object eval(FormInstance model, EvaluationContext evalContext)
eval
in class XPathExpression
private static void assertArgsCount(java.lang.String name, java.lang.Object[] args, int count)
private static java.lang.Object evalCustomFunction(IFunctionHandler handler, java.lang.Object[] args, EvaluationContext ec)
handler
- args
- private static java.lang.Object[] matchPrototype(java.lang.Object[] args, java.lang.Class[] prototype)
args
- prototype
- public static boolean isNull(java.lang.Object o)
public static java.lang.Double stringLength(java.lang.Object o)
public static java.lang.Boolean toBoolean(java.lang.Object o)
o
- public static java.lang.Double toDouble(java.lang.Object o)
public static java.lang.Double toNumeric(java.lang.Object o)
o
- public static java.lang.Double toInt(java.lang.Object o)
o
- public static java.lang.String toString(java.lang.Object o)
o
- public static java.lang.Object toDate(java.lang.Object o, boolean preserveTime)
o
- public static java.lang.Object toDecimalDateTime(java.lang.Object o, boolean keepDate)
public static java.lang.Boolean boolNot(java.lang.Object o)
public static java.lang.Boolean boolStr(java.lang.Object o)
public static java.lang.String dateStr(java.lang.Object od, java.lang.Object of, boolean preserveTime)
private java.lang.Double position(TreeReference refAt)
public static java.lang.Object ifThenElse(FormInstance model, EvaluationContext ec, XPathExpression[] args, java.lang.Object[] argVals)
public static java.lang.Object indexedRepeat(FormInstance model, EvaluationContext ec, XPathExpression[] args, java.lang.Object[] argVals) throws XPathTypeMismatchException
model
- ec
- args
- argVals
- XPathTypeMismatchException
public static java.lang.Boolean multiSelected(java.lang.Object o1, java.lang.Object o2, java.lang.String functionName)
o1
- XML-serialized answer to multi-select question (i.e, space-delimited choice values)o2
- choice to look forpublic static java.lang.Double countSelected(java.lang.Object o)
o
- XML-serialized answer to multi-select question (i.e, space-delimited choice values)public static java.lang.String selectedAt(java.lang.Object o1, java.lang.Object o2)
o1
- XML-serialized answer to multi-select question (i.e, space-delimited choice values)o2
- the integer index into the list to returnpublic static java.lang.Double count(java.lang.Object o)
o
- public static java.lang.Double sum(java.lang.Object[] argVals)
model
- o
- private static java.lang.Double round(double num, double numDecim)
num
- dblDecim
- private static java.lang.Object max(java.lang.Object[] argVals)
argVals
- private static java.lang.Object min(java.lang.Object[] argVals)
public static java.lang.String join(java.lang.Object oSep, java.lang.Object[] argVals)
argVals
- public static java.lang.String substring(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
public static java.lang.Boolean checklist(java.lang.Object oMin, java.lang.Object oMax, java.lang.Object[] factors)
argVals
- the first argument is a numeric value expressing the minimum number of factors required.
if -1, no minimum is applicable
the second argument is a numeric value expressing the maximum number of allowed factors.
if -1, no maximum is applicalbe
arguments 3 through the end are the individual factors, each coerced to a boolean valuepublic static java.lang.Boolean checklistWeighted(java.lang.Object oMin, java.lang.Object oMax, java.lang.Object[] flags, java.lang.Object[] weights)
argVals
- public static java.lang.Boolean regex(java.lang.Object o1, java.lang.Object o2)
o1
- string being matchedo2
- regular expressionprivate static java.lang.Object[] subsetArgList(java.lang.Object[] args, int start)
private static java.lang.Object[] subsetArgList(java.lang.Object[] args, int start, int skip)
args
- start
- index to start atskip
- sub-list will contain every nth argument, where n == skip (default: 1)public static java.lang.Object unpack(java.lang.Object o)
public java.lang.Object pivot(FormInstance model, EvaluationContext evalContext, java.util.List<java.lang.Object> pivots, java.lang.Object sentinal) throws UnpivotableExpressionException
XPathExpression
pivot
in class XPathExpression
model
- The model to evaluate the current expression againstevalContext
- The evaluation context to evaluate againstpivots
- The list of pivot points in the xpath being evaluated. Pivots should be added to this list.sentinal
- The value which is being pivoted around.UnpivotableExpressionException
- If the expression is too complex to pivot