View Javadoc

1   /***
2    * Jetrix TetriNET Server
3    * Copyright (C) 2001-2003  Emmanuel Bourg
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
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 License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package net.jetrix;
21  
22  import java.util.*;
23  
24  /***
25   * Internal message sent between server, channels and client handlers.
26   *
27   * @author Emmanuel Bourg
28   * @version $Revision: 794 $, $Date: 2009-02-17 20:08:39 +0100 (Tue, 17 Feb 2009) $
29   */
30  public abstract class Message
31  {
32      private Destination source;
33      private Destination destination;
34      private long time;
35      private Map<Protocol, String> rawMessages;
36  
37      /***
38       * Constructs a new server message.
39       */
40      public Message()
41      {
42          this.time = System.currentTimeMillis();
43          rawMessages = new HashMap<Protocol, String>();
44      }
45  
46      /***
47       * Return the source of this message. The source is a Destination accepting
48       * replies to this message.
49       */
50      public Destination getSource()
51      {
52          return source;
53      }
54  
55      /***
56       * Set the source of this message.
57       */
58      public void setSource(Destination source)
59      {
60          this.source = source;
61      }
62  
63      /***
64       * Return the destination of this message. If the destination is null the
65       * default destination is the current channel of the user.
66       */
67      public Destination getDestination() {
68          return destination;
69      }
70  
71      /***
72       * Set the destination of this message (optional).
73       */
74      public void setDestination(Destination destination) {
75          this.destination = destination;
76      }
77  
78      /***
79       * Returns the creation date of this message.
80       */
81      public long getTime()
82      {
83          return time;
84      }
85  
86      /***
87       * Set the view of the message in the specified protocol.
88       */
89      public void setRawMessage(Protocol protocol, String message)
90      {
91          rawMessages.put(protocol, message);
92      }
93  
94      /***
95       * Return the view of this message in the specified protocol.
96       */
97      public String getRawMessage(Protocol protocol, Locale locale)
98      {
99          // is the raw message available for the specified protocol
100         String message = rawMessages.get(protocol);
101 
102         if (message == null)
103         {
104             // building the raw message for this protocol
105             message = protocol.translate(this, locale);
106             rawMessages.put(protocol, message);
107         }
108 
109         return message;
110     }
111 
112 }