/**
 * Copyright 1996-2014 FoxBPM ORG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @author kenshin
 */
package org.foxbpm.engine.impl.util;

import java.util.ArrayList;
import java.util.List;

import org.foxbpm.engine.impl.Context;
import org.foxbpm.engine.impl.entity.TaskEntity;
import org.foxbpm.engine.impl.task.TaskDefinition;
import org.foxbpm.engine.impl.task.filter.AbstractCommandFilter;
import org.foxbpm.engine.task.TaskCommand;

public class CoreUtil {

	public static List<TaskCommand> getTaskCommand(TaskEntity task, boolean isProcessTracking) {

		List<TaskCommand> taskCommands = new ArrayList<TaskCommand>();

		if (task != null) {

			for (TaskCommand taskCommand : task.getTaskDefinition().getTaskCommands()) {
				AbstractCommandFilter abstractCommandFilter = Context.getProcessEngineConfiguration().getAbstractCommandFilterMap()
						.get(taskCommand.getTaskCommandType());
				if (abstractCommandFilter != null) {
					abstractCommandFilter.setProcessTracking(isProcessTracking);
					abstractCommandFilter.setTaskCommandInst(taskCommand);
					if (abstractCommandFilter.accept(task)) {
						taskCommands.add(taskCommand);
					}
				} else {
					if (!isProcessTracking) {
						taskCommands.add(taskCommand);
					}

				}
			}
		}

		return taskCommands;
	}
	
	
	public static List<TaskCommand> getSubmitNodeTaskCommand(TaskDefinition taskDefinition) {

		List<TaskCommand> taskCommandInsts = taskDefinition.getTaskCommands();
		List<TaskCommand> taskCommandInstsNew = new ArrayList<TaskCommand>();
		for (TaskCommand taskCommandInst : taskCommandInsts) {
			AbstractCommandFilter abstractCommandFilter = Context.getProcessEngineConfiguration().getAbstractCommandFilterMap()
					.get(taskCommandInst.getTaskCommandType());
			if (abstractCommandFilter != null) {
				abstractCommandFilter.setProcessTracking(false);
				abstractCommandFilter.setTaskCommandInst(taskCommandInst);
				if (abstractCommandFilter.accept(null)) {
					taskCommandInstsNew.add(taskCommandInst);
				}
			} else {
				taskCommandInstsNew.add(taskCommandInst);
			}
		}
		
		
//		for (TaskCommandInst taskCommandInstObj : taskCommandInstsNew) {
//					taskCommandInstObj.clearParamMap();
//					taskCommandInstObj.execExpressionParam(null,null);
//				}
			
		
		//taskCommandInstsNew.get(0).getParamMap();

		return taskCommandInstsNew;
	}
}

@@ -708,16 +708,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0Aimport
@@ -1095,25 +1095,24 @@
 Tracking) %7B%0A
-%0A
 %09%09List%3CTaskC
@@ -1164,17 +1164,16 @@
 and%3E();%0A
-%0A
 %09%09if (ta
@@ -1186,16 +1186,157 @@
 null) %7B%0A
+%09%09%09Map%3CString, AbstractCommandFilter%3E abstractCommandFilterMap = Context%0A%09%09%09%09%09.getProcessEngineConfiguration().getAbstractCommandFilterMap();
 %0A%09%09%09for 
@@ -1462,52 +1462,9 @@
 r = 
-Context.getProcessEngineConfiguration().getA
+a
 bstr
@@ -1478,26 +1478,24 @@
 andFilterMap
-()
 %0A%09%09%09%09%09%09.get(
@@ -1918,19 +1918,16 @@
 nds;%0A%09%7D%0A
-%09%0A%09
 %0A%09public
@@ -2156,16 +2156,156 @@
 and%3E();%0A
+%09%09Map%3CString, AbstractCommandFilter%3E abstractCommandFilterMap = Context%0A%09%09%09%09.getProcessEngineConfiguration().getAbstractCommandFilterMap();%0A
 %09%09for (T
@@ -2406,52 +2406,9 @@
 r = 
-Context.getProcessEngineConfiguration().getA
+a
 bstr
@@ -2430,16 +2430,8 @@
 rMap
-()%0A%09%09%09%09%09
 .get
@@ -2796,18 +2796,14 @@
 %09%09%7D%0A
-%09%09
 %0A%09%09
-%0A
 //
-%09%09
+ 
 for 
@@ -2863,23 +2863,21 @@
 sNew) %7B%0A
-//%09%09%09%09%09
+%09%09// 
 taskComm
@@ -2908,15 +2908,13 @@
 ();%0A
-//%09%09%09%09%09
+%09%09// 
 task
@@ -2964,27 +2964,21 @@
 l);%0A
-//%09%09%09%09%7D%0A%09%09%09%0A%09%09
+%09%09// %7D%0A
 %0A%09%09//
+ 
 task

改善代码，避免循环内方法多次调用