Example usage for org.apache.commons.scxml.io SCXMLParser parse

List of usage examples for org.apache.commons.scxml.io SCXMLParser parse

Introduction

In this page you can find the example usage for org.apache.commons.scxml.io SCXMLParser parse.

Prototype

public static SCXML parse(final InputSource documentInputSource, final ErrorHandler errHandler,
        final List<CustomAction> customActions) throws IOException, SAXException, ModelException 

Source Link

Document

API for standalone usage where the SCXML document is an InputSource.

Usage

From source file:alma.acs.nc.sm.generic.AcsScxmlEngine.java

/**
 * Loads the SCXML model from an XML file stored inside of a jar file on the classpath.
 * <p>//from w ww .j av a  2 s  .co m
 * TODO: define and throw exception in case of load/parse failure.
 * 
 * @param scxmlFileName The qualified xml file name, e.g. "/alma/acs/nc/sm/generated/EventSubscriberSCXML.xml"
 */
public void loadModel(final String scxmlFileName) {

    try {
        // TODO: Pass InputSource instead of String,
        // because the xml file may be inside a component impl jar file
        // which is not visible to the classloader of this generic SMEngine class.
        URL scxmlUrl = getClass().getResource(scxmlFileName);

        if (scxmlUrl == null) {
            logger.severe(
                    "Failed to load the scxml definition file '" + scxmlFileName + "' from the classpath.");
            // TODO ex;
        }

        List<CustomAction> scxmlActions = actionDispatcher.getScxmlActionMap();
        scxml = SCXMLParser.parse(scxmlUrl, errorTracer, scxmlActions);
        logger.fine("Loaded SCXML file " + scxmlUrl.toString() + "...");
    } catch (ModelException e) {
        logger.severe("Could not load model: " + e.getMessage());
    } catch (SAXException e) {
        logger.severe("Could not load model: " + e.getMessage());
    } catch (IOException e) {
        logger.severe("Could not load model: " + e.getMessage());
    }
}

From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java

/**
 * Load the SCXML object representing this state machine.
 * //from ww  w . j av a2  s. co m
 * @param scxmlDocument
 *            The URL pointing to the SCXML document that describes the
 *            &quot;lifecycle&quot; of the instances of this class.
 * @return Returns the stateMachine.
 */
private SCXML load(final URL scxmlDocument) {

    log = LogFactory.getLog(this.getClass());
    // logInfo(log.getClass().getName());
    if (log.isDebugEnabled()) {
        // logInfo("debub enabled");
    }
    ErrorHandler errHandler = new SimpleErrorHandler();
    try {

        List customActions = new ArrayList();
        CustomAction ca = new CustomAction("http://www.dfki.de/mmds/scxml/customaction", "raise", Raise.class);
        customActions.add(ca);

        SCXML stateMachine = SCXMLParser.parse(scxmlDocument, errHandler, customActions);
        // logInfo("SCXML loaded");
        return stateMachine;
    } catch (IOException ioe) {
        logError(ioe);
    } catch (SAXException sae) {
        logError(sae);
    } catch (ModelException me) {
        logError(me);
    }
    return null;
}

From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLEngine.java

/**
 * Sets the SCXML model with an InputStream
 *
 * @param inputFileStream the model input stream
 *///from   w  w  w.  j a  v a2s.  co  m
