📄 scxmlparser.java
字号:
"Could not parse SCXML InputSource";
/**
* Parser configuration error while registering data rule.
*/
private static final String ERR_PARSER_CFG_DATA = "XML Parser "
+ "misconfiguration, error registering <data> element rule";
/**
* Parser configuration error while registering send rule.
*/
private static final String ERR_PARSER_CFG_SEND = "XML Parser "
+ "misconfiguration, error registering <send> element rule";
/**
* Parser configuration error while registering body content rule for
* custom action.
*/
private static final String ERR_PARSER_CFG_CUSTOM = "XML Parser "
+ "misconfiguration, error registering custom action rules";
/**
* Error message while attempting to define a custom action which does
* not extend the Commons SCXML Action base class.
*/
private static final String ERR_CUSTOM_ACTION_TYPE = "Custom actions list"
+ " contained unknown object (not a Commons SCXML Action subtype)";
/**
* Error message when the URI in a <state>'s "src"
* attribute does not point to a valid SCXML document, and thus cannot be
* parsed.
*/
private static final String ERR_STATE_SRC =
"Source attribute in <state src=\"{0}\"> cannot be parsed";
/**
* Error message when the target of the URI fragment in a <state>'s
* "src" attribute is not defined in the referenced document.
*/
private static final String ERR_STATE_SRC_FRAGMENT = "URI Fragment in "
+ "<state src=\"{0}\"> is an unknown state in referenced document";
/**
* Error message when the target of the URI fragment in a <state>'s
* "src" attribute is not a <state> or <final> in
* the referenced document.
*/
private static final String ERR_STATE_SRC_FRAGMENT_TARGET = "URI Fragment"
+ " in <state src=\"{0}\"> does not point to a <state> or <final>";
// String constants
/** Slash. */
private static final String STR_SLASH = "/";
//---------------------- PRIVATE UTILITY METHODS ----------------------//
/*
* Private utility functions for configuring digester rule base for SCXML.
*/
/**
* Initialize the Digester rules for the current document.
*
* @param scxml The parent SCXML document (or null)
* @param pr The PathResolver
* @param customActions The list of custom actions this digester needs
* to be able to process
*
* @return scxmlRules The rule set to be used for digestion
*/
private static ExtendedBaseRules initRules(final SCXML scxml,
final PathResolver pr, final List customActions) {
ExtendedBaseRules scxmlRules = new ExtendedBaseRules();
scxmlRules.setNamespaceURI(NAMESPACE_SCXML);
//// SCXML
scxmlRules.add(XP_SM, new ObjectCreateRule(SCXML.class));
scxmlRules.add(XP_SM, new SetPropertiesRule());
scxmlRules.add(XP_SM, new SetCurrentNamespacesRule());
//// Datamodel at document root i.e. <scxml> datamodel
addDatamodelRules(XP_SM + XPF_DM, scxmlRules, scxml, pr);
//// States
// Level one states
addStateRules(XP_SM_ST, scxmlRules, customActions, scxml, pr);
// Nested states
addStateRules(XPU_ST_ST, scxmlRules, customActions, scxml, pr);
// Orthogonal states
addStateRules(XPU_PAR_ST, scxmlRules, customActions, scxml, pr);
//// Parallels
// Level one parallels
addParallelRules(XP_SM_PAR, scxmlRules, customActions, scxml, pr);
// Parallel children of composite states
addParallelRules(XPU_ST_PAR, scxmlRules, customActions, scxml, pr);
//// Finals
// Level one finals
addFinalRules(XP_SM_FIN, scxmlRules, customActions, scxml, pr);
// Final children of composite states
addFinalRules(XPU_ST_FIN, scxmlRules, customActions, scxml, pr);
//// Ifs
addIfRules(XPU_IF, scxmlRules, pr, customActions);
//// Custom actions
addCustomActionRules(XPU_ONEN, scxmlRules, customActions);
addCustomActionRules(XPU_ONEX, scxmlRules, customActions);
addCustomActionRules(XPU_TR, scxmlRules, customActions);
addCustomActionRules(XPU_IF, scxmlRules, customActions);
addCustomActionRules(XPU_FIN, scxmlRules, customActions);
return scxmlRules;
}
/**
* Add Digester rules for all <state> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param scxml The parent SCXML document (or null)
* @param pr The PathResolver
*/
private static void addStateRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final SCXML scxml, final PathResolver pr) {
scxmlRules.add(xp, new ObjectCreateRule(State.class));
addStatePropertiesRules(xp, scxmlRules, customActions, pr, scxml);
addDatamodelRules(xp + XPF_DM, scxmlRules, scxml, pr);
addInvokeRules(xp + XPF_INV, scxmlRules, customActions, pr, scxml);
addInitialRules(xp + XPF_INI, scxmlRules, customActions, pr, scxml);
addHistoryRules(xp + XPF_HIST, scxmlRules, customActions, pr, scxml);
addTransitionRules(xp + XPF_TR, scxmlRules, "addTransition",
pr, customActions);
addHandlerRules(xp, scxmlRules, pr, customActions);
scxmlRules.add(xp, new UpdateModelRule(scxml));
scxmlRules.add(xp, new SetNextRule("addChild"));
}
/**
* Add Digester rules for all <parallel> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param pr The {@link PathResolver} for this document
* @param scxml The parent SCXML document (or null)
*/
private static void addParallelRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final SCXML scxml, final PathResolver pr) {
addSimpleRulesTuple(xp, scxmlRules, Parallel.class, null, null,
"addChild");
addDatamodelRules(xp + XPF_DM, scxmlRules, scxml, pr);
addTransitionRules(xp + XPF_TR, scxmlRules, "addTransition",
pr, customActions);
addHandlerRules(xp, scxmlRules, pr, customActions);
scxmlRules.add(xp, new UpdateModelRule(scxml));
}
/**
* Add Digester rules for all <final> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param scxml The parent SCXML document (or null)
* @param pr The {@link PathResolver} for this document
*/
private static void addFinalRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final SCXML scxml, final PathResolver pr) {
addSimpleRulesTuple(xp, scxmlRules, Final.class, null, null,
"addChild");
addHandlerRules(xp, scxmlRules, pr, customActions);
scxmlRules.add(xp, new UpdateModelRule(scxml));
}
/**
* Add Digester rules for all <state> element attributes.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param pr The PathResolver
* @param scxml The root document, if this one is src'ed in
*/
private static void addStatePropertiesRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final PathResolver pr, final SCXML scxml) {
scxmlRules.add(xp, new SetPropertiesRule(
new String[] {"id", "final", "initial"},
new String[] {"id", "final", "first"}));
scxmlRules.add(xp, new DigestSrcAttributeRule(scxml,
customActions, pr));
}
/**
* Add Digester rules for all <datamodel> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param pr The PathResolver
* @param scxml The parent SCXML document (or null)
*/
private static void addDatamodelRules(final String xp,
final ExtendedBaseRules scxmlRules, final SCXML scxml,
final PathResolver pr) {
scxmlRules.add(xp, new ObjectCreateRule(Datamodel.class));
scxmlRules.add(xp + XPF_DATA, new ObjectCreateRule(Data.class));
scxmlRules.add(xp + XPF_DATA, new SetPropertiesRule());
scxmlRules.add(xp + XPF_DATA, new SetCurrentNamespacesRule());
scxmlRules.add(xp + XPF_DATA, new SetNextRule("addData"));
try {
scxmlRules.add(xp + XPF_DATA, new ParseDataRule(pr));
} catch (ParserConfigurationException pce) {
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLParser.class);
log.error(ERR_PARSER_CFG_DATA, pce);
}
scxmlRules.add(xp, new SetNextRule("setDatamodel"));
}
/**
* Add Digester rules for all <invoke> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of {@link CustomAction}s this digester
* instance will process, can be null or empty
* @param pr The PathResolver
* @param scxml The parent SCXML document (or null)
*/
private static void addInvokeRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final PathResolver pr, final SCXML scxml) {
scxmlRules.add(xp, new ObjectCreateRule(Invoke.class));
scxmlRules.add(xp, new SetPropertiesRule());
scxmlRules.add(xp, new SetCurrentNamespacesRule());
scxmlRules.add(xp, new SetPathResolverRule(pr));
scxmlRules.add(xp + XPF_PRM, new ObjectCreateRule(Param.class));
scxmlRules.add(xp + XPF_PRM, new SetPropertiesRule());
scxmlRules.add(xp + XPF_PRM, new SetCurrentNamespacesRule());
scxmlRules.add(xp + XPF_PRM, new SetNextRule("addParam"));
scxmlRules.add(xp + XPF_FIN, new ObjectCreateRule(Finalize.class));
scxmlRules.add(xp + XPF_FIN, new UpdateFinalizeRule());
addActionRules(xp + XPF_FIN, scxmlRules, pr, customActions);
scxmlRules.add(xp + XPF_FIN, new SetNextRule("setFinalize"));
scxmlRules.add(xp, new SetNextRule("setInvoke"));
}
/**
* Add Digester rules for all <initial> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param pr The PathResolver
* @param scxml The parent SCXML document (or null)
*/
private static void addInitialRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final PathResolver pr, final SCXML scxml) {
scxmlRules.add(xp, new ObjectCreateRule(Initial.class));
addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr,
scxml);
scxmlRules.add(xp, new UpdateModelRule(scxml));
addTransitionRules(xp + XPF_TR, scxmlRules, "setTransition",
pr, customActions);
scxmlRules.add(xp, new SetNextRule("setInitial"));
}
/**
* Add Digester rules for all <history> elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param pr The PathResolver
* @param scxml The parent SCXML document (or null)
*/
private static void addHistoryRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions,
final PathResolver pr, final SCXML scxml) {
scxmlRules.add(xp, new ObjectCreateRule(History.class));
addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr,
scxml);
scxmlRules.add(xp, new UpdateModelRule(scxml));
scxmlRules.add(xp, new SetPropertiesRule(new String[] {"type"},
new String[] {"type"}));
addTransitionRules(xp + XPF_TR, scxmlRules, "setTransition",
pr, customActions);
scxmlRules.add(xp, new SetNextRule("addHistory"));
}
/**
* Add Digester rules for all pseudo state (initial, history) element
* attributes.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param customActions The list of custom actions this digester needs
* to be able to process
* @param pr The PathResolver
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -