List of usage examples for org.apache.commons.scxml.model TransitionTarget getParent
public final TransitionTarget getParent()
From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java
/** * Gets the signals that would trigger transitions for the current state. * <p>//from w w w. j a v a 2 s. com * When actually sending such signals later on, the SM may have moved to a different state. * To prevent this, you can synchronize on this AcsScxmlEngine, which will block concurrent calls to {@link #fireSignal(Enum)}. * <p> * This method can be useful for displaying applicable signals in a GUI, * or to reject signals (with exception etc) that do not "fit" the current state * (while normally such signals would be silently ignored). * The latter gets used in {@link #fireSignalWithErrorFeedback(Enum)}. * * @see org.apache.commons.scxml.semantics.SCXMLSemanticsImpl#enumerateReachableTransitions(SCXML, Step, ErrorReporter) */ public synchronized Set<S> getApplicableSignals() { Set<String> events = new HashSet<String>(); @SuppressWarnings("unchecked") Set<TransitionTarget> stateSet = new HashSet<TransitionTarget>(exec.getCurrentStatus().getStates()); LinkedList<TransitionTarget> todoList = new LinkedList<TransitionTarget>(stateSet); while (!todoList.isEmpty()) { TransitionTarget tt = todoList.removeFirst(); @SuppressWarnings("unchecked") List<Transition> transitions = tt.getTransitionsList(); for (Transition t : transitions) { String event = t.getEvent(); events.add(event); } TransitionTarget parentTT = tt.getParent(); if (parentTT != null && !stateSet.contains(parentTT)) { stateSet.add(parentTT); todoList.addLast(parentTT); } } // convert signal names to enum constants Set<S> ret = new HashSet<S>(); for (String signalName : events) { S signal = Enum.valueOf(signalType, signalName); ret.add(signal); } return ret; }
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;/* www.ja v a 2s . c om*/ 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; }