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

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

Introduction

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

Prototype

Object get(String name);

Source Link

Document

Get the value of this variable; delegating to parent.

Usage

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

@Override
public Map<String, Object> getCurrentScxmlContext() {
    Map<String, Object> result = new HashMap<String, Object>();
    Context currentContext = stateMachine.getCurrentContext();
    List<String> activeStates = stateMachine.getAllActiveStates();
    for (String stateId : activeStates) {
        AbstractState node = idToDialogueNode.get(stateId);
        for (Variable variable : node.getVariables()) {
            result.put(variable.getName(), currentContext.get(variable.getName()));
        }/*  ww w.  j a v a  2s. c  om*/
    }
    return result;
}

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

@Override
public void onTransition(TransitionTarget from, TransitionTarget to, Transition transition) {
    // save variables of firing transition to context that were filled
    // during transition pattern matching process
    Context currentContext = siamStateMachine.getCurrentContext();
    Log log = (Log) transition.getActions().get(0);
    String transitionId = log.getLabel();
    if (variableCache.containsKey(transitionId)) {
        Map<String, Object> variables = variableCache.get(transitionId);
        // set context variables
        for (String key : variables.keySet()) {
            Variable variable = (Variable) currentContext.get("_variable$" + key);
            if (variable == null) {
                Logger.getLogger(this.getClass())
                        .warn(String.format(
                                "In transition \'%s': Variable \"%s\" is not defined for scope of state \"%s\"",
                                transitionId, key, currentContext.get("stateID")));
            } else {
                try {
                    currentContext.set(key, variables.get(key));
                } catch (IllegalArgumentException ex) {
                    Logger.getLogger(getClass()).warn(
                            String.format("In transition \'%s': %s", transitionId, ex.getLocalizedMessage()));
                }/*from   ww w .ja  va 2  s .  com*/
            }

        }
    }
    variableCache.remove(transitionId);
}