@Override
public void execute(DelegateExecution execution) throws Exception {
ProcessToolContext ptc = ProcessToolContext.Util.getThreadProcessToolContext();
ProcessInstanceDAO dao = ptc.getProcessInstanceDAO();
String processInstanceId = execution.getProcessInstanceId();
ProcessInstance pi = dao.getProcessInstanceByInternalId(processInstanceId);
String res;
String stepName = (String) this.stepName.getValue(execution);
Map params = new HashMap();
if (this.params != null) {
String xml = (String) this.params.getValue(execution);
if (xml != null) {
XStream xs = new XStream();
xs.alias("map", java.util.Map.class);
xs.registerConverter(new Converter() {
public boolean canConvert(Class clazz) {
return AbstractMap.class.isAssignableFrom(clazz);
}
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
AbstractMap<String, String> map = (AbstractMap<String, String>) value;
for (Map.Entry<String, String> entry : map.entrySet()) {
writer.startNode(entry.getKey().toString());
writer.setValue(entry.getValue().toString());
writer.endNode();
}
}
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
Map<String, String> map = new HashMap<String, String>();
while (reader.hasMoreChildren()) {
reader.moveDown();
map.put(reader.getNodeName(), reader.getValue());
reader.moveUp();
}
return map;
}
});
params = (Map) xs.fromXML(xml);
}
}
try {
ProcessToolProcessStep stepInstance = ptc.getRegistry().getStep(stepName);
if (stepInstance == null) {
throw new IllegalArgumentException("No step defined by name: " + stepName);
}
processAutowiredProperties(stepInstance, params);
res = stepInstance.invoke(prepareStep(pi, execution), params);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (ProcessInstanceAttribute pia : pi.getProcessAttributes()) {
if (pia instanceof BpmVariable) {
BpmVariable bpmVar = (BpmVariable) pia;
if (hasText(bpmVar.getBpmVariableName())) {
execution.setVariable(bpmVar.getBpmVariableName(), bpmVar.getBpmVariableValue());
}