if (nodeInstance instanceof DynamicNodeInstance) {
stream.writeShort(PersisterEnums.DYNAMIC_NODE_INSTANCE);
} else {
stream.writeShort(PersisterEnums.COMPOSITE_NODE_INSTANCE);
}
CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
List<Long> timerInstances =
((CompositeContextNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance == null) {
stream.writeInt(0);
} else {
Map<String, Object> variables = variableScopeInstance.getVariables();
List<String> keys = new ArrayList<String>(variables.keySet());
Collections.sort(keys,
new Comparator<String>() {
public int compare(String o1,
String o2) {
return o1.compareTo(o2);
}
});
stream.writeInt(keys.size());
for (String key : keys) {
stream.writeUTF(key);
stream.writeObject(variables.get(key));
}
}
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(compositeNodeInstance.getNodeInstances());
Collections.sort(nodeInstances,
new Comparator<NodeInstance>() {
public int compare(NodeInstance o1,
NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance subNodeInstance : nodeInstances) {
stream.writeShort(PersisterEnums.NODE_INSTANCE);
writeNodeInstance(context,
subNodeInstance);
}
stream.writeShort(PersisterEnums.END);
List<ContextInstance> exclusiveGroupInstances =
compositeNodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
if (exclusiveGroupInstances == null) {
stream.writeInt(0);
} else {
stream.writeInt(exclusiveGroupInstances.size());
for (ContextInstance contextInstance: exclusiveGroupInstances) {