List of usage examples for org.apache.commons.scxml Context reset
void reset();
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLCommons.java
/** * Checks if a variable assignment satisfies a condition for a transition * Conditions involving the negative variables are auto satisfied/ignored * * @param variables the assignments * @param condition the condition * @param negativeVariables the negative variables * @return Boolean true if condition passes, false otherwise *///from w ww . j a v a 2s.c o m public Boolean checkTransition(Map<String, String> variables, String condition, Set<String> negativeVariables) { Boolean pass; //condition must exist if (condition == null) { pass = true; } else { //condition must not concern one of the negative variables for (String negativeVariable : negativeVariables) { if (condition.contains(negativeVariable)) { pass = true; return pass; } } //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 : variables.entrySet()) { context.set(e.getKey(), e.getValue()); } //evaluate condition try { pass = (Boolean) this.getEvaluator().eval(context, condition); } catch (SCXMLExpressionException ex) { pass = false; } } return pass; }
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 *///www . j av a2 s. co 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 av a 2 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); } } } }