List of usage examples for org.apache.commons.scxml.model Transition getTargets
public final List<TransitionTarget> getTargets()
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLCommons.java
/** * For a given state in the state chart, every transition out from that state is checked against every possible * variable assignment; those combinations satisfying the transition condition are added to the bootstrap list * * @param nextState the state whose transitions are checked and which was * expanded to get the variable assignments * @param product a list of variable assignment maps * @param negativeVariables the variables with a negative value, or an empty set * @param bootStrap the bootstrap list *///from ww w. ja v a 2 s.c om public void checkTransitions(TransitionTarget nextState, List<Map<String, String>> product, Set<String> negativeVariables, List<NegPossibleState> bootStrap) { //go through every transition and see which of the products are valid, adding them to the list List<Transition> transitions = nextState.getTransitionsList(); for (Transition transition : transitions) { String condition = transition.getCond(); TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0); for (Map<String, String> p : product) { //transition condition satisfied, add to bootstrap list if (checkTransition(p, condition, negativeVariables)) { NegPossibleState result = new NegPossibleState(target, p, negativeVariables); bootStrap.add(result); } } } }
From source file:org.finra.datagenerator.engine.scxml.SCXMLEngine.java
/** * Performs a partial BFS on model until the search frontier reaches the desired bootstrap size * * @param min the desired bootstrap size * @return a list of found PossibleState * @throws ModelException if the desired bootstrap can not be reached *//*w ww . j a va 2 s. c o m*/ public List<PossibleState> bfs(int min) throws ModelException { List<PossibleState> bootStrap = new LinkedList<>(); TransitionTarget initial = model.getInitialTarget(); PossibleState initialState = new PossibleState(initial, fillInitialVariables()); bootStrap.add(initialState); while (bootStrap.size() < min) { PossibleState state = bootStrap.remove(0); TransitionTarget nextState = state.nextState; if (nextState.getId().equalsIgnoreCase("end")) { throw new ModelException("Could not achieve required bootstrap without reaching end state"); } //run every action in series List<Map<String, String>> product = new LinkedList<>(); product.add(new HashMap<>(state.variables)); OnEntry entry = nextState.getOnEntry(); List<Action> actions = entry.getActions(); for (Action action : actions) { for (CustomTagExtension tagExtension : tagExtensionList) { if (tagExtension.getTagActionClass().isInstance(action)) { product = tagExtension.pipelinePossibleStates(action, product); } } } //go through every transition and see which of the products are valid, adding them to the list List<Transition> transitions = nextState.getTransitionsList(); for (Transition transition : transitions) { String condition = transition.getCond(); TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0); for (Map<String, String> p : product) { Boolean pass; if (condition == null) { pass = true; } else { //scrub the context clean so we may use it to evaluate transition conditional Context context = this.getRootContext(); context.reset(); //set up new context for (Map.Entry<String, String> e : p.entrySet()) { context.set(e.getKey(), e.getValue()); } //evaluate condition try { pass = (Boolean) this.getEvaluator().eval(context, condition); } catch (SCXMLExpressionException ex) { pass = false; } } //transition condition satisfied, add to bootstrap list if (pass) { PossibleState result = new PossibleState(target, p); bootStrap.add(result); } } } } return bootStrap; }
From source file:org.finra.datagenerator.engine.scxml.SCXMLFrontier.java
private void dfs(ProcessingStrategy processingStrategy, AtomicBoolean flag, PossibleState state) { if (flag.get()) { return;/*w w w.j a v a2 s. c o m*/ } TransitionTarget nextState = state.nextState; //reached end of chart, valid assignment found if (nextState.getId().equalsIgnoreCase("end")) { processingStrategy.processOutput(state.variables); return; } //run every action in series List<Map<String, String>> product = new LinkedList<>(); product.add(new HashMap<>(state.variables)); OnEntry entry = nextState.getOnEntry(); List<Action> actions = entry.getActions(); for (Action action : actions) { for (CustomTagExtension tagExtension : tagExtensionList) { if (tagExtension.getTagActionClass().isInstance(action)) { product = tagExtension.pipelinePossibleStates(action, product); } } } //go through every transition and see which of the products are valid, recursive searching on them List<Transition> transitions = nextState.getTransitionsList(); for (Transition transition : transitions) { String condition = transition.getCond(); TransitionTarget target = ((List<TransitionTarget>) transition.getTargets()).get(0); for (Map<String, String> p : product) { Boolean pass; if (condition == null) { pass = true; } else { //scrub the context clean so we may use it to evaluate transition conditional Context context = this.getRootContext(); context.reset(); //set up new context for (Map.Entry<String, String> e : p.entrySet()) { context.set(e.getKey(), e.getValue()); } //evaluate condition try { pass = (Boolean) this.getEvaluator().eval(context, condition); } catch (SCXMLExpressionException ex) { pass = false; } } //transition condition satisfied, continue search recursively if (pass) { PossibleState result = new PossibleState(target, p); dfs(processingStrategy, flag, result); } } } }