Source code: com/voytechs/jnetanalyzer/message/MessageListenerSupport.java
1 /*
2 * File: MessageListenerSupport.java
3 * Auth: Mark Bednarczyk
4 * Date: DATE
5 * Id: $Id: MessageListenerSupport.java,v 1.1.1.1 2003/09/22 16:32:06 voytechs Exp $
6 ********************************************
7 Copyright (C) 2003 Mark Bednarczyk
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ********************************************
23 * $Log: MessageListenerSupport.java,v $
24 * Revision 1.1.1.1 2003/09/22 16:32:06 voytechs
25 * Initial import.
26 *
27 */
28 package com.voytechs.jnetanalyzer.message;
29
30 import java.lang.*;
31 import java.util.*;
32
33 /**
34 * Handles the lists and dispatching of events to listeners. This class is a support class for Message based
35 * event handling. Events can be sent on behalf of a message or its individual segments. In addition standard
36 * listner interface methods for notification of new message or its segments are implemented.
37 */
38 public class MessageListenerSupport {
39
40 /* Internal attributes */
41 private static final boolean debug = false;
42
43 /**
44 * List of listeners.
45 */
46 private ArrayList listeners = new ArrayList();
47
48 /**
49 * Add listener.
50 * @param listener Message Listener to be added. Listner must implement the MessageListener interface.
51 */
52 public void addMessageListener(MessageListener listener) {
53 listeners.add(listener);
54 }
55
56
57 /**
58 * Remove listner.
59 * @param listener Message Listener to be removed.
60 */
61 public void removeMessageListener(MessageListener listener) {
62 listeners.remove(listener);
63 }
64
65
66
67
68 /**
69 * Notifies all listeners of msgNewMessage event.
70 * @param msg the newly created message to be dispatched.
71 */
72 public void fireNewMessage(Message msg) {
73
74 for(int i = 0; i < listeners.size(); i ++) {
75 MessageListener l = (MessageListener)listeners.get(i);
76
77 /**
78 * Dispatch the event.
79 */
80 l.msgNewMessage(msg);
81 }
82 }
83
84
85
86
87
88 /**
89 * Notifies all listeners of msgNewMessageSegment event. A new segment has been added.
90 * @param msg overall message.
91 * @param seg the newly created message segment to be dispatched.
92 */
93 public void fireNewMessageSegment(Message msg, MessageSegment seg) {
94
95 for(int i = 0; i < listeners.size(); i ++) {
96 MessageListener l = (MessageListener)listeners.get(i);
97
98 /**
99 * Dispatch the event.
100 */
101 l.msgNewMessageSegment(msg, seg);
102 }
103 }
104
105
106
107
108
109 /**
110 * Notifies all listeners of message specific event.
111 * @param msg overall message.
112 * @param event custom/generic event to be dispatched.
113 */
114 public void fireMessageEvent(Message msg, MessageEvent event) {
115
116 for(int i = 0; i < listeners.size(); i ++) {
117 MessageListener l = (MessageListener)listeners.get(i);
118
119 /**
120 * Dispatch the event.
121 */
122 l.msgMessageEvent(msg, event);
123 }
124 }
125
126
127
128
129 /**
130 * Notifies all listeners of message segment specific event.
131 * @param msg overall message.
132 * @param event custom/generic event to be dispatched.
133 */
134 public void fireMessageSegmentEvent(Message msg, MessageSegment seg, MessageEvent event) {
135
136 for(int i = 0; i < listeners.size(); i ++) {
137 MessageListener l = (MessageListener)listeners.get(i);
138
139 /**
140 * Dispatch the event.
141 */
142 l.msgMessageSegmentEvent(msg, seg, event);
143 }
144 }
145
146
147 /**
148 * Test function for MessageListenerSupport
149 * @param args command line arguments
150 */
151 public static void main(String [] args) {
152 }
153
154 } /* END OF: MessageListenerSupport */