01: package org.wings.session;
02:
03: import org.wings.script.ScriptListener;
04:
05: import java.util.List;
06: import java.util.LinkedList;
07:
08: public class ScriptManager {
09: private final List scriptListenerList = new LinkedList();
10:
11: public static ScriptManager getInstance() {
12: return SessionManager.getSession().getScriptManager();
13: }
14:
15: public final void addScriptListener(ScriptListener listener) {
16: if (scriptListenerList.contains(listener))
17: return;
18:
19: int placingPosition = -1;
20: for (int i = 0; i < scriptListenerList.size()
21: && placingPosition < 0; i++) {
22: ScriptListener existingListener = (ScriptListener) scriptListenerList
23: .get(i);
24: if (existingListener.getPriority() < listener.getPriority())
25: placingPosition = i;
26: }
27:
28: if (placingPosition >= 0)
29: scriptListenerList.add(placingPosition, listener);
30: else
31: scriptListenerList.add(listener);
32: }
33:
34: public final void addScriptListeners(ScriptListener[] listeners) {
35: for (int i = 0; i < listeners.length; ++i) {
36: addScriptListener(listeners[i]);
37: }
38: }
39:
40: public final void removeScriptListener(ScriptListener listener) {
41: scriptListenerList.remove(listener);
42: }
43:
44: public ScriptListener[] getScriptListeners() {
45: return (ScriptListener[]) scriptListenerList
46: .toArray(new ScriptListener[scriptListenerList.size()]);
47: }
48:
49: public void clearScriptListeners() {
50: scriptListenerList.clear();
51: }
52: }
|