AbstractEventAtomicOperation.java 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 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.activiti5.engine.impl.pvm.runtime;

import java.util.List;

18
import org.activiti.engine.delegate.ExecutionListener;
19 20 21
import org.activiti5.engine.impl.pvm.PvmException;
import org.activiti5.engine.impl.pvm.process.ScopeImpl;

22

23 24 25 26
/**
 * @author Tom Baeyens
 */
public abstract class AbstractEventAtomicOperation implements AtomicOperation {
27
  
28 29 30
  public boolean isAsync(InterpretableExecution execution) {
    return false;
  }
31

32 33 34 35
  public void execute(InterpretableExecution execution) {
    ScopeImpl scope = getScope(execution);
    List<ExecutionListener> exectionListeners = scope.getExecutionListeners(getEventName());
    int executionListenerIndex = execution.getExecutionListenerIndex();
36 37
    
    if (exectionListeners.size()>executionListenerIndex) {
38 39 40 41 42 43 44 45
      execution.setEventName(getEventName());
      execution.setEventSource(scope);
      ExecutionListener listener = exectionListeners.get(executionListenerIndex);
      try {
        listener.notify(execution);
      } catch (RuntimeException e) {
        throw e;
      } catch (Exception e) {
46
        throw new PvmException("couldn't execute event listener : "+e.getMessage(), e);
47
      }
48
      execution.setExecutionListenerIndex(executionListenerIndex+1);
49
      execution.performOperation(this);
T
Tijs Rademakers 已提交
50

51 52 53 54
    } else {
      execution.setExecutionListenerIndex(0);
      execution.setEventName(null);
      execution.setEventSource(null);
55
      
56
      eventNotificationsCompleted(execution);
T
Tijs Rademakers 已提交
57
    }
58
  }
T
Tijs Rademakers 已提交
59

60 61 62
  protected abstract ScopeImpl getScope(InterpretableExecution execution);
  protected abstract String getEventName();
  protected abstract void eventNotificationsCompleted(InterpretableExecution execution);
63
}