HistoryParseListener.java 6.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 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.
 */

package org.activiti.engine.impl.history.handler;

16
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
17
import org.activiti.engine.impl.bpmn.parser.BpmnParseListener;
18
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
19
import org.activiti.engine.impl.pvm.delegate.ExecutionListener;
J
jbarrez 已提交
20
import org.activiti.engine.impl.pvm.delegate.TaskListener;
T
tombaeyens 已提交
21 22 23
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.process.ScopeImpl;
import org.activiti.engine.impl.pvm.process.TransitionImpl;
24
import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
25
import org.activiti.engine.impl.task.TaskDefinition;
26
import org.activiti.engine.impl.util.xml.Element;
27
import org.activiti.engine.impl.variable.VariableDeclaration;
28 29 30 31


/**
 * @author Tom Baeyens
32
 * @author Joram Barrez
33
 * @author Falko Menge
34 35
 */
public class HistoryParseListener implements BpmnParseListener {
36
  
37
  protected static final StartEventEndHandler START_EVENT_END_HANDLER = new StartEventEndHandler();
38

39
  protected static final ActivityInstanceEndHandler ACTIVITI_INSTANCE_END_LISTENER = new ActivityInstanceEndHandler();
40

41
  protected static final ActivityInstanceStartHandler ACTIVITY_INSTANCE_START_LISTENER = new ActivityInstanceStartHandler();
42

43
  protected static final UserTaskAssignmentHandler USER_TASK_ASSIGNMENT_HANDLER = new UserTaskAssignmentHandler();
44

45
  // The history level set in the Activiti configuration
46
  protected int historyLevel;
47 48
  
  public HistoryParseListener(int historyLevel) {
49
    this.historyLevel = historyLevel;
50 51
  }
  
52
  public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
53
    if (activityHistoryEnabled(processDefinition, historyLevel)) {
54 55
      processDefinition.addExecutionListener(ExecutionListener.EVENTNAME_END, new ProcessInstanceEndHandler());
    }
56 57
  }

58
  public void parseExclusiveGateway(Element exclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
59
    addActivityHandlers(activity);
60 61 62
  }

  public void parseCallActivity(Element callActivityElement, ScopeImpl scope, ActivityImpl activity) {
63
    addActivityHandlers(activity);
64 65 66
  }

  public void parseManualTask(Element manualTaskElement, ScopeImpl scope, ActivityImpl activity) {
67
    addActivityHandlers(activity);
68 69
  }

70
  public void parseScriptTask(Element scriptTaskElement, ScopeImpl scope, ActivityImpl activity) {
71
    addActivityHandlers(activity);
72 73 74
  }

  public void parseTask(Element taskElement, ScopeImpl scope, ActivityImpl activity) {
75
    addActivityHandlers(activity);
76 77 78
  }

  public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
79
    addActivityHandlers(activity);
80
    
81
    if (activityHistoryEnabled(scope, historyLevel)) {
82
      TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).getTaskDefinition();
83 84
      taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, USER_TASK_ASSIGNMENT_HANDLER);
    }
85 86 87
  }

  public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {
88
    addActivityHandlers(activity);
89
  }
90 91
  
  public void parseBusinessRuleTask(Element businessRuleTaskElement, ScopeImpl scope, ActivityImpl activity) {
92
    addActivityHandlers(activity);
93
  }
94 95

  public void parseSubProcess(Element subProcessElement, ScopeImpl scope, ActivityImpl activity) {
96
    addActivityHandlers(activity);
97 98
  }

99
  public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl activity) {
100
    if (fullHistoryEnabled(historyLevel)) {
101
      activity.addExecutionListener(ExecutionListener.EVENTNAME_END, START_EVENT_END_HANDLER);
102
    }
103
  }
104 105 106 107
  
  public void parseSendTask(Element sendTaskElement, ScopeImpl scope, ActivityImpl activity) {
    addActivityHandlers(activity);
  }
108 109 110 111 112 113

  public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
  }

  public void parseParallelGateway(Element parallelGwElement, ScopeImpl scope, ActivityImpl activity) {
  }
114 115 116

  public void parseBoundaryTimerEventDefinition(Element timerEventDefinition, boolean interrupting, ActivityImpl timerActivity) {
  }
117 118 119
  
  public void parseBoundaryErrorEventDefinition(Element errorEventDefinition, boolean interrupting, ActivityImpl activity, ActivityImpl nestedErrorEventActivity) {
  }
120 121 122 123 124 125

  public void parseProperty(Element propertyElement, VariableDeclaration variableDeclaration, ActivityImpl activity) {
  }

  public void parseSequenceFlow(Element sequenceFlowElement, ScopeImpl scopeElement, TransitionImpl transition) {
  }
126 127
  
  public void parseMultiInstanceLoopCharacteristics(Element activityElement, 
128
          Element multiInstanceLoopCharacteristicsElement, ActivityImpl activity) {
129 130 131
    // Remove any history parse listeners already attached: the Multi instance behavior will
    // call them for every instance that will be created

132
  }
133 134 135

  // helper methods ///////////////////////////////////////////////////////////
  
136
  protected void addActivityHandlers(ActivityImpl activity) {
137
    if (activityHistoryEnabled(activity, historyLevel)) {
138
      activity.addExecutionListener(ExecutionListener.EVENTNAME_START, ACTIVITY_INSTANCE_START_LISTENER, 0);
139
      activity.addExecutionListener(ExecutionListener.EVENTNAME_END, ACTIVITI_INSTANCE_END_LISTENER);
140 141 142
    }
  }
  
143 144
  public static boolean fullHistoryEnabled(int historyLevel) {
    return historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL;
145 146
  }
  
147
  public static boolean auditHistoryEnabled(ScopeImpl scopeElement, int historyLevel) {
148
    return historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT;
149
  }
150
  
151
  public static boolean activityHistoryEnabled(ScopeImpl scopeElement, int historyLevel) {
152
    return historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY;
153
  }
154

155
}