ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.jbpm.pvm.internal.util;
 
import java.util.ArrayList;
import java.util.List;
 
import org.jbpm.api.JbpmException;
 
/** default implementation of the {@link Observable} interface.
 * 
 * @author Tom Baeyens
 */
public class DefaultObservable implements Observable {
 
  protected List<Listener> listeners = null;
  
  public void addListener(Listener listener) {
    if (listener==null) {
      throw new JbpmException("listener is null");
    }
    if (listeners==null) {
      listeners = new ArrayList<Listener>();
    }
    listeners.add(listener);
  }
 
  public void removeListener(Listener listener) {
    if (listener==null) {
      throw new JbpmException("listener is null");
    }
    if (listeners!=null) {
      listeners.remove(listener);
    }
  }
 
  public Listener addListener(Listener listener, String eventName) {
    if (eventName==null) {
      throw new JbpmException("eventName is null");
    }
 
    List<String> eventNames = new ArrayList<String>();
    eventNames.add(eventName);
 
    return addListener(listener, eventNames);
  }
 
 
  public Listener addListener(Listener listener, List<String> eventNames) {
    if (listener==null) {
      throw new JbpmException("listener is null");
    }
    if (eventNames==null) {
      throw new JbpmException("eventNames is null");
    }
    FilterListener filterListener = new FilterListener(listener, eventNames);
    addListener(filterListener);
    return filterListener;
  }
 
  public void fire(String eventName) {
    fire(eventName, null);
  }
 
  public void fire(String eventName, Object info) {
    if (listeners!=null) {
      for (Listener listener: listeners)  {
        listener.event(this, eventName, info);
      }
    }
  }
  
  public List<Listener> getListeners() {
    return listeners;
  }
}