📄 scxmlparser.java
字号:
});
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLParser.class);
log.error(errMsg, rte);
throw rte;
}
if (scxml != null) {
ModelUpdater.updateSCXML(scxml);
}
return scxml;
}
/**
* <p>API for standalone usage where the SCXML document is an
* InputSource. This method may be used when the SCXML document is
* packaged in a Java archive, or part of a compound document
* where the SCXML root is available as a
* <code>org.w3c.dom.Element</code> or via a <code>java.io.Reader</code>.
* </p>
*
* <p><em>Note:</em> Since there is no path resolution, the SCXML document
* must not have external state sources.</p>
*
* @param documentInputSource
* The InputSource for the SCXML document
* @param errHandler
* The SAX ErrorHandler
* @param customActions
* The list of {@link CustomAction}s this digester
* instance will process, can be null or empty
*
* @return SCXML The SCXML object corresponding to the file argument
*
* @throws IOException Underlying Digester parsing threw an IOException
* @throws SAXException Underlying Digester parsing threw a SAXException
* @throws ModelException If the resulting document model has flaws
*
* @see ErrorHandler
*/
public static SCXML parse(final InputSource documentInputSource,
final ErrorHandler errHandler, final List customActions)
throws IOException, SAXException, ModelException {
Digester scxmlParser = SCXMLParser.newInstance(null, null,
customActions);
scxmlParser.setErrorHandler(errHandler);
SCXML scxml = null;
try {
scxml = (SCXML) scxmlParser.parse(documentInputSource);
} catch (RuntimeException rte) {
// Intercept runtime exceptions, only to log them with a
// sensible error message about failure in document parsing
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLParser.class);
log.error(ERR_ISRC_PARSE_FAIL, rte);
throw rte;
}
if (scxml != null) {
ModelUpdater.updateSCXML(scxml);
}
return scxml;
}
/**
* <p>Obtain a SCXML digester instance for further customization.</p>
* <b>API Notes:</b>
* <ul>
* <li>Use the digest() convenience methods if you do not
* need a custom digester.</li>
* <li>After the SCXML document is parsed by the customized digester,
* the object model <b>must</b> be made executor-ready by calling
* <code>updateSCXML(SCXML)</code> method in this class.</li>
* </ul>
*
* @return Digester A newly configured SCXML digester instance
*
* @see SCXMLParser#updateSCXML(SCXML)
*/
public static Digester newInstance() {
return newInstance(null, null, null);
}
/**
* <p>Obtain a SCXML digester instance for further customization.</p>
* <b>API Notes:</b>
* <ul>
* <li>Use the digest() convenience methods if you do not
* need a custom digester.</li>
* <li>After the SCXML document is parsed by the customized digester,
* the object model <b>must</b> be made executor-ready by calling
* <code>updateSCXML(SCXML)</code> method in this class.</li>
* </ul>
*
* @param pr The PathResolver, may be null for standalone documents
* @return Digester A newly configured SCXML digester instance
*
* @see SCXMLParser#updateSCXML(SCXML)
*/
public static Digester newInstance(final PathResolver pr) {
return newInstance(null, pr, null);
}
/**
* <p>Obtain a SCXML digester instance for further customization.</p>
* <b>API Notes:</b>
* <ul>
* <li>Use the digest() convenience methods if you do not
* need a custom digester.</li>
* <li>After the SCXML document is parsed by the customized digester,
* the object model <b>must</b> be made executor-ready by calling
* <code>updateSCXML(SCXML)</code> method in this class.</li>
* </ul>
*
* @param scxml The parent SCXML document if there is one (in case of
* state templates for example), null otherwise
* @param pr The PathResolver, may be null for standalone documents
* @return Digester A newly configured SCXML digester instance
*
* @see SCXMLParser#updateSCXML(SCXML)
*/
public static Digester newInstance(final SCXML scxml,
final PathResolver pr) {
return newInstance(scxml, pr, null);
}
/**
* <p>Obtain a SCXML digester instance for further customization.</p>
* <b>API Notes:</b>
* <ul>
* <li>Use the digest() convenience methods if you do not
* need a custom digester.</li>
* <li>After the SCXML document is parsed by the customized digester,
* the object model <b>must</b> be made executor-ready by calling
* <code>updateSCXML(SCXML)</code> method in this class.</li>
* </ul>
*
* @param scxml The parent SCXML document if there is one (in case of
* state templates for example), null otherwise
* @param pr The PathResolver, may be null for standalone documents
* @param customActions The list of {@link CustomAction}s this digester
* instance will process, can be null or empty
* @return Digester A newly configured SCXML digester instance
*
* @see SCXMLParser#updateSCXML(SCXML)
*/
public static Digester newInstance(final SCXML scxml,
final PathResolver pr, final List customActions) {
Digester digester = new Digester();
digester.setNamespaceAware(true);
//Uncomment next line after SCXML DTD is available
//digester.setValidating(true);
WithDefaultsRulesWrapper rules =
new WithDefaultsRulesWrapper(initRules(scxml, pr, customActions));
rules.addDefault(new IgnoredElementRule());
digester.setRules(rules);
return digester;
}
/**
* <p>Update the SCXML object model and make it SCXMLExecutor ready.
* This is part of post-digester processing, and sets up the necessary
* object references throughtout the SCXML object model for the parsed
* document. Should be used only if a customized digester obtained
* using the <code>newInstance()</code> methods is needed.</p>
*
* @param scxml The SCXML object (output from Digester)
* @throws ModelException If the document model has flaws
*/
public static void updateSCXML(final SCXML scxml)
throws ModelException {
ModelUpdater.updateSCXML(scxml);
}
//---------------------- PRIVATE CONSTANTS ----------------------//
//// Patterns to get the digestion going, prefixed by XP_
/** Root <scxml> element. */
private static final String XP_SM = "scxml";
/** <state> children of root <scxml> element. */
private static final String XP_SM_ST = "scxml/state";
/** <state> children of root <scxml> element. */
private static final String XP_SM_PAR = "scxml/parallel";
/** <final> children of root <scxml> element. */
private static final String XP_SM_FIN = "scxml/final";
//// Universal matches, prefixed by XPU_
// State
/** <state> children of <state> elements. */
private static final String XPU_ST_ST = "!*/state/state";
/** <final> children of <state> elements. */
private static final String XPU_ST_FIN = "!*/state/final";
/** <state> children of <parallel> elements. */
private static final String XPU_PAR_ST = "!*/parallel/state";
// Parallel
/** <parallel> child of <state> elements. */
private static final String XPU_ST_PAR = "!*/state/parallel";
// If
/** <if> element. */
private static final String XPU_IF = "!*/if";
// Executables, next three patterns useful when adding custom actions
/** <onentry> element. */
private static final String XPU_ONEN = "!*/onentry";
/** <onexit> element. */
private static final String XPU_ONEX = "!*/onexit";
/** <transition> element. */
private static final String XPU_TR = "!*/transition";
/** <finalize> element. */
private static final String XPU_FIN = "!*/finalize";
//// Path Fragments, constants prefixed by XPF_
// Onentries and Onexits
/** <onentry> child element. */
private static final String XPF_ONEN = "/onentry";
/** <onexit> child element. */
private static final String XPF_ONEX = "/onexit";
// Datamodel section
/** <datamodel> child element. */
private static final String XPF_DM = "/datamodel";
/** Individual <data> elements. */
private static final String XPF_DATA = "/data";
// Initial
/** <initial> child element. */
private static final String XPF_INI = "/initial";
// Invoke, param and finalize
/** <invoke> child element of <state>. */
private static final String XPF_INV = "/invoke";
/** <param> child element of <invoke>. */
private static final String XPF_PRM = "/param";
/** <finalize> child element of <invoke>. */
private static final String XPF_FIN = "/finalize";
// History
/** <history> child element. */
private static final String XPF_HIST = "/history";
// Transition, target and exit
/** <transition> child element. */
private static final String XPF_TR = "/transition";
/** <exit> child element, a Commons SCXML custom action. */
private static final String XPF_EXT = "/exit";
// Actions
/** <assign> child element. */
private static final String XPF_ASN = "/assign";
/** <event> child element. */
private static final String XPF_EVT = "/event";
/** <send> child element. */
private static final String XPF_SND = "/send";
/** <cancel> child element. */
private static final String XPF_CAN = "/cancel";
/** <elseif> child element. */
private static final String XPF_EIF = "/elseif";
/** <else> child element. */
private static final String XPF_ELS = "/else";
// Custom Commons SCXML actions
/** <var> child element. */
private static final String XPF_VAR = "/var";
/** <log> child element. */
private static final String XPF_LOG = "/log";
//// Other constants
// Error messages
/**
* Null URL passed as argument.
*/
private static final String ERR_NULL_URL = "Cannot parse null URL";
/**
* Null path passed as argument.
*/
private static final String ERR_NULL_PATH = "Cannot parse null URL";
/**
* Null InputSource passed as argument.
*/
private static final String ERR_NULL_ISRC = "Cannot parse null URL";
/**
* Parsing SCXML document has failed.
*/
private static final String ERR_DOC_PARSE_FAIL = "Error parsing "
+ "SCXML document: \"{0}\", with message: \"{1}\"\n";
/**
* Parsing SCXML document InputSource has failed.
*/
private static final String ERR_ISRC_PARSE_FAIL =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -