View Javadoc

1   /*
2   Copyright (C) 2007 Dirk Huenniger
3   
4   This library is free software; you can redistribute it and/or
5   modify it under the terms of the GNU Lesser General Public
6   License as published by the Free Software Foundation; either
7   version 2.1 of the License, or (at your option) any later version.
8   
9   This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Lesser General Public License for more details.
13  
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17   */
18  
19  package org.indi.objects;
20  
21  import java.text.SimpleDateFormat;
22  import java.util.Date;
23  import java.util.LinkedList;
24  import java.util.SimpleTimeZone;
25  
26  /**
27   * A class repersenting a single indi message
28   * 
29   * @author Dirk Hünniger
30   * 
31   */
32  public class Message extends Object<Object> {
33      /**
34       * 
35       */
36      private static final long serialVersionUID = 1L;
37      /**
38       * the device the message is associated with
39       */
40      private final String device;
41      /**
42       * the SimpleDateFormat used for timestamping the message
43       */
44      private final SimpleDateFormat dateformat;
45  
46      /**
47       * class constructor
48       * 
49       * @param device
50       *                the device the message is associated with
51       */
52      public Message(String device) {
53  	super(new LinkedList<Object>());
54  	this.device = device;
55  	this.dateformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
56  	this.dateformat.setTimeZone(new SimpleTimeZone(0, "GMT"));
57      }
58  
59      /**
60       * 
61       * @return the device the message is associated with
62       */
63      public String getDevice() {
64  	return this.device;
65      }
66  
67      @Override
68      public String getXML(TransferType type, String message) {
69  	return "<message" + " device=\"" + this.device + "\" message=\""
70  		+ message + "\" timestamp=\""
71  		+ this.dateformat.format(new Date()) + "\"/>";
72      }
73  
74      @Override
75      public boolean oEquals(Object o) {
76  	if (o instanceof Message) {
77  	    return ((Message) o).device.equals(this.device);
78  	} else {
79  	    return false;
80  	}
81      }
82  
83      @Override
84      public int hashCode() {
85  	return this.device.hashCode();
86      };
87  }