Package com.opengamma.financial.expression

Examples of com.opengamma.financial.expression.UserExpression$Evaluator


    }
  }

  @Override
  public OverrideOperation compile(final String operation, final ComputationTargetResolver.AtVersionCorrection resolver) {
    final UserExpression expr = getParser().parse(operation);
    return new Evaluator(expr, resolver);
  }
View Full Code Here


  private static final Logger s_logger = LoggerFactory.getLogger(ExpressionParserTest.class);

  private static void parse(final String str, final String expected) {
    s_logger.debug("Parsing {}", str);
    final UserExpression expr = new ExpressionParser().parse(str);
    assertNotNull(expr);
    assertEquals(expr.toString(), expected);
  }
View Full Code Here

    assertEquals(expr.toString(), expected);
  }

  @Test(expectedExceptions = {IllegalArgumentException.class })
  public void testEmptyString() {
    final UserExpression expr = new ExpressionParser().parse("");
  }
View Full Code Here

    final UserExpression expr = new ExpressionParser().parse("");
  }

  @Test(expectedExceptions = {IllegalArgumentException.class })
  public void testIllegalString() {
    final UserExpression expr = new ExpressionParser().parse("Foo less \"Bar\"");
  }
View Full Code Here

            System.out.println("USAGE: java "
                    + StandaloneJexlExpressions.class.getName()
                    + "<url|filename>");
            System.exit(-1);
        }
        Evaluator evaluator = new JexlEvaluator();
        StandaloneUtils.execute(args[0], evaluator);
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
        Context ctx = exctx.getContext(getParentEnterableState());
        Evaluator eval = exctx.getEvaluator();
        ctx.setLocal(getNamespacesKey(), getNamespaces());
        exctx.getAppLog().info(label + ": " + String.valueOf(eval.eval(ctx, expr)));
        ctx.setLocal(getNamespacesKey(), null);
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
        Context ctx = exctx.getContext(getParentEnterableState());
        Evaluator eval = exctx.getEvaluator();
        ctx.setLocal(getNamespacesKey(), getNamespaces());
        Object varObj = eval.eval(ctx, expr);
        ctx.setLocal(getNamespacesKey(), null);
        ctx.setLocal(name, varObj);
        if (exctx.getAppLog().isDebugEnabled()) {
            exctx.getAppLog().debug("<var>: Defined variable '" + name
                + "' with initial value '" + String.valueOf(varObj) + "'");
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
        Context ctx = exctx.getContext(getParentEnterableState());
        Evaluator eval = exctx.getEvaluator();
        ctx.setLocal(getNamespacesKey(), getNamespaces());
        try {
            Object arrayObject = eval.eval(ctx,array);
            if (arrayObject != null && (arrayObject instanceof Iterable || arrayObject.getClass().isArray())) {
                if (arrayObject.getClass().isArray()) {
                    for (int currentIndex = 0, size = Array.getLength(arrayObject); currentIndex < size; currentIndex++) {
                        ctx.setLocal(item, Array.get(arrayObject, currentIndex));
                        ctx.setLocal(index, currentIndex);
View Full Code Here

     */
    @Override
    public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
        EnterableState parentState = getParentEnterableState();
        Context ctx = exctx.getContext(parentState);
        Evaluator eval = exctx.getEvaluator();
        ctx.setLocal(getNamespacesKey(), getNamespaces());
        Boolean rslt;
        try {
            rslt = eval.evalCond(ctx, cond);
            if (rslt == null) {
                if (exctx.getAppLog().isDebugEnabled()) {
                    exctx.getAppLog().debug("Treating as false because the cond expression was evaluated as null: '"
                            + cond + "'");
                }
                rslt = Boolean.FALSE;
            }
        } catch (SCXMLExpressionException e) {
            rslt = Boolean.FALSE;
            exctx.getInternalIOProcessor().addEvent(new TriggerEvent(TriggerEvent.ERROR_EXECUTION, TriggerEvent.ERROR_EVENT));
            exctx.getErrorReporter().onError(ErrorConstants.EXPRESSION_ERROR, "Treating as false due to error: "
                    + e.getMessage(), this);
        }
        execute = rslt;
        ctx.setLocal(getNamespacesKey(), null);
        // The "if" statement is a "container"
        for (Action aa : actions) {
            if (execute && !(aa instanceof ElseIf)) {
                aa.execute(exctx);
            } else if (execute && aa instanceof ElseIf) {
                break;
            } else if (aa instanceof Else) {
                execute = true;
            } else if (aa instanceof ElseIf) {
                ctx.setLocal(getNamespacesKey(), getNamespaces());
                execute = eval.evalCond(ctx, ((ElseIf) aa).getCond());
                ctx.setLocal(getNamespacesKey(), null);
            }
        }
    }
View Full Code Here

    public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
        // Send attributes evaluation
        EnterableState parentState = getParentEnterableState();
        Context ctx = exctx.getContext(parentState);
        ctx.setLocal(getNamespacesKey(), getNamespaces());
        Evaluator eval = exctx.getEvaluator();
        // Most attributes of <send> are expressions so need to be
        // evaluated before the EventDispatcher callback
        Object hintsValue = null;
        if (hints != null) {
            hintsValue = eval.eval(ctx, hints);
        }
        String targetValue = target;
        if (target != null) {
            targetValue = (String) eval.eval(ctx, target);
            if ((targetValue == null || targetValue.trim().length() == 0)
                    && exctx.getAppLog().isWarnEnabled()) {
                exctx.getAppLog().warn("<send>: target expression \"" + target
                    + "\" evaluated to null or empty String");
            }
        }
        String typeValue;
        if (type != null) {
            typeValue = (String) eval.eval(ctx, type);
            if ((typeValue == null || typeValue.trim().length() == 0)
                    && exctx.getAppLog().isWarnEnabled()) {
                exctx.getAppLog().warn("<send>: type expression \"" + type
                    + "\" evaluated to null or empty String");
            }
        } else {
            // must default to 'scxml' when unspecified
            typeValue = TYPE_SCXML;
        }
        Map<String, Object> params = null;
        if (namelist != null) {
            StringTokenizer tkn = new StringTokenizer(namelist);
            params = new HashMap<String, Object>(tkn.countTokens());
            while (tkn.hasMoreTokens()) {
                String varName = tkn.nextToken();
                Object varObj = ctx.get(varName);
                if (varObj == null) {
                    //considered as a warning here
                    exctx.getErrorReporter().onError(ErrorConstants.UNDEFINED_VARIABLE,
                            varName + " = null", parentState);
                }
                params.put(varName, varObj);
            }
        }
        long wait = 0L;
        if (delay != null) {
            Object delayValue = eval.eval(ctx, delay);
            if (delayValue != null) {
                String delayString = delayValue.toString();
                wait = parseDelay(delayString, exctx.getAppLog());
            }
        }
        String eventValue = event;
        if (event != null) {
            eventValue = (String) eval.eval(ctx, event);
            if ((eventValue == null || eventValue.trim().length() == 0) && exctx.getAppLog().isWarnEnabled()) {
                exctx.getAppLog().warn("<send>: event expression \"" + event
                    + "\" evaluated to null or empty String");
            }
        }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.expression.UserExpression$Evaluator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.