KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > notification > Message


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.notification;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Properties JavaDoc;
26
27
28 /**
29  * Encapsulate a single message that is delivered by the {@link Notifier}
30  * to one or more {@link MessageSink} implementations.
31  * <p>
32  * A message must have a least one {@link Recipient}.
33  * <p>
34  * A message may be marked as <i>Urgent</i> in which case it is placed
35  * at the top of the queue.
36  *
37  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
38  */

39 public class Message {
40     
41     // Private instance variables
42

43     private String JavaDoc subject;
44     private String JavaDoc content;
45     private List JavaDoc<Recipient> recipients;
46     private boolean urgent;
47     private long id;
48     private String JavaDoc sinkName;
49     private Properties JavaDoc parameters;
50     private String JavaDoc lastMessage;
51
52     /**
53      * Constructor.
54      *
55      * @param subject subject
56      * @param content content
57      * @param urgent urgent
58      */

59     public Message(String JavaDoc subject, String JavaDoc content, boolean urgent) {
60         this.subject = subject;
61         this.content = content;
62         this.urgent = urgent;
63         recipients = new ArrayList JavaDoc<Recipient>();
64         parameters = new Properties JavaDoc();
65         lastMessage = "";
66     }
67
68     /**
69      * Constructor.
70      *
71      * @param subject subject
72      * @param content content
73      * @param urgent urgent
74      * @param recipient recipient
75      */

76     public Message(String JavaDoc subject, String JavaDoc content, boolean urgent, Recipient recipient) {
77         this(subject, content, urgent);
78         recipients.add(recipient);
79     }
80
81     /**
82      * @return Returns the id.
83      */

84     public long getId() {
85         return id;
86     }
87
88     /**
89      * @param id The id to set.
90      */

91     public void setId(long id) {
92         this.id = id;
93     }
94     
95     /**
96      * Set a parameter. It will be up to the {@link com.sslexplorer.notification.MessageSink}
97      * to understand these parameters and deal with them accordingly.
98      *
99      * @param key parameter key
100      * @param value parameter value
101      */

102     public void setParameter(String JavaDoc key, String JavaDoc value) {
103         parameters.setProperty(key, value);
104     }
105     
106     /**
107      * Get a parameter. It will be up to the {@link com.sslexplorer.notification.MessageSink}
108      * to understand these parameters and deal with them accordingly.
109      *
110      * @param key parameter key
111      * @return value parameter value or <code>null</code> if no such parameter exists
112      */

113     public String JavaDoc getParameter(String JavaDoc key) {
114         return parameters.getProperty(key);
115     }
116     
117     /**
118      * Get a parameter. It will be up to the {@link com.sslexplorer.notification.MessageSink}
119      * to understand these parameters and deal with them accordingly.
120      *
121      * @param key parameter key
122      * @param defaultValue default value if no parameter exists
123      * @return value parameter value or <code>null</code> if no such parameter exists
124      */

125     public String JavaDoc getParameter(String JavaDoc key, String JavaDoc defaultValue) {
126         return parameters.getProperty(key, defaultValue);
127     }
128     
129     /**
130      * Get an {@link Iterator} of parameter names
131      *
132      * @return parameter names
133      */

134     public Iterator JavaDoc getParameterNames() {
135         return parameters.keySet().iterator();
136     }
137
138     /**
139      * Get the content of this message.
140      *
141      * @return content
142      */

143     public String JavaDoc getContent() {
144         return content;
145     }
146
147     /**
148      * Set the content of this message.
149      *
150      * @param content content of message
151      */

152     public void setContent(String JavaDoc content) {
153         this.content = content;
154     }
155
156     /**
157      * Get the list of recipients this message should be sent to
158      *
159      * @return recipients
160      */

161     public List JavaDoc<Recipient> getRecipients() {
162         return recipients;
163     }
164
165     /**
166      * Set the list of recipients for this messages.
167      *
168      * @param recipients recipients
169      */

170     public void setRecipients(List JavaDoc<Recipient> recipients) {
171         this.recipients = recipients;
172     }
173
174     /**
175      * Get the subject for this message.
176      *
177      * @return subject
178      */

179     public String JavaDoc getSubject() {
180         return subject;
181     }
182
183     /**
184      * Set the subject for this message.
185      *
186      * @param subject subject
187      */

188     public void setSubject(String JavaDoc subject) {
189         this.subject = subject;
190     }
191
192     /**
193      * Get if this message is urgent. If so it will be placed at the
194      * top of the message queue.
195      *
196      * @return urgent
197      */

198     public boolean isUrgent() {
199         return urgent;
200     }
201
202     /**
203      * Set if this message is urgent. If so it will be placed at the
204      * top of the message queue.
205      *
206      * @param urgent urgent
207      */

208     public void setUrgent(boolean urgent) {
209         this.urgent = urgent;
210     }
211     
212     /**
213      * Get the name of the sink this message should be delivered to.
214      *
215      * @return sink name
216      */

217     public String JavaDoc getSinkName() {
218         return sinkName;
219     }
220
221     /**
222      * Get the any status text that may have been generated the last
223      * time this message was sent.
224      *
225      * @return last status message
226      */

227     public String JavaDoc getLastMessage() {
228         return lastMessage;
229     }
230
231
232     /**
233      * Set the any status text that may have been generated the last
234      * time this message was sent.
235      *
236      * @param lastMessage last status message
237      */

238     public void setLastMessage(String JavaDoc lastMessage) {
239         this.lastMessage = lastMessage;
240     }
241
242     
243     protected void setSinkName(String JavaDoc sinkName) {
244         this.sinkName = sinkName;
245     }
246 }
247
Popular Tags