List of usage examples for org.apache.commons.scxml.model OnEntry getActions
public final List<Action> getActions()
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLCommons.java
/** * Expands a NegPossibleState using only the positive scenarios/assign statements * * @param state the NegPossibleState to expand * @param bootStrap the list to add new NegPossibleStates found by expansion *//*w ww . ja v a2 s . c o m*/ public void expandPositive(NegPossibleState state, List<NegPossibleState> bootStrap) { TransitionTarget nextState = state.nextState; OnEntry entry = nextState.getOnEntry(); List<Action> actions = entry.getActions(); //set every variable with cartesian product of 'assign' actions List<Map<String, String>> product = new LinkedList<>(); product.add(new HashMap<>(state.variables)); for (Action action : actions) { if (action instanceof Assign) { String expr = ((Assign) action).getExpr(); String variable = ((Assign) action).getName(); product = takeProduct(product, variable, splitSet(expr)); } } //apply every transform tag to the results of the cartesian product for (Action action : actions) { if (action instanceof Transform) { String name = ((Transform) action).getName(); DataTransformer tr = transformations.get(name); DataPipe pipe = new DataPipe(0, null); for (Map<String, String> p : product) { pipe.getDataMap().putAll(p); tr.transform(pipe); p.putAll(pipe.getDataMap()); } } } //check each set of possible assignments set against transition conditions checkTransitions(nextState, product, state.negVariable, bootStrap); }
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLCommons.java
/** * Expands a NegPossibleState using the negative scenarios as well, multiple times for different numbers * and combinations of negative scenarios * * @param state the NegPossibleState to expand * @param bootStrap the list to add new NegPossibleStates found by expansion * @param negDegreesFreedom the max number of negative scenarios this expansion can add *///from w w w .j a va 2s . co m public void expandNegative(NegPossibleState state, List<NegPossibleState> bootStrap, int negDegreesFreedom) { TransitionTarget nextState = state.nextState; OnEntry entry = nextState.getOnEntry(); List<Action> actions = entry.getActions(); //determine which variables have positive assignments, negative assignments, or both Set<String> positiveOnlyVariables = new HashSet<>(); Set<String> hasNegativeVariables = new HashSet<>(); Map<String, Assign> positiveAssignments = new HashMap<>(); Map<String, NegativeAssign> negativeAssignments = new HashMap<>(); for (Action action : actions) { if (action instanceof Assign) { String variable = ((Assign) action).getName(); positiveAssignments.put(variable, (Assign) action); positiveOnlyVariables.add(variable); } else if (action instanceof NegativeAssign) { String variable = ((NegativeAssign) action).getName(); negativeAssignments.put(variable, (NegativeAssign) action); hasNegativeVariables.add(variable); } } for (String variable : hasNegativeVariables) { positiveOnlyVariables.remove(variable); } //produce core cartesian product from variables with only positive assignments List<Map<String, String>> productCore = new LinkedList<>(); productCore.add(new HashMap<>(state.variables)); for (String variable : positiveOnlyVariables) { Assign assign = positiveAssignments.get(variable); String expr = assign.getExpr(); productCore = takeProduct(productCore, variable, splitSet(expr)); } //produce the negative assignments from the positive core, from 1 assignment to negDegreesFreedom assignments for (int n = 1; n <= negDegreesFreedom; n++) { //find all combinations of choosing n negative variables in negativeAssignments List<Set<String>> completeChoices = new LinkedList<Set<String>>(); List<Set<String>> incompleteChoices = new LinkedList<Set<String>>(); Set<String> emptyChoice = new HashSet<String>(); incompleteChoices.add(emptyChoice); for (String variable : hasNegativeVariables) { List<Set<String>> newChoices = new LinkedList<Set<String>>(); for (Set<String> choice : incompleteChoices) { Set<String> newChoice = new HashSet<>(choice); newChoice.add(variable); if (newChoice.size() == n) { completeChoices.add(newChoice); } else { newChoices.add(newChoice); } } for (Set<String> choice : newChoices) { incompleteChoices.add(choice); } } //for each choice of n negative variables, make the needed variable assignments for (Set<String> choice : completeChoices) { List<Map<String, String>> product = new LinkedList<>(productCore); Set<String> newlyNegativeVariables = new HashSet<>(hasNegativeVariables); //make the negative assignments for (String variable : choice) { NegativeAssign neg = negativeAssignments.get(variable); String expr = neg.getExpr(); product = takeProduct(product, variable, splitSet(expr)); newlyNegativeVariables.add(variable); } //make all other potentially negative assignments positive for (String variable2 : negativeAssignments.keySet()) { if (!choice.contains(variable2)) { Assign assign = positiveAssignments.get(variable2); String expr = assign.getExpr(); product = takeProduct(product, variable2, splitSet(expr)); } } //apply every transform tag to the results of the cartesian product for (Action action : actions) { if (action instanceof Transform) { String name = ((Transform) action).getName(); DataTransformer tr = transformations.get(name); DataPipe pipe = new DataPipe(0, null); for (Map<String, String> p : product) { pipe.getDataMap().putAll(p); tr.transform(pipe); p.putAll(pipe.getDataMap()); } } } checkTransitions(nextState, product, newlyNegativeVariables, bootStrap); } } }
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLEngine.java
/** * Searches the model for all variable assignments and makes a default map of those variables, setting them to "" * * @return the default variable assignment map *///from w ww . j a va2 s .c o m private Map<String, String> fillInitialVariables() { Map<String, TransitionTarget> targets = model.getChildren(); Set<String> variables = new HashSet<>(); for (TransitionTarget target : targets.values()) { OnEntry entry = target.getOnEntry(); List<Action> actions = entry.getActions(); for (Action action : actions) { if (action instanceof Assign) { String variable = ((Assign) action).getName(); variables.add(variable); } } } Map<String, String> result = new HashMap<>(); for (String variable : variables) { result.put(variable, ""); } return result; }
From source file:org.finra.datagenerator.engine.scxml.SCXMLEngine.java
/** * Searches the model for all variable assignments and makes a default map of those variables, setting them to "" * * @return the default variable assignment map *///from ww w. j a va 2 s.co m private Map<String, String> fillInitialVariables() { Map<String, TransitionTarget> targets = model.getChildren(); Set<String> variables = new HashSet<>(); for (TransitionTarget target : targets.values()) { OnEntry entry = target.getOnEntry(); List<Action> actions = entry.getActions(); for (Action action : actions) { if (action instanceof Assign) { String variable = ((Assign) action).getName(); variables.add(variable); } else if (action instanceof SetAssignExtension.SetAssignTag) { String variable = ((SetAssignExtension.SetAssignTag) action).getName(); variables.add(variable); } } } Map<String, String> result = new HashMap<>(); for (String variable : variables) { result.put(variable, ""); } return 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 *//*from w w w. ja va 2 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;//from ww w. j av a2 s.c om } 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); } } } }