예제 #1
0
  private EvaluationResult extractFromAny(AbstractTCLNode expr, Any any, String rootName)
      throws EvaluationException {
    if (logger_.isDebugEnabled()) {
      logger_.debug("extractFromAny" + "\trootname=" + rootName + "\tvalue=" + any);
    }

    EvaluationResult _result = null;
    Any _any = null;

    AbstractTCLNode _currentOperator = expr;
    Any _currentAny = any;

    StringBuffer _currentPath = new StringBuffer(rootName);

    while (_currentOperator != null) {
      _currentPath.append(_currentOperator.toString());

      if (logger_.isDebugEnabled()) {
        logger_.debug("current path=" + _currentPath.toString());
        logger_.debug("current operator=" + _currentOperator.toString());
        logger_.debug("current any=" + _currentAny);
      }

      // lookup result in cache
      _any = lookupAny(_currentPath.toString());

      if (_any == null) {
        // cache MISS
        switch (_currentOperator.getType()) {
          case TCLParserTokenTypes.DOT:
            // dots are skipped
            break;

          case TCLParserTokenTypes.UNION_POS:
            logger_.debug("evaluate union by position");
            UnionPositionOperator _upo = (UnionPositionOperator) _currentOperator;

            // default union
            if (_upo.isDefault()) {
              _any = getETCLEvaluator().evaluateUnion(_currentAny);
            } else {
              _any = getETCLEvaluator().evaluateUnion(_currentAny, _upo.getPosition());
            }

            break;

          case TCLParserTokenTypes.IDENTIFIER:
            String _identifer = ((IdentValue) _currentOperator).getIdentifier();

            _any = getETCLEvaluator().evaluateIdentifier(_currentAny, _identifer);

            break;

          case TCLParserTokenTypes.NUMBER:
            int _pos = ((NumberValue) _currentOperator).getNumber().intValue();

            _any = getETCLEvaluator().evaluateIdentifier(_currentAny, _pos);

            break;

          case TCLParserTokenTypes.IMPLICIT:
            ImplicitOperator _op = ((ImplicitOperatorNode) _currentOperator).getOperator();

            _any = _op.evaluateImplicit(getETCLEvaluator(), _currentAny);

            _result = EvaluationResult.fromAny(_any);

            _result.addAny(_currentAny);

            return _result;

          case TCLParserTokenTypes.ARRAY:
            int _arrayIndex = ((ArrayOperator) _currentOperator).getArrayIndex();

            _any = getETCLEvaluator().evaluateArrayIndex(_currentAny, _arrayIndex);

            break;

          case TCLParserTokenTypes.ASSOC:
            String _assocName = ((AssocOperator) _currentOperator).getAssocName();

            _any = getETCLEvaluator().evaluateNamedValueList(_currentAny, _assocName);

            break;

          default:
            throw new RuntimeException(
                "unexpected operator: "
                    + AbstractTCLNode.getNameForType(_currentOperator.getType()));
        }
      }

      if (_any != null) {
        storeAny(_currentPath.toString(), _any);
        _currentAny = _any;
      }

      _currentOperator = (AbstractTCLNode) _currentOperator.getNextSibling();
    }

    // Create the EvaluationResult
    _result = EvaluationResult.fromAny(_any);

    return _result;
  }