/** * Returns a parameter. * * @param value value * @param name name * @param declared variable declaration flags * @return parameter * @throws QueryException HTTP exception */ private RestXqParam param(final Value value, final QNm name, final boolean[] declared) throws QueryException { // [CG] RESTXQ: allow identical field names? final long vs = value.size(); if (vs < 2) error(ANN_PARAMS, "%", name.string(), 2); // name of parameter final String key = toString(value.itemAt(0), name); // variable template final QNm qnm = checkVariable(toString(value.itemAt(1), name), declared); // default value final ValueBuilder vb = new ValueBuilder(); for (int v = 2; v < vs; v++) vb.add(value.itemAt(v)); return new RestXqParam(qnm, key, vb.value()); }
@Override protected Expr opt(final CompileContext cc) throws QueryException { if (allAreValues() && exprs[0].size() < UNROLL_LIMIT) { // unroll the loop cc.info(QueryText.OPTUNROLL_X, this); final Value seq = (Value) exprs[0]; final int len = (int) seq.size(); // fn:for-each(...) final Expr[] results = new Expr[len]; for (int i = 0; i < len; i++) { results[i] = new DynFuncCall(info, sc, exprs[1], seq.itemAt(i)).optimize(cc); } return new List(info, results).optimize(cc); } return this; }
/** * Adds items to the specified list. * * @param value value * @param name name * @param list list to add values to * @throws QueryException HTTP exception */ private void strings(final Value value, final QNm name, final StringList list) throws QueryException { final long vs = value.size(); for (int v = 0; v < vs; v++) list.add(toString(value.itemAt(v), name)); }