Example usage for org.apache.commons.scxml SCXMLExpressionException SCXMLExpressionException

List of usage examples for org.apache.commons.scxml SCXMLExpressionException SCXMLExpressionException

Introduction

In this page you can find the example usage for org.apache.commons.scxml SCXMLExpressionException SCXMLExpressionException.

Prototype

public SCXMLExpressionException(final Throwable cause) 

Source Link

Usage

From source file:de.dfki.iui.mmds.dialogue.SiamEvaluator.java

private PPattern resolveJexlExpressions(PPattern pattern) throws SCXMLExpressionException {
    Context currentContext = siamStateMachine.getCurrentContext();
    PPattern patternClone = EcoreUtil.copy(pattern);
    TreeIterator<EObject> it = patternClone.eAllContents();
    while (it.hasNext()) {
        EObject next = it.next();/*from ww w .ja  v a2s. com*/
        if (next instanceof PRestriction && ((PRestriction) next).getExpression() != null
                && !((PRestriction) next).getExpression().isEmpty()) {
            Object result = eval(currentContext, ((PRestriction) next).getExpression());
            if (result == null)
                throw new SCXMLExpressionException(
                        "Cannot resolve expression: " + ((PRestriction) next).getExpression());
            try {
                // TODO alle Datentypen untersttzen
                if (next instanceof PStringRestriction) {
                    ((PRestriction) next).setValue(new BString(result.toString()));
                }
            } catch (ClassCastException ex) {
                throw new SCXMLExpressionException(String.format(
                        "Cannot cast result of expression %s, which is of type %s, to value of restriction with type %s.",
                        ((PRestriction) next).getExpression(), result.getClass().toString(),
                        ((PRestriction) next).eClass().getName()));
            }

        }
    }
    return patternClone;
}