public void setModelByInputFileStream(InputStream inputFileStream) {
    try {
        this.model = SCXMLParser.parse(new InputSource(inputFileStream), null, customActions());
        this.setStateMachine(this.model);
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}

From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLEngine.java

/**
 * Sets the SCXML model with a string/*from   w  w w  .ja v  a 2  s  .  co m*/
 *
 * @param model the model text
 */
public void setModelByText(String model) {
    try {
        InputStream is = new ByteArrayInputStream(model.getBytes());
        this.model = SCXMLParser.parse(new InputSource(is), null, customActions());
        this.setStateMachine(this.model);
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}

From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLGapper.java

private void setModel(String model) {
    try {//from ww  w  .ja  v  a2s .  c  o  m
        InputStream is = new ByteArrayInputStream(model.getBytes());
        this.model = SCXMLParser.parse(new InputSource(is), null, customActions());
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}

From source file:org.finra.datagenerator.engine.scxml.SCXMLEngine.java

/**
 * Sets the SCXML model with an InputStream
 *
 * @param inputFileStream the model input stream
 *///from  w w w  . j a  va2s . co m
public void setModelByInputFileStream(InputStream inputFileStream) {
    try {
        this.model = SCXMLParser.parse(new InputSource(inputFileStream), null,
                customActionsFromTagExtensions());
        this.setStateMachine(this.model);
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}

From source file:org.finra.datagenerator.engine.scxml.SCXMLEngine.java

/**
 * Sets the SCXML model with a string/*from   w  w  w. j a va 2  s  .co m*/
 *
 * @param model the model text
 */
public void setModelByText(String model) {
    try {
        InputStream is = new ByteArrayInputStream(model.getBytes());
        this.model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions());
        this.setStateMachine(this.model);
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}

From source file:org.finra.datagenerator.engine.scxml.SCXMLFrontierTest.java

/**
 * Multiple variable assignments using set:{}
 *//*from  w w w .j av a2 s . c om*/
@Test
public void testMultiVariableAssignment() {
    SCXMLEngine e = new SCXMLEngine();
    InputStream is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml");
    e.setModelByInputFileStream(is);

    List<CustomTagExtension> tagExtensionList = customTagExtensionList();

    try {
        List<PossibleState> bfs = e.bfs(343);
        PossibleState p = bfs.get(0);

        try {
            is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml");
            SCXML model = SCXMLParser.parse(new InputSource(is), null,
                    customActionsFromTagExtensions(tagExtensionList));

            SCXMLFrontier frontier = new SCXMLFrontier(p, model, tagExtensionList);
            Queue<Map<String, String>> queue = new LinkedList<>();
            AtomicBoolean flag = new AtomicBoolean(false);
            frontier.searchForScenarios(new QueueResultsProcessing(queue), flag);

            Assert.assertEquals(queue.size(), 6);
        } catch (IOException | SAXException ex) {
            Assert.fail();
        }
    } catch (ModelException ex) {
        Assert.fail();
    }
}

From source file:org.finra.datagenerator.engine.scxml.SCXMLFrontierTest.java

/**
 * Test the ability of the exit flag to stop the DFS in SCXMLFrontier
 *///from www  . j a va 2s  .co  m
@Test
public void testExitFlag() {
    SCXMLEngine e = new SCXMLEngine();
    InputStream is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml");
    e.setModelByInputFileStream(is);

    List<CustomTagExtension> tagExtensionList = customTagExtensionList();

    try {
        List<PossibleState> bfs = e.bfs(1);
        PossibleState p = bfs.get(0);

        try {
            is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml");
            SCXML model = SCXMLParser.parse(new InputSource(is), null,
                    customActionsFromTagExtensions(tagExtensionList));

            SCXMLFrontier frontier = new SCXMLFrontier(p, model, tagExtensionList);
            Queue<Map<String, String>> queue = new LinkedList<>();
            AtomicBoolean flag = new AtomicBoolean(true);
            frontier.searchForScenarios(new QueueResultsProcessing(queue), flag);

            Assert.assertEquals(queue.isEmpty(), true);
        } catch (IOException | SAXException ex) {
            Assert.fail();
        }
    } catch (ModelException ex) {
        Assert.fail();
    }
}

From source file:org.finra.datagenerator.engine.scxml.SCXMLGapper.java

private void setModel(String model, List<CustomTagExtension> tagExtensionList) {
    List<CustomAction> customActions = new ArrayList<>();

    for (CustomTagExtension tagExtension : tagExtensionList) {
        if (!tagExtension.getTagNameSpace().equals("http://www.w3.org/2005/07/scxml")) {
            CustomAction action = new CustomAction(tagExtension.getTagNameSpace(), tagExtension.getTagName(),
                    tagExtension.getTagActionClass());
            customActions.add(action);//from   w  w w  .  j a v a  2  s .  c om
        }
    }

    try {
        InputStream is = new ByteArrayInputStream(model.getBytes());
        this.model = SCXMLParser.parse(new InputSource(is), null, customActions);
    } catch (IOException | SAXException | ModelException e) {
        e.printStackTrace();
    }
}