Exemplo n.º 1
0
  /**
   * Adds a local function.
   *
   * @param fun function instance
   * @param ii input info
   * @return function id
   * @throws QueryException query exception
   */
  public int add(final UserFunc fun, final InputInfo ii) throws QueryException {
    final QNm name = fun.name;
    final byte[] uri = name.uri();
    if (uri.length == 0) FUNNONS.thrw(ii, name.string());

    if (NSGlobal.reserved(uri)) {
      if (fun.declared) NAMERES.thrw(ii, name.string());
      funError(name, ii);
    }

    final byte[] ln = name.local();
    for (int l = 0; l < funcs.length; ++l) {
      final QNm qn = funcs[l].name;
      final byte[] u = qn.uri();
      final byte[] nm = qn.local();

      if (eq(ln, nm) && eq(uri, u) && fun.args.length == funcs[l].args.length) {
        // declare function that has been called before
        if (!funcs[l].declared) {
          funcs[l] = fun;
          return l;
        }
        // duplicate declaration
        FUNCDEFINED.thrw(ii, fun.name.string());
      }
    }
    // add function skeleton
    funcs = Array.add(funcs, fun);
    calls = Array.add(calls, new UserFuncCall[0]);
    return funcs.length - 1;
  }
Exemplo n.º 2
0
 /**
  * Throws an error if one of the pre-defined functions is similar to the specified function name.
  *
  * @param name function name
  * @param ii input info
  * @throws QueryException query exception
  */
 public void error(final QNm name, final InputInfo ii) throws QueryException {
   // compare specified name with names of predefined functions
   final byte[] ln = name.local();
   final Levenshtein ls = new Levenshtein();
   for (int k = 1; k < size; ++k) {
     final int i = indexOf(keys[k], '}');
     final byte[] u = substring(keys[k], 2, i);
     final byte[] l = substring(keys[k], i + 1);
     if (eq(ln, l)) {
       final byte[] ur = name.uri();
       FUNSIMILAR.thrw(
           ii,
           new TokenBuilder(NSGlobal.prefix(ur)).add(':').add(l),
           new TokenBuilder(NSGlobal.prefix(u)).add(':').add(l));
     } else if (ls.similar(ln, l, 0)) {
       FUNSIMILAR.thrw(ii, name.string(), l);
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public final String toString() {
   final byte[] pre = NSGlobal.prefix(uri());
   return new TokenBuilder(pre).add(':').add(desc).toString();
 }