/**
  * set parameter choice value. The string value is in English locale, and needs to be parsed back
  * into object value based on the data type.
  *
  * @param value the string value for the object
  * @param type the parameter data type
  */
 public void setValue(String value, int type) {
   try {
     switch (type) {
       case IScalarParameterDefn.TYPE_BOOLEAN:
         this.value = DataTypeUtil.toBoolean(value);
         break;
       case IScalarParameterDefn.TYPE_DATE_TIME:
         this.value = DataTypeUtil.toDate(value);
         break;
       case IScalarParameterDefn.TYPE_DECIMAL:
         this.value = DataTypeUtil.toBigDecimal(value);
         break;
       case IScalarParameterDefn.TYPE_FLOAT:
         this.value = DataTypeUtil.toDouble(value);
         break;
       case IScalarParameterDefn.TYPE_INTEGER:
         this.value = DataTypeUtil.toInteger(value);
         break;
       case IScalarParameterDefn.TYPE_DATE:
         this.value = DataTypeUtil.toSqlDate(value);
         break;
       case IScalarParameterDefn.TYPE_TIME:
         this.value = DataTypeUtil.toSqlTime(value);
         break;
       case IScalarParameterDefn.TYPE_STRING:
       default:
         this.value = DataTypeUtil.toString(value);
         break;
     }
   } catch (BirtException e) {
     log.log(Level.SEVERE, e.getLocalizedMessage(), e);
     this.value = null;
   }
 }
Ejemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.birt.data.engine.api.aggregation.ICalculator#getTypedObject(java.lang.Object)
  */
 public Object getTypedObject(Object obj) throws DataException {
   try {
     return DataTypeUtil.toDouble(obj);
   } catch (BirtException e) {
     throw DataException.wrap(e);
   }
 }
Ejemplo n.º 3
0
  /**
   * Evaluate the given value
   *
   * @param value
   * @param n
   * @return
   * @throws DataException
   */
  public boolean evaluate(ScriptContext cx, Scriptable scope, DataSetRuntime dataSet)
      throws DataException {
    if (filterPassController.getForceReset()) {
      doReset();
      filterPassController.setForceReset(false);
    }

    if (N == -1) {
      // Create a new evaluator
      // Evaluate N (which is operand1) at this time
      Object n_object = null;
      try {
        n_object = ExprEvaluateUtil.evaluateRawExpression2(n_expr, scope, cx, dataSet);
      } catch (BirtException e1) {
        throw DataException.wrap(e1);
      }

      double n_value = -1;
      try {
        n_value = DataTypeUtil.toDouble(n_object).doubleValue();
      } catch (BirtException e) {
        // conversion error
        throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_ARGUMENT, e);
      }

      // First time; calculate N based on updated row count
      if (n_percent) {
        if (n_value < 0 || n_value > 100)
          throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_PERCENT_ARGUMENT);
        N = (int) Math.round(n_value / 100 * filterPassController.getRowCount());
      } else {
        if (n_value < 0) throw new DataException(ResourceConstants.INVALID_TOP_BOTTOM_N_ARGUMENT);
        N = (int) n_value;
      }
    }

    // Evaluate operand expression
    Object value =
        ScriptEvalUtil.evalExpr(op_expr, cx.newContext(scope), ScriptExpression.defaultID, 0);

    if (filterPassController.getPassLevel() == FilterPassController.FIRST_PASS) {
      return doFirstPass(value);
    } else if (filterPassController.getPassLevel() == FilterPassController.SECOND_PASS) {
      return doSecondPass();
    }
    return false;
  }
Ejemplo n.º 4
0
 /*
  * @see org.eclipse.birt.data.engine.api.IResultIterator#getDouble(java.lang.String)
  */
 public Double getDouble(String name) throws BirtException {
   return DataTypeUtil.toDouble(getValue(name));
 }