private void mergeStates() {
if (flowModel.getStates() == null) {
return;
}
for (Iterator it = flowModel.getStates().iterator(); it.hasNext();) {
AbstractStateModel childState = (AbstractStateModel) it.next();
String parent = childState.getParent();
if (childState.getParent() != null) {
String flowId;
String stateId;
AbstractStateModel parentState = null;
int hashIndex = parent.indexOf("#");
if (hashIndex == -1) {
throw new FlowModelBuilderException("Invalid parent syntax '" + parent
+ "', should take form 'flowId#stateId'");
}
flowId = parent.substring(0, hashIndex).trim();
stateId = parent.substring(hashIndex + 1).trim();
try {
parentState = modelLocator.getFlowModel(flowId).getStateById(stateId);
if (parentState == null) {
throw new FlowModelBuilderException("Unable to find state '" + stateId + "' in flow '" + flowId
+ "'");
}
childState.merge(parentState);
} catch (NoSuchFlowModelException e) {
throw new FlowModelBuilderException("Unable to find flow '" + flowId + "' to inherit from", e);
} catch (ClassCastException e) {
throw new FlowModelBuilderException("Parent state type '" + parentState.getClass().getName()
+ "' cannot be merged with state type '" + childState.getClass().getName() + "'", e);
}
}
}