Пример #1
0
  /** Test Delegate Method Call */
  public void testCase1() throws Exception {
    ContextA contextA = new ContextA();
    ContextB contextB = new ContextB();

    OOEEContext context = OOEEContextFactory.createOOEEContext();

    context.setParsingContextObject("$", contextA);
    context.setEvaluationContextObject("$", contextA);

    context.setParsingContextObject("#", contextB);
    context.setEvaluationContextObject("#", contextB);

    String expressionStr = "$setValue(\"a\")";
    Expression expression = ExpressionParser.parse(expressionStr, context);
    ExpressionEvaluator.evaluate(expression, context);

    expressionStr = "#setValue(\"b\")";
    expression = ExpressionParser.parse(expressionStr, context);
    ExpressionEvaluator.evaluate(expression, context);

    expressionStr = "$var";
    expression = ExpressionParser.parse(expressionStr, context);
    Object value = ExpressionEvaluator.evaluate(expression, context);
    assertEquals("a", value);

    expressionStr = "#var";
    expression = ExpressionParser.parse(expressionStr, context);
    value = ExpressionEvaluator.evaluate(expression, context);
    assertEquals("b", value);

    SerializeUtil.serializeData(expression);
    SerializeUtil.serializeData(context);
  }
Пример #2
0
  /**
   * add @CurrentUser, external parsingContext should be MultiParsingCongtext
   *
   * @param variables the variables of the LogicNode, or the Output Data of DisplayNode. request
   *     context
   * @param globalVariables the Global variables of the WebChunk. session context
   * @return
   */
  public static OpExecuteContext getOpParsingContext(
      List<ParamType> variables, List<ParamType> globalVariables) {
    OpExecuteContext op = new OpExecuteContext();
    OOEEContext external = OOEEContextFactory.createOOEEContext();
    DefaultParsingContext global = getHttpSessionParsingContext(globalVariables);
    // set CurrentUser in session parsing context
    DefaultParsingContext local = getHttpRequestParsingContext(variables);
    if (logger.isDebugEnabled()) logger.debug("local: {}", local);

    external.setParsingContextObject(WebflowConstants.REQUEST_PARSING_CONTEXT_PREFIX, local);
    external.setParsingContextObject(WebflowConstants.SESSION_PARSING_CONTEXT_PREFIX, global);

    op.setExternalParseContext(external);
    op.setParsingContextObject(WebflowConstants.REQUEST_PARSING_CONTEXT_PREFIX, local);
    op.setParsingContextObject(WebflowConstants.SESSION_PARSING_CONTEXT_PREFIX, global);

    return op;
  }
Пример #3
0
  public void testCase2() throws Exception {
    ContextA contextA = new ContextA();

    OOEEContext context = OOEEContextFactory.createOOEEContext();

    context.setParsingContextObject("$", contextA);
    context.setEvaluationContextObject("$", contextA);

    String expressionStr = "$setValue(\"a\")";
    Expression expression = ExpressionParser.parse(expressionStr, context);
    ExpressionEvaluator.evaluate(expression, context);

    expressionStr = "$var\"aa\"";
    try {
      expression = ExpressionParser.parse(expressionStr, context);
      fail("no exception happend");
    } catch (Exception e) {
      assertTrue(true);
    }
  }
Пример #4
0
 /**
  * Parse the expression using default OOEEContext as the Parsing Context
  *
  * @param expressionString
  * @return parsedexpression
  * @throws ParsingException if the expression string is invalid
  * @see #parse(String)
  */
 public static Expression parse(String expressionString) throws ParsingException {
   return parse(expressionString, OOEEContextFactory.createOOEEContext());
 }