try {
externalSCXML = SCXMLReader.readInternal(configuration, new URL(location), null, null, null, null);
} catch (Exception e) {
MessageFormat msgFormat = new MessageFormat(ERR_STATE_SRC);
String errMsg = msgFormat.format(new Object[] {src});
throw new ModelException(errMsg + " : " + e.getMessage(), e);
}
// Pull in the parts of the external document as needed
if (fragment == null) {
// All targets pulled in since its not a src fragment
if (ts instanceof State) {
State s = (State) ts;
Initial ini = new Initial();
SimpleTransition t = new SimpleTransition();
t.setNext(externalSCXML.getInitial());
ini.setTransition(t);
s.setInitial(ini);
for (EnterableState child : externalSCXML.getChildren()) {
s.addChild(child);
}
s.setDatamodel(externalSCXML.getDatamodel());
} else if (ts instanceof Parallel) {
// TODO src attribute for <parallel>
}
} else {
// Need to pull in only descendent targets
Object source = externalSCXML.getTargets().get(fragment);
if (source == null) {
MessageFormat msgFormat = new MessageFormat(ERR_STATE_SRC_FRAGMENT);
String errMsg = msgFormat.format(new Object[] {src});
throw new ModelException(errMsg);
}
if (source instanceof State && ts instanceof State) {
State s = (State) ts;
State include = (State) source;
for (OnEntry onentry : include.getOnEntries()) {
s.addOnEntry(onentry);
}
for (OnExit onexit : include.getOnExits()) {
s.addOnExit(onexit);
}
s.setDatamodel(include.getDatamodel());
List<History> histories = include.getHistory();
for (History h : histories) {
s.addHistory(h);
configuration.parent.addTarget(h);
}
for (EnterableState child : include.getChildren()) {
s.addChild(child);
configuration.parent.addTarget(child);
readInExternalTargets(configuration.parent, child);
}
for (Invoke invoke : include.getInvokes()) {
s.addInvoke(invoke);
}
if (include.getInitial() != null) {
s.setInitial(include.getInitial());
}
List<Transition> transitions = include.getTransitionsList();
for (Transition t : transitions) {
s.addTransition(t);
}
} else if (ts instanceof Parallel && source instanceof Parallel) {
// TODO src attribute for <parallel>
} else {
MessageFormat msgFormat =
new MessageFormat(ERR_STATE_SRC_FRAGMENT_TARGET);
String errMsg = msgFormat.format(new Object[] {src});
throw new ModelException(errMsg);
}
}
}