//初始化流程变量,从父实例获得初始值
Map<String ,Object> processVars = ((TaskInstance) taskInstance).getAliveProcessInstance().getProcessInstanceVariables();
List<DataField> datafields = subWorkflowProcess.getDataFields();
for (int i = 0; datafields != null && i < datafields.size(); i++) {
DataField df = datafields.get(i);
//TODO wmj2003 疑问,这里的逻辑都不对吧? 直接 subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
//还需要判断什么类型啊?反正value是Object
if (df.getDataType().equals(DataField.STRING)) {
if (processVars.get(df.getName()) != null && (processVars.get(df.getName()) instanceof String)) {
subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
} else if (df.getInitialValue() != null) {
subProcessInstance.setProcessInstanceVariable(df.getName(), df.getInitialValue());
} else {
subProcessInstance.setProcessInstanceVariable(df.getName(), "");
}
} else if (df.getDataType().equals(DataField.INTEGER)) {
if (processVars.get(df.getName()) != null && (processVars.get(df.getName()) instanceof Integer)) {
subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
} else if (df.getInitialValue() != null) {
try {
Integer intValue = new Integer(df.getInitialValue());
subProcessInstance.setProcessInstanceVariable(df.getName(), intValue);
} catch (Exception e) {
}
} else {
subProcessInstance.setProcessInstanceVariable(df.getName(), new Integer(0));
}
} else if (df.getDataType().equals(DataField.FLOAT)) {
if (processVars.get(df.getName()) != null && (processVars.get(df.getName()) instanceof Float)) {
subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
} else if (df.getInitialValue() != null) {
Float floatValue = new Float(df.getInitialValue());
subProcessInstance.setProcessInstanceVariable(df.getName(), floatValue);
} else {
subProcessInstance.setProcessInstanceVariable(df.getName(), new Float(0));
}
} else if (df.getDataType().equals(DataField.BOOLEAN)) {
if (processVars.get(df.getName()) != null && (processVars.get(df.getName()) instanceof Boolean)) {
subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
} else if (df.getInitialValue() != null) {
Boolean booleanValue = new Boolean(df.getInitialValue());
subProcessInstance.setProcessInstanceVariable(df.getName(), booleanValue);
} else {
subProcessInstance.setProcessInstanceVariable(df.getName(), Boolean.FALSE);
}
} else if (df.getDataType().equals(DataField.DATETIME)) {
//TODO 需要完善一下 ( 父子流程数据传递——时间类型的数据还未做传递-不知道为什么?)
//wmj2003 20090925 补充上了
if (processVars.get(df.getName()) != null && (processVars.get(df.getName()) instanceof Date)) {
subProcessInstance.setProcessInstanceVariable(df.getName(), processVars.get(df.getName()));
} else if (df.getInitialValue() != null) {
try {
SimpleDateFormat dFormat = new SimpleDateFormat(df.getDataPattern());
Date dateTmp = dFormat.parse(df.getInitialValue());
subProcessInstance.setProcessInstanceVariable(df.getName(), dateTmp);
} catch (ParseException e) {
subProcessInstance.setProcessInstanceVariable(df.getName(), null);
e.printStackTrace();
}
} else {
subProcessInstance.setProcessInstanceVariable(df.getName(), null);
}
}
}
//TODO 应将下面这句删除!这里还需要吗?应该直接subProcessInstance.run()就可以了。
runtimeContext.getPersistenceService().saveOrUpdateProcessInstance(subProcessInstance);