use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class ProcessInstanceImpl method getContextInstance.
public ContextInstance getContextInstance(String contextId) {
ContextInstance contextInstance = this.contextInstances.get(contextId);
if (contextInstance != null) {
return contextInstance;
}
Context context = ((ContextContainer) getProcess()).getDefaultContext(contextId);
if (context != null) {
contextInstance = getContextInstance(context);
return contextInstance;
}
return null;
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class ProcessInstanceImpl method getContextInstance.
public ContextInstance getContextInstance(final 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, this);
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 WorkItemNodeInstance 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 WorkflowProcessInstanceImpl method getVariables.
public Map<String, Object> getVariables() {
// be null and the associated working memory is no longer accessible)
if (getKnowledgeRuntime() == null) {
List<ContextInstance> variableScopeInstances = getContextInstances(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstances == null) {
return null;
}
Map<String, Object> result = new HashMap<String, Object>();
for (ContextInstance contextInstance : variableScopeInstances) {
Map<String, Object> variables = ((VariableScopeInstance) contextInstance).getVariables();
result.putAll(variables);
}
return result;
}
// else retrieve the variable scope
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance == null) {
return null;
}
return variableScopeInstance.getVariables();
}
use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method writeProcessInstance.
// Output methods
public Object writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
ObjectOutputStream stream = context.stream;
stream.writeLong(workFlow.getId());
stream.writeUTF(workFlow.getProcessId());
stream.writeInt(workFlow.getState());
stream.writeLong(workFlow.getNodeInstanceCounter());
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContextInstance != null) {
Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
stream.writeInt(swimlaneActors.size());
for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
stream.writeUTF(entry.getKey());
stream.writeUTF(entry.getValue());
}
} else {
stream.writeInt(0);
}
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
public int compare(NodeInstance o1, NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance nodeInstance : nodeInstances) {
stream.writeShort(PersisterEnums.NODE_INSTANCE);
writeNodeInstance(context, nodeInstance);
}
stream.writeShort(PersisterEnums.END);
List<ContextInstance> exclusiveGroupInstances = workFlow.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 nodeInstance : groupNodeInstances) {
stream.writeLong(nodeInstance.getId());
}
}
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance(VariableScope.VARIABLE_SCOPE);
Map<String, Object> variables = variableScopeInstance.getVariables();
List<String> keys = new ArrayList<String>(variables.keySet());
Collection<Object> values = variables.values();
Collections.sort(keys, new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
// Process Variables
// - Number of non null Variables = nonnullvariables.size()
// For Each Variable
// - Variable Key
// - Marshalling Strategy Index
// - Marshalled Object
Collection<Object> notNullValues = new ArrayList<Object>();
for (Object value : values) {
if (value != null) {
notNullValues.add(value);
}
}
stream.writeInt(notNullValues.size());
for (String key : keys) {
Object object = variables.get(key);
if (object != null) {
stream.writeUTF(key);
// New marshalling algorithm when using strategies
int useNewMarshallingStrategyAlgorithm = -2;
stream.writeInt(useNewMarshallingStrategyAlgorithm);
// Choose first strategy that accepts the object (what was always done)
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(object);
stream.writeUTF(strategy.getClass().getName());
strategy.write(stream, object);
}
}
return null;
}
Aggregations