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.io.IOException;
23 import java.io.InputStream;
24 import java.util.Locale;
25
26 /***
27 * A protocol to communicate with a client. A protocol is responsible for
28 * transforming the messages in string format comming for a client into the
29 * corresponding server {@link net.jetrix.Message}, as well as performing the
30 * reverse operation.
31 *
32 * @author Emmanuel Bourg
33 * @version $Revision: 848 $, $Date: 2010-05-03 22:51:32 +0200 (lun., 03 mai 2010) $
34 */
35 public interface Protocol
36 {
37 /***
38 * Return the name of this protocol.
39 *
40 * @return the name of this protocol
41 */
42 String getName();
43
44 /***
45 * Parse the specified string and return the corresponding server
46 * message for this protocol.
47 *
48 * @param message the client message to parse
49 *
50 * @return the {@link net.jetrix.Message} equivalent of the specified
51 * String or null if the protocol cannot understand the message.
52 */
53 Message getMessage(String message);
54
55 /***
56 * Translate the specified message into a string that will be sent
57 * to a client using this protocol.
58 *
59 * @param m the message to translate
60 * @param locale the locale used for internationalized text messages
61 *
62 * @return the String equivalent in this protocol for the specified
63 * {@link net.jetrix.Message} or null if it can't be translated.
64 */
65 String translate(Message m, Locale locale);
66
67 /***
68 * Transform the style tags (<tt><blue></tt>, <tt><u></tt>,
69 * etc...) contained in the specified string into the style codes of this
70 * protocol.
71 *
72 * @param text the string to transform
73 *
74 * @return the stylized representation of the specified string for
75 * this protocol.
76 */
77 String applyStyle(String text);
78
79 /***
80 * Return the end of line character used by this protocol.
81 */
82 char getEOL();
83
84 /***
85 * Read a line for this protocol. A line is ended by a \n or \r character,
86 * or by a protocol specific end of line as defined by the {@link #getEOL()}
87 * method.
88 *
89 * @since 0.3
90 *
91 * @param in the stream to be read
92 * @param encoding the charset encoding used to read the message
93 * @throws IOException thrown if the stream is closed
94 */
95 String readLine(InputStream in, String encoding) throws IOException;
96
97 }