List of usage examples for org.apache.commons.scxml SCInstance getContext
public Context getContext(final TransitionTarget transitionTarget)
Context
for this TransitionTarget
. From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
@Override public Map<String, Map<String, List<Object[]>>> getAvailableEventsStates() { Map<String, Map<String, List<Object[]>>> eventsStates = new HashMap<String, Map<String, List<Object[]>>>(); if (engine.getCurrentStatus().isFinal()) // stop the interpretation by sending an empty config/available // event states return eventsStates; String event, id;// w w w. j a v a 2s . c o m Map<String, List<Object[]>> states; Map<String, Object> vars, rootVars; List<Object[]> state; int pos; SCInstance sci = engine.getSCInstance(); Set<String> datas; for (TransitionTarget tt : engine.getCurrentStatus().getAllStates()) { id = tt.getId(); pos = 0; for (Transition t : tt.getTransitionsList()) { event = t.getEvent(); event = (event != null || engine.isSuperStep()) ? event : TriggerEvent.EMPTY_EVENT; if (event != null) { // 1. add all events to the configuration if (!eventsStates.containsKey(event)) { eventsStates.put(event, new HashMap<String, List<Object[]>>()); } // 2. add all active source states to the config states = eventsStates.get(event); if (!states.containsKey(id)) { states.put(id, new LinkedList<Object[]>()); } // 3. add the transition condition to the config state = states.get(id); /* * the following 4 values in the Object array indicate: i) * the position of the transition ii) the condition of the * transition iii) that the evaluation of the transition's * condition is not performed in the last step, i.e. it is * 'UNKNOWN' // * iii) that the transition condition was not * changed in the last step, i.e. no dynamical change and * this is not a 'refresh' event */ state.add(new Object[] { pos, t.getCond() == null ? "" : t.getCond(), -1 }); // 4. add all contexts to the config vars = new HashMap<String, Object>(); while (tt != null) { vars.putAll(sci.getContext(tt).getVars()); tt = tt.getParent(); } rootVars = sci.getRootContext().getVars(); if (rootVars != null) { vars.putAll(rootVars); } // to skip double entries the names of all datas in the // state config are needed // the following set/for-loop could be removed if the used // list would check double occurrences itself -> exchange // LinkedList by something else datas = new HashSet<String>(); for (Object[] data : state) { if (data[0] instanceof String) { datas.add((String) data[0]); } } for (Entry<String, Object> e : vars.entrySet()) { /* * the following 3 values in the Object array indicate: * i) the name of the data ii) the current value of the * data iii) that the data value was not changed in the * last step, i.e. no dynamical change and this is not a * 'refresh' event */ if (!datas.contains(e.getKey())) { state.add(new Object[] { e.getKey(), e.getValue(), false }); datas.add(e.getKey()); } } } pos++; } } return eventsStates; }