Ejemplo n.º 1
0
  public void setViewParameters(
      ViewFactoryContext viewFactoryContext, List<ExprNode> expressionParameters)
      throws ViewParameterException {
    List<Object> viewParameters =
        ViewFactorySupport.validateAndEvaluate(
            "Time batch view", viewFactoryContext.getStatementContext(), expressionParameters);
    String errorMessage =
        "Time batch view requires a single numeric or time period parameter, and an optional long-typed reference point in msec, and an optional list of control keywords as a string parameter (please see the documentation)";
    if ((viewParameters.size() < 1) || (viewParameters.size() > 3)) {
      throw new ViewParameterException(errorMessage);
    }

    processExpiry(
        viewParameters.get(0), errorMessage, "Time batch view requires a size of at least 1 msec");

    if ((viewParameters.size() == 2) && (viewParameters.get(1) instanceof String)) {
      processKeywords(viewParameters.get(1), errorMessage);
    } else {
      if (viewParameters.size() >= 2) {
        Object paramRef = viewParameters.get(1);
        if ((!(paramRef instanceof Number))
            || (JavaClassHelper.isFloatingPointNumber((Number) paramRef))) {
          throw new ViewParameterException(
              "Time batch view requires a Long-typed reference point in msec as a second parameter");
        }
        optionalReferencePoint = ((Number) paramRef).longValue();
      }

      if (viewParameters.size() == 3) {
        processKeywords(viewParameters.get(2), errorMessage);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Process view expiry parameter
   *
   * @param parameter the parameter to parse
   * @param errorMessage error text
   * @param errorMessage2 error text
   * @throws ViewParameterException if validation failed
   */
  protected void processExpiry(Object parameter, String errorMessage, String errorMessage2)
      throws ViewParameterException {
    if (!(parameter instanceof Number)) {
      throw new ViewParameterException(errorMessage);
    } else {
      Number param = (Number) parameter;
      if (JavaClassHelper.isFloatingPointNumber(param)) {
        millisecondsBeforeExpiry = Math.round(1000d * param.doubleValue());
      } else {
        millisecondsBeforeExpiry = 1000 * param.longValue();
      }
    }

    if (millisecondsBeforeExpiry < 1) {
      throw new ViewParameterException(errorMessage2);
    }
  }