View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2006 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  package com.mindtree.techworks.insight.reporting.jobs.message;
25  
26  import java.util.ArrayList;
27  import java.util.Iterator;
28  import java.util.List;
29  
30  import com.mindtree.techworks.insight.filter.criteria.FilterCriteria;
31  
32  /**
33   * A simple implementation of <code>JobMessage</code>. All <code>Job</code>s 
34   * support this message type. An instance of this class would contain just a 
35   * list of <code>String</code> messages.
36   * 
37   * @see com.mindtree.techworks.insight.reporting.jobs.message.JobMessage
38   * @see com.mindtree.techworks.insight.reporting.jobs.Job
39   * 
40   * @author <a href="mailto:bindul_bhowmik@mindtree.com">Bindul Bhowmik</a>
41   * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
42   * @since Insight 1.5
43   */
44  public class DefaultJobMessage implements JobMessage {
45  
46  	// -------------------------------------------------------------------------
47  	// Class fields
48  	// -------------------------------------------------------------------------
49  
50  	/**
51  	 * Serial Version UID for the serialized form of the class.
52  	 */
53  	private static final long serialVersionUID = 6336374138580664199L;
54  
55  	// -------------------------------------------------------------------------
56  	// Instance fields
57  	// -------------------------------------------------------------------------
58  
59  	/**
60  	 * The action that caused the message
61  	 */
62  	private int _action;
63  
64  	/**
65  	 * The mode insight was running in.
66  	 */
67  	private short _mode;
68  
69  	/**
70  	 * The criteria in use during message creation.
71  	 */
72  	private FilterCriteria _criteria;
73  
74  	/**
75  	 * The messages in this object.
76  	 */
77  	private List _messages;
78  
79  	// -------------------------------------------------------------------------
80  	// Constructors
81  	// -------------------------------------------------------------------------
82  
83  	/**
84  	 * Creates a new instance of <code>DefaultJobMessage</code>. Defaults the
85  	 * action to <code>ACTION_FILTER</code> and the mode to
86  	 * <code>MODE_INTERACTIVE</code>.
87  	 */
88  	public DefaultJobMessage() {
89  		this(JobMessage.ACTION_FILTER, JobMessage.MODE_INTERACTIVE);
90  	}
91  
92  	/**
93  	 * Creates a new instance of <code>DefaultJobMessage</code> with the mode
94  	 * provided. Defaults the action to <code>ACTION_FILTER</code>.
95  	 * 
96  	 * @param mode
97  	 *            The mode in which Insight is running.
98  	 */
99  	public DefaultJobMessage(short mode) {
100 		this(JobMessage.ACTION_FILTER, mode);
101 	}
102 
103 	/**
104 	 * Creates a new instance of <code>DefaultJobMessage</code> with the mode
105 	 * and action provided.
106 	 * 
107 	 * @param action
108 	 *            The action which caused the message.
109 	 * @param mode
110 	 *            The mode in which Insight is running.
111 	 */
112 	public DefaultJobMessage(int action, short mode) {
113 		this._action = action;
114 		this._mode = mode;
115 		this._messages = new ArrayList();
116 	}
117 
118 	// -------------------------------------------------------------------------
119 	// Methods implemented from
120 	// com.mindtree.techworks.insight.reporting.jobs.message.JobMessage
121 	// -------------------------------------------------------------------------
122 
123 	/**
124 	 * @see JobMessage#getJobMessageType()
125 	 */
126 	public String getJobMessageType() {
127 
128 		return DefaultJobMessage.class.getName();
129 	}
130 
131 	/**
132 	 * @see JobMessage#getAction()
133 	 */
134 	public int getAction() {
135 
136 		return this._action;
137 	}
138 
139 	/**
140 	 * @see JobMessage#getFilterCriteria()
141 	 */
142 	public FilterCriteria getFilterCriteria() {
143 
144 		return this._criteria;
145 	}
146 
147 	/**
148 	 * @see JobMessage#getInsightMode()
149 	 */
150 	public short getInsightMode() {
151 
152 		return this._mode;
153 	}
154 
155 	// -------------------------------------------------------------------------
156 	// Accessor methods
157 	// -------------------------------------------------------------------------
158 
159 	/**
160 	 * Sets the criteria which caused the message.
161 	 * 
162 	 * @param filterCriteria The criteria executed to get the message.
163 	 */
164 	public void setFilterCriteria(FilterCriteria filterCriteria) {
165 
166 		this._criteria = filterCriteria;
167 	}
168 
169 	/**
170 	 * Adds a message to the <code>DefaultJobMessage</code>.
171 	 * 
172 	 * @param message The message to be added.
173 	 */
174 	public void addMessage(String message) {
175 
176 		this._messages.add(message);
177 	}
178 
179 	/**
180 	 * Returns an <code>Iterator</code> for all the messages in the instance.
181 	 * 
182 	 * @return An Iterator for all the messages.
183 	 */
184 	public Iterator iterateMessages() {
185 
186 		return this._messages.iterator();
187 	}
188 
189 	/**
190 	 * Returns the number of messages in the instance.
191 	 * 
192 	 * @return The number of messages in the instance.
193 	 */
194 	public int getMessageCount() {
195 
196 		return this._messages.size();
197 	}
198 
199 	/**
200 	 * Returns the message at the specified index.
201 	 * 
202 	 * @param index
203 	 *            The index at which the message is required.
204 	 * @return The message at the index.
205 	 * @throws ArrayIndexOutOfBoundsException
206 	 *             If there is no message at the specified index.
207 	 */
208 	public String getMessage(int index) {
209 
210 		return (String) this._messages.get(index);
211 	}
212 }