Esempio n. 1
0
  public static Object call(PageContext pc, Object[] objArr) throws PageException {
    if (objArr.length < 3)
      throw new ExpressionException("invalid call of a CFML Based built in function");

    // translate arguments
    String filename = Caster.toString((((FunctionValue) objArr[0]).getValue()));
    Collection.Key name = KeyImpl.toKey((((FunctionValue) objArr[1]).getValue()));
    boolean isweb = Caster.toBooleanValue((((FunctionValue) objArr[2]).getValue()));

    UDF udf = loadUDF(pc, filename, name, isweb);
    Struct meta = udf.getMetaData(pc);
    boolean caller =
        meta == null ? false : Caster.toBooleanValue(meta.get(CALLER, Boolean.FALSE), false);

    Struct namedArguments = null;
    Object[] arguments = null;
    if (objArr.length <= 3) arguments = ArrayUtil.OBJECT_EMPTY;
    else if (objArr[3] instanceof FunctionValue) {
      FunctionValue fv;
      namedArguments = new StructImpl();
      if (caller) namedArguments.setEL(CALLER, pc.undefinedScope().duplicate(false));
      for (int i = 3; i < objArr.length; i++) {
        fv = toFunctionValue(name, objArr[i]);
        namedArguments.set(fv.getName(), fv.getValue());
      }
    } else {
      int offset = (caller ? 2 : 3);
      arguments = new Object[objArr.length - offset];
      if (caller) arguments[0] = pc.undefinedScope().duplicate(false);
      for (int i = 3; i < objArr.length; i++) {
        arguments[i - offset] = toObject(name, objArr[i]);
      }
    }

    // load UDF

    // execute UDF
    if (namedArguments == null) {
      return udf.call(pc, arguments, false);
    }

    return udf.callWithNamedValues(pc, namedArguments, false);
  }