📄 modelupdater.java
字号:
}
Iterator j = p.getTransitionsList().iterator();
while (j.hasNext()) {
updateTransition((Transition) j.next(), targets);
}
}
/**
* Update this Transition object (part of post-digestion processing).
*
* @param t The Transition object
* @param targets The global Map of all transition targets
* @throws ModelException If the object model is flawed
*/
private static void updateTransition(final Transition t,
final Map targets) throws ModelException {
String next = t.getNext();
if (next == null) { // stay transition
return;
}
List tts = t.getTargets();
if (tts.size() == 0) {
// 'next' is a space separated list of transition target IDs
StringTokenizer ids = new StringTokenizer(next);
while (ids.hasMoreTokens()) {
String id = ids.nextToken();
TransitionTarget tt = (TransitionTarget) targets.get(id);
if (tt == null) {
logAndThrowModelError(ERR_TARGET_NOT_FOUND, new Object[] {
id });
}
tts.add(tt);
}
if (tts.size() > 1) {
boolean legal = verifyTransitionTargets(tts);
if (!legal) {
logAndThrowModelError(ERR_ILLEGAL_TARGETS, new Object[] {
next });
}
}
}
t.getPaths(); // init paths
}
/**
* Log an error discovered in post-digestion processing.
*
* @param errType The type of error
* @param msgArgs The arguments for formatting the error message
* @throws ModelException The model error, always thrown.
*/
private static void logAndThrowModelError(final String errType,
final Object[] msgArgs) throws ModelException {
MessageFormat msgFormat = new MessageFormat(errType);
String errMsg = msgFormat.format(msgArgs);
org.apache.commons.logging.Log log = LogFactory.
getLog(ModelUpdater.class);
log.error(errMsg);
throw new ModelException(errMsg);
}
/**
* Get state identifier for error message. This method is only
* called to produce an appropriate log message in some error
* conditions.
*
* @param state The <code>State</code> object
* @return The state identifier for the error message
*/
private static String getStateName(final State state) {
String badState = "anonymous state";
if (!SCXMLHelper.isStringEmpty(state.getId())) {
badState = "state with ID \"" + state.getId() + "\"";
}
return badState;
}
/**
* If a transition has multiple targets, then they satisfy the following
* criteria.
* <ul>
* <li>They must belong to the regions of the same parallel</li>
* <li>All regions must be represented with exactly one target</li>
* </ul>
*
* @param tts The transition targets
* @return Whether this is a legal configuration
*/
private static boolean verifyTransitionTargets(final List tts) {
if (tts.size() <= 1) { // No contention
return true;
}
TransitionTarget lca = SCXMLHelper.getLCA((TransitionTarget)
tts.get(0), (TransitionTarget) tts.get(1));
if (lca == null || !(lca instanceof Parallel)) {
return false; // Must have a Parallel LCA
}
Parallel p = (Parallel) lca;
Set regions = new HashSet();
for (int i = 0; i < tts.size(); i++) {
TransitionTarget tt = (TransitionTarget) tts.get(i);
while (tt.getParent() != p) {
tt = tt.getParent();
}
if (!regions.add(tt)) {
return false; // One per region
}
}
if (regions.size() != p.getChildren().size()) {
return false; // Must represent all regions
}
return true;
}
/**
* Discourage instantiation since this is a utility class.
*/
private ModelUpdater() {
super();
}
//// Error messages
/**
* Error message when SCXML document specifies an illegal initial state.
*/
private static final String ERR_SCXML_NO_INIT = "No SCXML child state "
+ "with ID \"{0}\" found; illegal initialstate for SCXML document";
/**
* Error message when a state element specifies an initial state which
* cannot be found.
*/
private static final String ERR_STATE_NO_INIT = "No initial element "
+ "available for {0}";
/**
* Error message when a state element specifies an initial state which
* is not a direct descendent.
*/
private static final String ERR_STATE_BAD_INIT = "Initial state "
+ "null or not a descendant of {0}";
/**
* Error message when a state element contains anything other than
* one <parallel>, one <invoke> or any number of
* <state> children.
*/
private static final String ERR_STATE_BAD_CONTENTS = "{0} should "
+ "contain either one <parallel>, one <invoke> or any number of "
+ "<state> children.";
/**
* Error message when a referenced history state cannot be found.
*/
private static final String ERR_STATE_NO_HIST = "Referenced history state"
+ " null for {0}";
/**
* Error message when a shallow history state is not a child state.
*/
private static final String ERR_STATE_BAD_SHALLOW_HIST = "History state"
+ " for shallow history is not child for {0}";
/**
* Error message when a deep history state is not a descendent state.
*/
private static final String ERR_STATE_BAD_DEEP_HIST = "History state"
+ " for deep history is not descendant for {0}";
/**
* Transition target is not a legal IDREF (not found).
*/
private static final String ERR_TARGET_NOT_FOUND =
"Transition target with ID \"{0}\" not found";
/**
* Transition targets do not form a legal configuration.
*/
private static final String ERR_ILLEGAL_TARGETS =
"Transition targets \"{0}\" do not satisfy the requirements for"
+ " target regions belonging to a <parallel>";
/**
* Simple states should not contain a history.
*/
private static final String ERR_HISTORY_SIMPLE_STATE =
"Simple {0} contains history elements";
/**
* History does not specify a default transition target.
*/
private static final String ERR_HISTORY_NO_DEFAULT =
"No default target specified for history with ID \"{0}\""
+ " belonging to {1}";
/**
* History specifies a bad default transition target.
*/
private static final String ERR_HISTORY_BAD_DEFAULT =
"Default target specified for history with ID \"{0}\""
+ " belonging to \"{1}\" is also a history";
/**
* Error message when an <invoke> does not specify a "targettype"
* attribute.
*/
private static final String ERR_INVOKE_NO_TARGETTYPE = "{0} contains "
+ "<invoke> with no \"targettype\" attribute specified.";
/**
* Error message when an <invoke> does not specify a "src"
* or a "srcexpr" attribute.
*/
private static final String ERR_INVOKE_NO_SRC = "{0} contains "
+ "<invoke> without a \"src\" or \"srcexpr\" attribute specified.";
/**
* Error message when an <invoke> specifies both "src" and "srcexpr"
* attributes.
*/
private static final String ERR_INVOKE_AMBIGUOUS_SRC = "{0} contains "
+ "<invoke> with both \"src\" and \"srcexpr\" attributes specified,"
+ " must specify either one, but not both.";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -