Package org.openntf.formula

Examples of org.openntf.formula.ValueHolder


   * function.evaluate(ctx,params) may throw any runtime exception. Error-Valueholders are not passed to the function. Thats why we need
   * an AST-AtText
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder params[] = new ValueHolder[children == null ? 0 : children.length];
    for (int i = 0; i < params.length; i++) {
      params[i] = children[i].evaluate(ctx);
      if (params[i].dataType == DataType.ERROR)
        return params[i];
    }
View Full Code Here


   * @see org.openntf.formula.ast.Node#solve(org.openntf.formula.FormulaContext)
   */
  @Override
  public final List<Object> solve(final FormulaContext ctx) throws EvaluateException {
    try {
      ValueHolder vh;
      try {
        vh = evaluate(ctx);
      } catch (FormulaReturnException e) {
        vh = e.getValue();
      }
      if (vh.dataType == DataType.ERROR)
        throw vh.getError();
      return vh.toList();
    } catch (EvaluateException ev) {
      throw ev;
    }
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Override
  public ValueHolder evaluate(final FormulaContext ctx, final ValueHolder[] params) throws FormulaReturnException {
    ValueHolder ret = null;
    Object result = null;
    // Errors cannt be used in a simple function. You must implement them as generic functions
    if (params != null) {
      for (int i = 0; i < params.length; i++) {
        if (params[i].dataType == DataType.ERROR)
          return params[i];
      }
    }

    try {
      if (varArgClass != null) {

        Collection<Object[]> values = new ParameterCollectionObject<Object>(params, (Class<Object>) varArgClass, false);

        // Our last parameter is a "varArg" this means, the LAST parameter is an array[]
        Object[] tmpParams = new Object[paramCount];
        for (Object[] value : values) {
          int i = 0;
          if (useContext) {
            tmpParams[i++] = ctx;
          }
          if (i == paramCount) {
            // that's not possible when useContext is true unless you specify FormulaContext... ctx
          } else if (i == paramCount - 1) {
            // exactly one parameter left. this is our vararg
            tmpParams[i++] = value;
          }
          result = method.invoke(null, tmpParams);
          if (result != null) {
            if (ret == null) {
              ret = ValueHolder.createValueHolder(result.getClass(), values.size());
            }
            ret.add(result);
          }
        }
      } else {
        Collection<Object[]> values = new ParameterCollectionObject<Object>(params, Object.class, false);

        for (Object[] value : values) {

          if (useContext) {
            Object[] tmpParams;
            if (value == null) {
              tmpParams = new Object[1];
            } else {
              tmpParams = new Object[value.length + 1];
              System.arraycopy(value, 0, tmpParams, 1, value.length);
            }
            tmpParams[0] = ctx;
            result = method.invoke(null, tmpParams);
          } else {
            result = method.invoke(null, value);
          }
          if (result != null) {
            if (ret == null) {
              ret = ValueHolder.createValueHolder(result.getClass(), values.size());
            }
            ret.add(result);
          }
        }
      }

      return ret;
View Full Code Here

  @Override
  public ValueHolder evaluate(final FormulaContext ctx, final ValueHolder[] params) throws FormulaReturnException {
    if (function == null)
      throw new UnsupportedOperationException("'" + functionName + "' is not properly declared");

    ValueHolder paramVals[] = new ValueHolder[parameter.length];
    ValueHolder varVals[] = new ValueHolder[variable.length];

    for (int i = 0; i < parameter.length; i++) {
      if (params == null || i >= params.length) {
        paramVals[i] = parameter[i].evaluate(ctx); //Optional params
      } else {
View Full Code Here

TOP

Related Classes of org.openntf.formula.ValueHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.