}
}
private void saveGraph(ModelGraph graph, Element parentElem, Document document)
throws FileNotFoundException, ParserConfigurationException {
ModelNode node = graph.getModel();
Element workflowElem = document.createElement(node.getExecutionType());
parentElem.appendChild(workflowElem);
if (node.isRef()) {
workflowElem.setAttribute("id-ref", node.getModelId());
if (node.getAlias() != null) {
workflowElem.setAttribute("alias", node.getAlias());
}
saveConfiguration(node, workflowElem, document);
} else {
workflowElem.setAttribute("id", node.getModelId());
workflowElem.setAttribute("name", node.getModelName());
if (node.getInstanceClass() != null) {
workflowElem.setAttribute("class", node.getInstanceClass());
}
saveConfiguration(node, workflowElem, document);
// handle preconditions
if (graph.getPreConditions() != null) {
Element preConditions = document.createElement("conditions");
workflowElem.appendChild(preConditions);
preConditions.setAttribute("type", "pre");
preConditions.setAttribute("execution", graph.getPreConditions()
.getModel().getExecutionType());
preConditions.setAttribute("timeout", String.valueOf(graph.getModel().getTimeout()));
preConditions.setAttribute("optional", String.valueOf(graph.getModel().isOptional()));
for (ModelGraph preCondition : graph.getPreConditions().getChildren()) {
saveGraph(preCondition, preConditions, document);
}
}
// handle subprocessors
for (ModelGraph subProcessor : graph.getChildren()) {
saveGraph(subProcessor, workflowElem, document);
}
// handle postconditions
if (graph.getPostConditions() != null) {
Element postConditions = document.createElement("conditions");
workflowElem.appendChild(postConditions);
postConditions.setAttribute("type", "post");
postConditions.setAttribute("execution", graph.getPostConditions()
.getModel().getExecutionType());
postConditions.setAttribute("timeout", String.valueOf(graph.getModel().getTimeout()));
postConditions.setAttribute("optional", String.valueOf(graph.getModel().isOptional()));
for (ModelGraph postCondition : graph.getPostConditions().getChildren()) {
saveGraph(postCondition, postConditions, document);
}
}
}
if (!node.getExcusedSubProcessorIds().isEmpty()) {
workflowElem.setAttribute("excused",
StringUtils.join(node.getExcusedSubProcessorIds(), ","));
}
if (node.isEntryPoint()) {
workflowElem.setAttribute("entryPoint", "true");
}
}