KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > messages > MessageHandler


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.messages;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 /**
25  *
26  * @author Matthew Large
27  * @version $Revision: 1.1 $
28  *
29  */

30 public class MessageHandler {
31
32     public static String JavaDoc TYPE_CONFIRM = "CONFIRM";
33     public static String JavaDoc TYPE_INFORMATION = "INFO";
34     public static String JavaDoc TYPE_ERROR = "ERROR";
35
36     private static MessageHandler m_instance = null;
37
38     private ArrayList JavaDoc m_listeners = new ArrayList JavaDoc();
39
40     /**
41      *
42      */

43     private MessageHandler() {
44         super();
45     }
46     
47     public static MessageHandler getInstance() {
48         if(m_instance==null) {
49             m_instance = new MessageHandler();
50         }
51         return m_instance;
52     }
53
54     public void addMessageListener(MessageListener listener) {
55         this.m_listeners.add(listener);
56     }
57     
58     public void removeMessageListener(MessageListener listener) {
59         this.m_listeners.remove(listener);
60     }
61     
62     public void fireMessageEvent(String JavaDoc sMessage, String JavaDoc sMessageType) {
63         Iterator JavaDoc itor = this.m_listeners.iterator();
64         MessageEvent me = new MessageEvent(sMessage, sMessageType);
65         while (itor.hasNext()) {
66             MessageListener listener = (MessageListener) itor.next();
67             listener.messageEvent(me);
68         }
69     }
70
71 }
72
Popular Tags