001 /**
002 * Jetrix TetriNET Server
003 * Copyright (C) 2001-2003 Emmanuel Bourg
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019
020 package net.jetrix;
021
022 import java.util.*;
023
024 /**
025 * Internal message sent between server, channels and client handlers.
026 *
027 * @author Emmanuel Bourg
028 * @version $Revision: 794 $, $Date: 2009-02-17 20:08:39 +0100 (Tue, 17 Feb 2009) $
029 */
030 public abstract class Message
031 {
032 private Destination source;
033 private Destination destination;
034 private long time;
035 private Map<Protocol, String> rawMessages;
036
037 /**
038 * Constructs a new server message.
039 */
040 public Message()
041 {
042 this.time = System.currentTimeMillis();
043 rawMessages = new HashMap<Protocol, String>();
044 }
045
046 /**
047 * Return the source of this message. The source is a Destination accepting
048 * replies to this message.
049 */
050 public Destination getSource()
051 {
052 return source;
053 }
054
055 /**
056 * Set the source of this message.
057 */
058 public void setSource(Destination source)
059 {
060 this.source = source;
061 }
062
063 /**
064 * Return the destination of this message. If the destination is null the
065 * default destination is the current channel of the user.
066 */
067 public Destination getDestination() {
068 return destination;
069 }
070
071 /**
072 * Set the destination of this message (optional).
073 */
074 public void setDestination(Destination destination) {
075 this.destination = destination;
076 }
077
078 /**
079 * Returns the creation date of this message.
080 */
081 public long getTime()
082 {
083 return time;
084 }
085
086 /**
087 * Set the view of the message in the specified protocol.
088 */
089 public void setRawMessage(Protocol protocol, String message)
090 {
091 rawMessages.put(protocol, message);
092 }
093
094 /**
095 * Return the view of this message in the specified protocol.
096 */
097 public String getRawMessage(Protocol protocol, Locale locale)
098 {
099 // 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 }