View Javadoc

1   /*
2    *  
3    *  Fosstrak LLRP Commander (www.fosstrak.org)
4    * 
5    *  Copyright (C) 2008 ETH Zurich
6    *
7    *  This program is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  This program is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with this program.  If not, see <http://www.gnu.org/licenses/> 
19   *
20   */
21  
22  package org.fosstrak.llrp.client;
23  
24  import java.sql.Timestamp;
25  import java.text.DateFormat;
26  import java.text.SimpleDateFormat;
27  import java.util.Date;
28  
29  /**
30   * This wrapper class for LLRP Message. Some extended attributes added for
31   * Repository use.
32   *
33   * @author Haoning Zhang
34   * @author sawielan
35   * @version 1.0
36   */
37  public class LLRPMessageItem {
38  	
39  	// Default values when it is empty
40  	private final static String EMPTY_READER_ID = "Unknown Reader";
41  	private final static String EMPTY_MESSAGE_TYPE = "Unknown Type";
42  	
43  	private static final DateFormat DATE_FORMATTER = new SimpleDateFormat(
44  	"yyyy-MMM-dd-HH-mm-ss-SSS");
45  	
46  	/**
47  	 * Static DB field value for Imcoming Message.
48  	 */
49  	public final static int MARK_INCOMING = 1;
50  	
51  	/**
52  	 * Static DB field value for Outgoing Message
53  	 */
54  	public final static int MARK_OUTGOING = 2;
55  	
56  	private String msgId;
57  	private String adapterId;
58  	private String readerId;
59  	private String messageType;
60  	private String statusCode;
61  	private String comment;
62  	private Timestamp issueTime;
63  	private String content;
64  	private int mark;
65  	
66  	/**
67  	 * Default Constructor
68  	 */
69  	public LLRPMessageItem() {
70  		setId(DATE_FORMATTER.format(new Date()));
71  		setMessageType(EMPTY_MESSAGE_TYPE);
72  		setStatusCode("");
73  		setTime(new Timestamp(System.currentTimeMillis()));
74  		setReader(EMPTY_READER_ID);
75  		setContent("");
76  		setComment("");
77  		setMark(MARK_INCOMING);
78  		setAdapter(Reader.LOCAL_ADAPTER_NAME);
79  	}
80  	
81  	/**
82  	 * Get the unique reader name (Adapter Name + Reader Name).
83  	 * 
84  	 * @return Unique Reader Name
85  	 */
86  	public String getUniqueName() {
87  		return Reader.getUniqueReaderId(getAdapter(), getReader());
88  	}
89  	
90  	/**
91  	 * Get the Message Id
92  	 * 
93  	 * @return Message Id
94  	 */
95  	public String getId() {
96  		return msgId;
97  	}
98  	
99  	/**
100 	 * Set the Message Id
101 	 * 
102 	 * @param aId Message Id
103 	 */
104 	public void setId(String aId) {
105 		msgId = aId;
106 	}
107 	
108 	/**
109 	 * Get the Message Content as String
110 	 * 
111 	 * @return Message Content
112 	 */
113 	public String getContent() {
114 		return content;
115 	}
116 	
117 	/**
118 	 * Set the Message Content
119 	 * 
120 	 * @param content Message Content
121 	 */
122 	public void setContent(String content) {
123 		this.content = content;
124 	}
125 
126 	/**
127 	 * Get the Reader Logical Name, without Adapter Logical Name.
128 	 * 
129 	 * @return Reader Logical Name
130 	 */
131 	public String getReader() {
132 		return readerId;
133 	}
134 	
135 	/**
136 	 * Set the Reader Logical Name, without Adapter Logical Name.
137 	 * 
138 	 * @param aReader Reader Logical Name
139 	 */
140 	public void setReader(String aReader) {
141 		readerId = aReader;
142 	}
143 	
144 	/**
145 	 * Get the Message Type.
146 	 * 
147 	 * @return Message Type
148 	 */
149 	public String getMessageType() {
150 		return messageType;
151 	}
152 	
153 	/**
154 	 * Set the Message Type.
155 	 * 
156 	 * @param messageType Message Type
157 	 */
158 	public void setMessageType(String messageType) {
159 		this.messageType = messageType;
160 	}
161 	
162 	/**
163 	 * Get the Status Code.
164 	 * 
165 	 * @return Status Code
166 	 */
167 	public String getStatusCode() {
168 		return statusCode;
169 	}
170 	
171 	/**
172 	 * Set the Status Code.
173 	 * 
174 	 * @param statusCode Status Code
175 	 */
176 	public void setStatusCode(String statusCode) {
177 		this.statusCode = statusCode;
178 	}
179 	
180 	/**
181 	 * Get the Message comments
182 	 * 
183 	 * @return Message comments
184 	 */
185 	public String getComment() {
186 		return comment;
187 	}
188 	
189 	/**
190 	 * Set the Message comments
191 	 * 
192 	 * @param comment Message comments
193 	 */
194 	public void setComment(String comment) {
195 		this.comment = comment;
196 	}
197 	
198 	/**
199 	 * Get the Message issue time
200 	 * 
201 	 * @return Issue Time
202 	 */
203 	public Timestamp getTime() {
204 		return issueTime;
205 	}
206 	
207 	/**
208 	 * Set the Message issue time
209 	 * 
210 	 * @param ts Issue Time
211 	 */
212 	public void setTime(Timestamp ts) {
213 		issueTime = ts;
214 	}
215 
216 	/**
217 	 * Get the mark of the Message
218 	 * 
219 	 * Static value MARK_INCOMING for incoming messages
220 	 * Static value MARK_OUTGOING for outgoing messages
221 	 * 
222 	 * @return Message Mark
223 	 */
224 	public int getMark() {
225 		return mark;
226 	}
227 
228 	/**
229 	 * Set the mark of the Message
230 	 * 
231 	 * Static value MARK_INCOMING for incoming messages
232 	 * Static value MARK_OUTGOING for outgoing messages
233 	 * 
234 	 * @param aMark Message Mark
235 	 */
236 	public void setMark(int aMark) {
237 		mark = aMark;
238 	}
239 
240 	/**
241 	 * Get Adapter Logic Name
242 	 * 
243 	 * @return Adapter Logic Name
244 	 */
245 	public String getAdapter() {
246 		return adapterId;
247 	}
248 
249 	/**
250 	 * Set Adapter Logic Name
251 	 * 
252 	 * @param aAdapterId Adapter Logic Name
253 	 */
254 	public void setAdapter(String aAdapterId) {
255 		adapterId = aAdapterId;
256 	}
257 	
258 	/**
259 	 * creates a pretty print of the llrp message item.
260 	 * @return a string holding the pretty print.
261 	 */
262 	public String prettyPrint() {
263 		StringBuffer buffer = new StringBuffer("\n");
264 		buffer.append("--------------------------------------"); buffer.append("\n");
265 		buffer.append("ID: "); buffer.append(getId()); buffer.append("\n");
266 		buffer.append("Adapter: "); buffer.append(getAdapter()); buffer.append("\n");
267 		buffer.append("Reader: "); buffer.append(getReader()); buffer.append("\n");
268 		buffer.append("time: "); buffer.append(getTime()); buffer.append("\n");
269 		buffer.append("mark: "); buffer.append(getMark()); buffer.append("\n");
270 		buffer.append("messagetype: "); buffer.append(getMessageType()); buffer.append("\n");
271 		buffer.append("statuscode: "); buffer.append(getStatusCode()); buffer.append("\n");
272 		buffer.append("--------------------------------------"); buffer.append("\n");
273 		
274 		return buffer.toString();
275 	}
276 }