Example usage for org.apache.commons.scxml Context getVars

List of usage examples for org.apache.commons.scxml Context getVars

Introduction

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

Prototype

Map<String, Object> getVars();

Source Link

Document

Get the Map of all variables in this Context.

Usage

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

@Override
public void send(String sendId, String target, String type, String event, Map<String, Object> params,
        Object hints, long delay, List<Node> externalNodes) {
    alreadyEvaluated.clear();//www  .  j a  v  a  2 s.c  o m
    if (type.equals("output_event")) {
        if (outputMessageMap.containsKey(sendId)) {
            // find context
            OutputMessage outputMessage = outputMessageMap.get(sendId);
            EObject temp = outputMessage;
            while (!(temp instanceof TransitionTarget)) {
                temp = temp.eContainer();
            }
            Context context = siamStateMachine.getContext(((TransitionTarget) temp).getId());
            // resolve bound entities
            context = ((SiamEvaluator) siamStateMachine.getEngine().getEvaluator())
                    .getTheEffectiveContext((JexlContext) context);
            List<EObject> evaluateContents = DialogueComponent.INSTANCE.evaluationService
                    .evaluateContents(outputMessage, context.getVars());
            if (evaluateContents.size() == 1) {
                DialogueComponent.dialogPlatformEventService
                        .postOutputEvent((OutputMessage) evaluateContents.get(0), DialogueComponent.INSTANCE);
            } else {
                Logger.getLogger(this.getClass()).error(
                        "Cannot send the following output event. There occured an error while evaluating inner script expressions!\n"
                                + EmfPersistence.writeToString(outputMessage));
            }
        } else {
            Logger.getLogger(this.getClass()).warn(String.format(
                    "Cannot raise send event with id: %s. The id must belong to an object of type OutputRequest!",
                    sendId));
        }
    } else {
        siamStateMachine.fireEvent(type, null);
    }
}

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

public boolean unifies(Object inst, PPattern pattern, String transitionId) {
    Context currentContext = siamStateMachine.getCurrentContext();
    if (inst instanceof String) {
        try {//from   www  .ja  v a 2 s  .  co  m
            inst = eval(currentContext, (String) inst);
        } catch (SCXMLExpressionException e) {
            Logger.getLogger(getClass()).warn(e.getLocalizedMessage());
        }
    } else if (inst instanceof EObject) {
        List<EObject> res = DialogueComponent.INSTANCE.evaluationService.evaluateContents((EObject) inst,
                currentContext.getVars());
        if (res.isEmpty()) {
            return false;
        }
        inst = res.get(0);
    }

    try {
        pattern = resolveJexlExpressions(pattern);
    } catch (SCXMLExpressionException e1) {
        Logger.getLogger(getClass()).warn(e1.getLocalizedMessage());
        return false;
    }

    MatchReport matchReport = Matches.matches(inst, pattern);
    if (matchReport.result == MatchResult.MATCH_SUCCESS) {
        if (!variableCache.containsKey(transitionId)) {
            variableCache.put(transitionId, matchReport.variables);
        } else {
            variableCache.get(transitionId).putAll(matchReport.variables);
        }
        return true;
    } else {
        return false;
    }
}