Пример #1
0
  private void initSumcElObjects() {
    String[] subExps = this.parseELExpression();

    // 寻找sumcEls的个数索引
    int index = 1;
    for (; index < subExps.length; index++) {
      if (SumcElObject.isSumcAggregateExpression(subExps[index]) == true) break;
      if (this.isHaveSumcElExpression(subExps, index) == true) break;
    }

    sumcEls = new Object[index < subExps.length ? index + 1 : index];

    for (int i = 0; i < index; i++) {
      sumcEls[i] = subExps[i];
    }

    if (index < subExps.length) {
      String tt = "";
      for (int i = index; i < subExps.length; i++)
        tt = tt.equals("") ? subExps[i] : tt + "." + subExps[i];
      SumcElObject subcEl = new SumcElObject("#{" + tt + "}", entityObject, request);
      sumcEls[index] = subcEl;
    }
    logger.debug(sumcEls);
  }
Пример #2
0
  public Object calculate() {

    Object tempObject = this.entityObject;
    boolean isAggregate = false;
    String sumcSplitStr = "";
    for (int i = 0; i < sumcEls.length; i++) {
      if (sumcEls[i] instanceof SumcElObject) { // 如果当前是一个SumcElObject,则上一个取得的对象肯定是一个集合对象,
        if (tempObject instanceof java.util.Collection) {
          Object[] objs = ((java.util.Collection) tempObject).toArray();
          StringBuffer buf = new StringBuffer();
          for (int j = 0; j < objs.length; j++) {
            SumcElObject tempSumcElObject = ((SumcElObject) sumcEls[i]);
            tempSumcElObject.setEntityObject(
                objs[j]); // 将当前集合取得的每个对象做为递归的SumcElObject的enitityObject以备计算之用
            buf.append(tempSumcElObject.calculate());
            if (j < objs.length - 1) buf.append(sumcSplitStr);
          }
          tempObject = buf.toString();
        } else {
          SumcElObject tempSumcElObject = ((SumcElObject) sumcEls[i]);
          tempSumcElObject.setEntityObject(
              tempObject); // 将当前集合取得的每个对象做为递归的SumcElObject的enitityObject以备计算之用
          tempObject = tempSumcElObject.calculate();
        }

      } else if (SumcElObject.isSumcAggregateExpression((String) sumcEls[i]) == true) {
        sumcSplitStr = getSumcSplitStr((String) sumcEls[i]);
        tempObject =
            ReflectHelper.invoke(
                tempObject,
                "get"
                    + StringHelper.converseFirstCharToUpper(
                        getAggregateMethod((String) sumcEls[i])));
        isAggregate = true;
      } else { // 普通的简单elobject对象调用
        if (isAggregate == true) {
          tempObject =
              sumcInvoke(
                  tempObject,
                  "get" + StringHelper.converseFirstCharToUpper((String) sumcEls[i]),
                  sumcSplitStr);
          break;
        } else {
          tempObject =
              ReflectHelper.invoke(
                  tempObject, "get" + StringHelper.converseFirstCharToUpper((String) sumcEls[i]));
          if (tempObject == null) {
            tempObject = "";
            break;
          }
        }
      }
    }

    return tempObject;
  }
Пример #3
0
 private boolean isHaveSumcElExpression(String[] subExps, int beginIndex) {
   for (int i = beginIndex; i < subExps.length; i++) {
     if (SumcElObject.isSumcAggregateExpression(subExps[i]) == true) return true;
   }
   return false;
 }