use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method writeNodeInstanceContent.
protected void writeNodeInstanceContent(ObjectOutputStream stream, NodeInstance nodeInstance, MarshallerWriteContext context) throws IOException {
if (nodeInstance instanceof RuleSetNodeInstance) {
stream.writeShort(PersisterEnums.RULE_SET_NODE_INSTANCE);
List<Long> timerInstances = ((RuleSetNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof HumanTaskNodeInstance) {
stream.writeShort(PersisterEnums.HUMAN_TASK_NODE_INSTANCE);
stream.writeLong(((HumanTaskNodeInstance) nodeInstance).getWorkItemId());
List<Long> timerInstances = ((HumanTaskNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof WorkItemNodeInstance) {
stream.writeShort(PersisterEnums.WORK_ITEM_NODE_INSTANCE);
stream.writeLong(((WorkItemNodeInstance) nodeInstance).getWorkItemId());
List<Long> timerInstances = ((WorkItemNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof SubProcessNodeInstance) {
stream.writeShort(PersisterEnums.SUB_PROCESS_NODE_INSTANCE);
stream.writeLong(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
List<Long> timerInstances = ((SubProcessNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof MilestoneNodeInstance) {
stream.writeShort(PersisterEnums.MILESTONE_NODE_INSTANCE);
List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof EventNodeInstance) {
stream.writeShort(PersisterEnums.EVENT_NODE_INSTANCE);
} else if (nodeInstance instanceof TimerNodeInstance) {
stream.writeShort(PersisterEnums.TIMER_NODE_INSTANCE);
stream.writeLong(((TimerNodeInstance) nodeInstance).getTimerId());
} else if (nodeInstance instanceof JoinInstance) {
stream.writeShort(PersisterEnums.JOIN_NODE_INSTANCE);
Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
stream.writeInt(triggers.size());
List<Long> keys = new ArrayList<Long>(triggers.keySet());
Collections.sort(keys, new Comparator<Long>() {
public int compare(Long o1, Long o2) {
return o1.compareTo(o2);
}
});
for (Long key : keys) {
stream.writeLong(key);
stream.writeInt(triggers.get(key));
}
} else if (nodeInstance instanceof StateNodeInstance) {
stream.writeShort(PersisterEnums.STATE_NODE_INSTANCE);
List<Long> timerInstances = ((StateNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
stream.writeInt(timerInstances.size());
for (Long id : timerInstances) {
stream.writeLong(id);
}
} else {
stream.writeInt(0);
}
} else if (nodeInstance instanceof CompositeContextNodeInstance) {
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) {
ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
stream.writeInt(groupNodeInstances.size());
for (NodeInstance groupNodeInstance : groupNodeInstances) {
stream.writeLong(groupNodeInstance.getId());
}
}
}
} else if (nodeInstance instanceof ForEachNodeInstance) {
stream.writeShort(PersisterEnums.FOR_EACH_NODE_INSTANCE);
ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances());
Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
public int compare(NodeInstance o1, NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance subNodeInstance : nodeInstances) {
if (subNodeInstance instanceof CompositeContextNodeInstance) {
stream.writeShort(PersisterEnums.NODE_INSTANCE);
writeNodeInstance(context, subNodeInstance);
}
}
stream.writeShort(PersisterEnums.END);
} else {
throw new IllegalArgumentException("Unknown node instance type: " + nodeInstance);
}
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class ForEachNodeInstance method getContextInstance.
@Override
public ContextInstance getContextInstance(String contextId) {
ContextInstance contextInstance = super.getContextInstance(contextId);
if (contextInstance == null) {
contextInstance = resolveContextInstance(contextId, TEMP_OUTPUT_VAR);
setContextInstance(contextId, contextInstance);
}
return contextInstance;
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class RuleSetNodeInstance method getContextInstance.
@Override
public ContextInstance getContextInstance(Context context) {
ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
if (conf == null) {
throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
}
ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
if (contextInstance == null) {
throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
}
return contextInstance;
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class SubProcessNodeInstance method getContextInstance.
@Override
public ContextInstance getContextInstance(Context context) {
ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
if (conf == null) {
throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
}
ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
if (contextInstance == null) {
throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
}
return contextInstance;
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class CompositeContextNodeInstance method getContextInstance.
public ContextInstance getContextInstance(String contextId) {
ContextInstance contextInstance = this.contextInstances.get(contextId);
if (contextInstance != null) {
return contextInstance;
}
Context context = getCompositeContextNode().getDefaultContext(contextId);
if (context != null) {
contextInstance = getContextInstance(context);
return contextInstance;
}
return null;
}
Aggregations