List of usage examples for org.apache.commons.scxml.model Transition getEvent
public final String getEvent()
From source file:de.dfki.iui.mmds.scxml.engine.events.SCXMLOnTransitionEvent.java
private static Map<String, Object> getMap(String id, TransitionTarget from, TransitionTarget to, Transition transition) { Map<String, Object> properties = new HashMap<String, Object>(6); properties.put(FROM, from.getId());//from w w w . j av a 2 s. c o m properties.put(TO, to.getId()); properties.put(TRANSITION, transition.getEvent()); properties.put(CONDITION, transition.getCond()); properties.put(ID, id); properties.put(EventConstants.TIMESTAMP, System.currentTimeMillis()); return properties; }
From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java
/** * Gets the signals that would trigger transitions for the current state. * <p>//from ww w. j a v a 2s. c om * 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 List<String> getAvailableEvents() { Set<TransitionTarget> states = engine.getCurrentStatus().getAllStates(); // logInfo("found states: " + states.size()); Set<Transition> transitions = new HashSet<Transition>(); for (TransitionTarget state : states) { // logInfo("found state: " + state.getId()); transitions.addAll(state.getTransitionsList()); }//from www.j a va 2s. c o m List<String> events = new LinkedList<String>(); for (Transition t : transitions) { // System.out.println("Available event: " + t.getEvent()); if (t.getEvent() != null) { events.add(t.getEvent()); } } return events; }
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;//from ww w. j a va2s . com 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; }
From source file:org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle.java
@Override public String[] getAvailableActions(RequestContext context) { Resource resource = context.getResource(); String currentState;/* w ww . ja va 2 s .co m*/ if (resource.getProperty(stateProperty) == null) { return new String[0]; } currentState = resource.getProperty(stateProperty).replace(" ", "."); initializeAspect(context, currentState); // Need to check whether the correct user has done the checking ArrayList<String> actions = new ArrayList<String>(); String user = CurrentSession.getUser(); State currentExecutionState = (State) (scxml.getChildren()).get(currentState); List currentTransitions = currentExecutionState.getTransitionsList(); try { List<PermissionsBean> permissionsBeans = transitionPermission.get(currentState); String[] roles = CurrentSession.getUserRealm().getUserStoreManager().getRoleListOfUser(user); /*In this loop we do both of the following tasks * 1.Make check items visible, not visible to the user * 2.Get the list of actions that is possible to the user*/ for (Object currentTransition : currentTransitions) { Transition t = (Transition) currentTransition; String transitionName = t.getEvent(); List<String> possibleActions = getPossibleActions(resource, currentState); if ((isTransitionAllowed(roles, permissionsBeans, transitionName) || permissionsBeans == null) && possibleActions.contains(transitionName)) { actions.add(transitionName); } } } catch (UserStoreException e) { log.error("Failed to get the current user role :", e); return new String[0]; } return actions.toArray(new String[actions.size()]); }
From source file:org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle.java
private void populateItems() throws Exception { Map stateList = scxml.getChildren(); for (Object stateObject : stateList.entrySet()) { Map.Entry state = (Map.Entry) stateObject; String currentStateName = (String) state.getKey(); State currentState = (State) state.getValue(); Datamodel model = currentState.getDatamodel(); states.add(currentStateName);// w w w. j a v a 2s. c om if (model != null) { List dataList = model.getData(); for (Object dataObject : dataList) { Data data = (Data) dataObject; OMElement node = XMLUtils.toOM((Element) data.getNode()); /* * when associating we will map the custom data model to a set of beans. * These will be used for further actions. * */ populateCheckItems(currentStateName, node, checkListItems); populateTransitionValidations(currentStateName, node, transitionValidations); populateTransitionPermissions(currentStateName, node, transitionPermission); populateTransitionScripts(currentStateName, node, scriptElements); populateTransitionUIs(currentStateName, node, transitionUIs); populateTransitionExecutors(currentStateName, node, transitionExecution); populateTransitionApprovals(currentStateName, node, transitionApproval); } } List<String> events = new ArrayList<String>(); for (Object t : currentState.getTransitionsList()) { Transition transition = (Transition) t; events.add(transition.getEvent()); } stateEvents.put(currentStateName, events); } }
From source file:org.wso2.carbon.pc.core.extensions.aspects.ProcessLifeCycle.java
@Override public String[] getAvailableActions(RequestContext context) { Resource resource = context.getResource(); String currentState;/*from w w w . ja v a 2 s . c o m*/ if (resource.getProperty(stateProperty) == null) { return new String[0]; } currentState = resource.getProperty(stateProperty).replace(" ", "."); initializeAspect(context, currentState); ArrayList<String> actions = new ArrayList<String>(); String user = CurrentSession.getUser(); State currentExecutionState = (State) (scxml.getChildren()).get(currentState); List currentTransitions = currentExecutionState.getTransitionsList(); try { List<PermissionsBean> permissionsBeans = transitionPermission.get(currentState); String[] roles = CurrentSession.getUserRealm().getUserStoreManager().getRoleListOfUser(user); for (Object currentTransition : currentTransitions) { Transition t = (Transition) currentTransition; String transitionName = t.getEvent(); List<String> possibleActions = getPossibleActions(resource, currentState); if ((isTransitionAllowed(roles, permissionsBeans, transitionName) || permissionsBeans == null) && possibleActions.contains(transitionName)) { actions.add(transitionName); } } } catch (UserStoreException e) { log.error("Failed to get the current user role :", e); return new String[0]; } return actions.toArray(new String[actions.size()]); }
From source file:org.wso2.carbon.pc.core.extensions.aspects.ProcessLifeCycle.java
private void populateItems() throws Exception { Map stateList = scxml.getChildren(); for (Object stateObject : stateList.entrySet()) { Map.Entry state = (Map.Entry) stateObject; String currentStateName = (String) state.getKey(); State currentState = (State) state.getValue(); Datamodel model = currentState.getDatamodel(); states.add(currentStateName);// ww w . j a v a 2 s. c om if (model != null) { List dataList = model.getData(); for (Object dataObject : dataList) { Data data = (Data) dataObject; OMElement node = XMLUtils.toOM((Element) data.getNode()); populateCheckItems(currentStateName, node, checkListItems); populateTransitionValidations(currentStateName, node, transitionValidations); populateTransitionPermissions(currentStateName, node, transitionPermission); populateTransitionScripts(currentStateName, node, scriptElements); populateTransitionUIs(currentStateName, node, transitionUIs); populateTransitionExecutors(currentStateName, node, transitionExecution); populateTransitionApprovals(currentStateName, node, transitionApproval); populateTransitionInputs(currentStateName, node, transitionInputs); } } List<String> events = new ArrayList<String>(); for (Object t : currentState.getTransitionsList()) { Transition transition = (Transition) t; events.add(transition.getEvent()); } stateEvents.put(currentStateName, events); } }
From source file:org.wso2.jaggery.scxml.aspects.JaggeryTravellingPermissionLifeCycle.java
@Override public String[] getAvailableActions(RequestContext context) { Resource resource = context.getResource(); String currentState;/* w w w.ja v a 2 s. co m*/ if (resource.getProperty(stateProperty) == null) { return new String[0]; } currentState = resource.getProperty(stateProperty).replace(" ", "."); initializeAspect(context, currentState); // Need to check whether the correct user has done the checking ArrayList<String> actions = new ArrayList<String>(); String user = CurrentSession.getUser(); State currentExecutionState = (State) (scxml.getChildren()).get(currentState); List currentTransitions = currentExecutionState.getTransitionsList(); try { List<PermissionsBean> permissionsBeans = transitionPermission.get(currentState); String[] roles = CurrentSession.getUserRealm().getUserStoreManager().getRoleListOfUser(user); /*In this loop we do both of the following tasks * 1.Make check items visible, not visible to the user * 2.Get the list of actions that is possible to the user*/ for (Object currentTransition : currentTransitions) { Transition t = (Transition) currentTransition; String transitionName = t.getEvent(); List<String> possibleActions = getPossibleActions(resource, currentState); if ((Utils.isTransitionAllowed(roles, permissionsBeans, transitionName) || permissionsBeans == null) && possibleActions.contains(transitionName)) { actions.add(transitionName); } } } catch (UserStoreException e) { log.error("Failed to get the current user role :", e); return new String[0]; } return actions.toArray(new String[actions.size()]); }
From source file:org.wso2.jaggery.scxml.aspects.JaggeryTravellingPermissionLifeCycle.java
private void populateItems() throws Exception { Map stateList = scxml.getChildren(); for (Object stateObject : stateList.entrySet()) { Map.Entry state = (Map.Entry) stateObject; String currentStateName = (String) state.getKey(); State currentState = (State) state.getValue(); Datamodel model = currentState.getDatamodel(); states.add(currentStateName);/*from ww w .ja v a 2s.c o m*/ if (model != null) { List dataList = model.getData(); for (Object dataObject : dataList) { Data data = (Data) dataObject; OMElement node = XMLUtils.toOM((Element) data.getNode()); /* * when associating we will map the custom data model to a set of beans. * These will be used for further actions. * */ Utils.populateCheckItems(currentStateName, node, checkListItems); Utils.populateTransitionValidations(currentStateName, node, transitionValidations); Utils.populateTransitionPermissions(currentStateName, node, transitionPermission); Utils.populateTransitionScripts(currentStateName, node, scriptElements); Utils.populateTransitionUIs(currentStateName, node, transitionUIs); Utils.populateTransitionExecutors(currentStateName, node, transitionExecution); Utils.populateTransitionApprovals(currentStateName, node, transitionApproval); } } List<String> events = new ArrayList<String>(); for (Object t : currentState.getTransitionsList()) { Transition transition = (Transition) t; events.add(transition.getEvent()); } stateEvents.put(currentStateName, events); } }