if (initialStates.size() == 0) {
logAndThrowModelError(ERR_STATE_BAD_INIT,
new Object[] {getStateName(s)});
} else {
for (int i = 0; i < initialStates.size(); i++) {
TransitionTarget initialState = (TransitionTarget)
initialStates.get(i);
if (!SCXMLHelper.isDescendant(initialState, s)) {
logAndThrowModelError(ERR_STATE_BAD_INIT,
new Object[] {getStateName(s)});
}
}
}
}
List histories = s.getHistory();
Iterator histIter = histories.iterator();
while (histIter.hasNext()) {
if (s.isSimple()) {
logAndThrowModelError(ERR_HISTORY_SIMPLE_STATE,
new Object[] {getStateName(s)});
}
History h = (History) histIter.next();
Transition historyTransition = h.getTransition();
if (historyTransition == null) {
// try to assign initial as default
if (initialStates != null && initialStates.size() > 0) {
for (int i = 0; i < initialStates.size(); i++) {
if (initialStates.get(i) instanceof History) {
logAndThrowModelError(ERR_HISTORY_BAD_DEFAULT,
new Object[] {h.getId(), getStateName(s)});
}
}
historyTransition = new Transition();
historyTransition.getTargets().addAll(initialStates);
h.setTransition(historyTransition);
} else {
logAndThrowModelError(ERR_HISTORY_NO_DEFAULT,
new Object[] {h.getId(), getStateName(s)});
}
}
updateTransition(historyTransition, targets);
List historyStates = historyTransition.getTargets();
if (historyStates.size() == 0) {
logAndThrowModelError(ERR_STATE_NO_HIST,
new Object[] {getStateName(s)});
}
for (int i = 0; i < historyStates.size(); i++) {
TransitionTarget historyState = (TransitionTarget)
historyStates.get(i);
if (!h.isDeep()) {
if (!c.containsValue(historyState)) {
logAndThrowModelError(ERR_STATE_BAD_SHALLOW_HIST,
new Object[] {getStateName(s)});
}
} else {
if (!SCXMLHelper.isDescendant(historyState, s)) {
logAndThrowModelError(ERR_STATE_BAD_DEEP_HIST,
new Object[] {getStateName(s)});
}
}
}
}
List t = s.getTransitionsList();
for (int i = 0; i < t.size(); i++) {
Transition trn = (Transition) t.get(i);
updateTransition(trn, targets);
}
Parallel p = s.getParallel(); //TODO: Remove in v1.0
Invoke inv = s.getInvoke();
if ((inv != null && p != null)
|| (inv != null && !c.isEmpty())
|| (p != null && !c.isEmpty())) {
logAndThrowModelError(ERR_STATE_BAD_CONTENTS,
new Object[] {getStateName(s)});
}
if (p != null) {
updateParallel(p, targets);
} else if (inv != null) {
String ttype = inv.getTargettype();
if (ttype == null || ttype.trim().length() == 0) {
logAndThrowModelError(ERR_INVOKE_NO_TARGETTYPE,
new Object[] {getStateName(s)});
}
String src = inv.getSrc();
boolean noSrc = (src == null || src.trim().length() == 0);
String srcexpr = inv.getSrcexpr();
boolean noSrcexpr = (srcexpr == null
|| srcexpr.trim().length() == 0);
if (noSrc && noSrcexpr) {
logAndThrowModelError(ERR_INVOKE_NO_SRC,
new Object[] {getStateName(s)});
}
if (!noSrc && !noSrcexpr) {
logAndThrowModelError(ERR_INVOKE_AMBIGUOUS_SRC,
new Object[] {getStateName(s)});
}
} else {
Iterator j = c.keySet().iterator();
while (j.hasNext()) {
TransitionTarget tt = (TransitionTarget) c.get(j.next());
if (tt instanceof State) {
updateState((State) tt, targets);
} else if (tt instanceof Parallel) {
updateParallel((Parallel) tt, targets);
}