Example usage for org.apache.commons.scxml.model ModelException ModelException

List of usage examples for org.apache.commons.scxml.model ModelException ModelException

Introduction

In this page you can find the example usage for org.apache.commons.scxml.model ModelException ModelException.

Prototype

public ModelException(final Throwable cause) 

Source Link

Usage

From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLEngine.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.  jav  a2s .  com
public List<NegPossibleState> bfs(int min) throws ModelException {
    List<NegPossibleState> bootStrap = new LinkedList<>();

    TransitionTarget initial = model.getInitialTarget();
    NegPossibleState initialState = new NegPossibleState(initial, fillInitialVariables(),
            new HashSet<String>());
    bootStrap.add(initialState);

    while (bootStrap.size() < min) {
        NegPossibleState state = bootStrap.remove(0);

        if (state.nextState.getId().equalsIgnoreCase("end")) {
            throw new ModelException("Could not achieve required bootstrap without reaching end state");
        }

        //produce purely positive scenarios
        expandPositive(state, bootStrap);

        //possible state does not have enough negative values yet, produce scenarios with some
        if (state.negVariable.size() < negative) {
            expandNegative(state, bootStrap, negative - state.negVariable.size());
        }
    }

    return bootStrap;
}

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 ww  . j av  a2 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;
}