Commons SCXML provides its own implementation of the Java object model for SCXML and a configured Digester that can parse SCXML documents into that object model.
The primary convenience method exposed by the SCXMLParser
is:
//import java.io.IOException; //import java.net.URL; //import org.apache.commons.scxml.io.SCXMLParser; //import org.apache.commons.scxml.model.ModelException; //import org.apache.commons.scxml.model.SCXML; //import org.xml.sax.ErrorHandler; //import org.xml.sax.SAXException; SCXML scxml = null; try { scxml = SCXMLParser.parse(<URL>, <ErrorHandler>); } catch (IOException ioe) { // IOException while parsing } catch (SAXException se) { // SAXException while parsing } catch (ModelException me) { // ModelException while parsing } if (scxml == null) { // Parsing failed }
It returns an SCXML
object, which is the state machine /
chart represented in the Commons SCXML Java object model. This method
uses the URL
of the initial SCXML document to resolve any
relative URLs referenced by the document, such as src
attributes of State
SCXML elements.
Commons SCXML provides convenience implementations of most of the
interfaces such as ErrorHandler
.
The SCXMLParser exposes other convenience methods which can handle
a SCXML document specified using its "real path" on the local
system, in which case an additional
org.apache.commons.SCXML.PathResolver
parameter needs to be
supplied for resolving relative document references or as an
InputSource
, in which case there is no path resolution,
so the document must be a standalone document.
The SCXMLParser
Javadoc is available
here.