📄 scxmldigester.java
字号:
private static void addHandlerRules(final String xp,
final ExtendedBaseRules scxmlRules, final PathResolver pr,
final List customActions) {
scxmlRules.add(xp + XPF_ONEN, new ObjectCreateRule(OnEntry.class));
addActionRules(xp + XPF_ONEN, scxmlRules, pr, customActions);
scxmlRules.add(xp + XPF_ONEN, new SetNextRule("setOnEntry"));
scxmlRules.add(xp + XPF_ONEX, new ObjectCreateRule(OnExit.class));
addActionRules(xp + XPF_ONEX, scxmlRules, pr, customActions);
scxmlRules.add(xp + XPF_ONEX, new SetNextRule("setOnExit"));
}
/**
* Add Digester rules for all actions ("executable" 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 {@link PathResolver} for this document
* @param customActions The list of custom actions this digester needs
* to be able to process
*/
private static void addActionRules(final String xp,
final ExtendedBaseRules scxmlRules, final PathResolver pr,
final List customActions) {
addActionRulesTuple(xp + XPF_ASN, scxmlRules, Assign.class);
scxmlRules.add(xp + XPF_ASN, new SetPathResolverRule(pr));
addActionRulesTuple(xp + XPF_VAR, scxmlRules, Var.class);
addActionRulesTuple(xp + XPF_LOG, scxmlRules, Log.class);
addSendRulesTuple(xp + XPF_SND, scxmlRules);
addActionRulesTuple(xp + XPF_CAN, scxmlRules, Cancel.class);
addActionRulesTuple(xp + XPF_EXT, scxmlRules, Exit.class);
//addCustomActionRules(xp, scxmlRules, customActions);
}
/**
* Add custom action rules, if any custom actions are provided.
*
* @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
*/
private static void addCustomActionRules(final String xp,
final ExtendedBaseRules scxmlRules, final List customActions) {
if (customActions == null || customActions.size() == 0) {
return;
}
for (int i = 0; i < customActions.size(); i++) {
Object item = customActions.get(i);
if (item == null || !(item instanceof CustomAction)) {
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLDigester.class);
log.warn(ERR_CUSTOM_ACTION_TYPE);
} else {
CustomAction ca = (CustomAction) item;
scxmlRules.setNamespaceURI(ca.getNamespaceURI());
String xpfLocalName = STR_SLASH + ca.getLocalName();
Class klass = ca.getActionClass();
if (SCXMLHelper.implementationOf(klass,
ExternalContent.class)) {
addCustomActionRulesTuple(xp + xpfLocalName, scxmlRules,
klass, true);
} else {
addCustomActionRulesTuple(xp + xpfLocalName, scxmlRules,
klass, false);
}
}
}
scxmlRules.setNamespaceURI(NAMESPACE_SCXML);
}
/**
* Add Digester rules that are specific to the <send> action
* element.
*
* @param xp The Digester style XPath expression of <send> element
* @param scxmlRules The rule set to be used for digestion
*/
private static void addSendRulesTuple(final String xp,
final ExtendedBaseRules scxmlRules) {
addActionRulesTuple(xp, scxmlRules, Send.class);
try {
scxmlRules.add(xp, new ParseExternalContentRule());
} catch (ParserConfigurationException pce) {
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLDigester.class);
log.error(ERR_PARSER_CFG_SEND, pce);
}
}
/**
* Add Digester rules for a simple custom action (no body content).
*
* @param xp The path to the custom action element
* @param scxmlRules The rule set to be used for digestion
* @param klass The <code>Action</code> class implementing the custom
* action.
* @param bodyContent Whether the custom rule has body content
* that should be parsed using
* <code>NodeCreateRule</code>
*/
private static void addCustomActionRulesTuple(final String xp,
final ExtendedBaseRules scxmlRules, final Class klass,
final boolean bodyContent) {
addActionRulesTuple(xp, scxmlRules, klass);
if (bodyContent) {
try {
scxmlRules.add(xp, new ParseExternalContentRule());
} catch (ParserConfigurationException pce) {
org.apache.commons.logging.Log log = LogFactory.
getLog(SCXMLDigester.class);
log.error(ERR_PARSER_CFG_CUSTOM, pce);
}
}
}
/**
* Add Digester rules for all <if> 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 {@link PathResolver} for this document
* @param customActions The list of custom actions this digester needs
* to be able to process
*/
private static void addIfRules(final String xp,
final ExtendedBaseRules scxmlRules, final PathResolver pr,
final List customActions) {
addActionRulesTuple(xp, scxmlRules, If.class);
addActionRules(xp, scxmlRules, pr, customActions);
addActionRulesTuple(xp + XPF_EIF, scxmlRules, ElseIf.class);
addActionRulesTuple(xp + XPF_ELS, scxmlRules, Else.class);
}
/**
* Add Digester rules that are common across all actions elements.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param klass The class in the Java object model to be instantiated
* in the ObjectCreateRule for this action
*/
private static void addActionRulesTuple(final String xp,
final ExtendedBaseRules scxmlRules, final Class klass) {
addSimpleRulesTuple(xp, scxmlRules, klass, null, null, "addAction");
scxmlRules.add(xp, new SetExecutableParentRule());
scxmlRules.add(xp, new SetCurrentNamespacesRule());
}
/**
* Add the run of the mill Digester rules for any element.
*
* @param xp The Digester style XPath expression of the parent
* XML element
* @param scxmlRules The rule set to be used for digestion
* @param klass The class in the Java object model to be instantiated
* in the ObjectCreateRule for this action
* @param args The attributes to be mapped into the object model
* @param props The properties that args get mapped to
* @param addMethod The method that the SetNextRule should call
*/
private static void addSimpleRulesTuple(final String xp,
final ExtendedBaseRules scxmlRules, final Class klass,
final String[] args, final String[] props,
final String addMethod) {
scxmlRules.add(xp, new ObjectCreateRule(klass));
if (args == null) {
scxmlRules.add(xp, new SetPropertiesRule());
} else {
scxmlRules.add(xp, new SetPropertiesRule(args, props));
}
scxmlRules.add(xp, new SetNextRule(addMethod));
}
/**
* Discourage instantiation since this is a utility class.
*/
private SCXMLDigester() {
super();
}
/**
* Custom digestion rule for establishing necessary associations of this
* TransitionTarget with the root SCXML object.
* These include: <br>
* 1) Updation of the SCXML object's global targets Map <br>
* 2) Obtaining a handle to the SCXML object's NotificationRegistry <br>
*
* @deprecated Will be removed in version 1.0
*/
public static class UpdateModelRule extends Rule {
/**
* The root SCXML object.
*/
private SCXML scxml;
/**
* Constructor.
* @param scxml The root SCXML object
*/
public UpdateModelRule(final SCXML scxml) {
super();
this.scxml = scxml;
}
/**
* @see Rule#end(String, String)
*/
public final void end(final String namespace, final String name) {
if (scxml == null) {
scxml = (SCXML) getDigester()
.peek(getDigester().getCount() - 1);
}
TransitionTarget tt = (TransitionTarget) getDigester().peek();
scxml.addTarget(tt);
}
}
/**
* Custom digestion rule for setting Executable parent of Action elements.
*
* @deprecated Will be removed in version 1.0
*/
public static class SetExecutableParentRule extends Rule {
/**
* Constructor.
*/
public SetExecutableParentRule() {
super();
}
/**
* @see Rule#end(String, String)
*/
public final void end(final String namespace, final String name) {
Action child = (Action) getDigester().peek();
for (int i = 1; i < getDigester().getCount() - 1; i++) {
Object ancestor = getDigester().peek(i);
if (ancestor instanceof Executable) {
child.setParent((Executable) ancestor);
return;
}
}
}
}
/**
* Custom digestion rule for parsing bodies of
* <code>ExternalContent</code> elements.
*
* @see ExternalContent
*
* @deprecated Will be removed in version 1.0
*/
public static class ParseExternalContentRule extends NodeCreateRule {
/**
* Constructor.
* @throws ParserConfigurationException A JAXP configuration error
*/
public ParseExternalContentRule()
throws ParserConfigurationException {
super();
}
/**
* @see Rule#end(String, String)
*/
public final void end(final String namespace, final String name) {
Element bodyElement = (Element) getDigester().pop();
NodeList childNodes = bodyElement.getChildNodes();
List externalNodes = ((ExternalContent) getDigester().
peek()).getExternalNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
externalNodes.add(childNodes.item(i));
}
}
}
/**
* Custom digestion rule for parsing bodies of <data> elements.
*
* @deprecated Will be removed in version 1.0
*/
public static class ParseDataRule extends NodeCreateRule {
/**
* The PathResolver used to resolve the src attribute to the
* SCXML document it points to.
* @see PathResolver
*/
private PathResolver pr;
/**
* The "src" attribute, retained to check if body content is legal.
*/
private String src;
/**
* The "expr" attribute, retained to check if body content is legal.
*/
private String expr;
/**
* The XML tree for this data, parse as a Node, obtained from
* either the "src" or the "expr" attributes.
*/
private Node attrNode;
/**
* Constructor.
*
* @param pr The <code>PathResolver</code>
* @throws ParserConfigurationException A JAXP configuration error
*/
public ParseDataRule(final PathResolver pr)
throws ParserConfigurationException {
super();
this.pr = pr;
}
/**
* @see Rule#begin(String, String, Attributes)
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -