View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
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  
21  package org.xnap.plugin.opennap.net.msg.server;
22  
23  import org.xnap.plugin.opennap.net.OpenNapServer;
24  import org.xnap.plugin.opennap.net.msg.Message;
25  import org.xnap.util.QuotedStringTokenizer;
26  
27  public class ServerMessage extends Message {
28  
29      //--- Data Field(s) ---
30  
31      protected OpenNapServer server;
32      protected String data;
33      protected boolean consumed = false;
34  
35      //--- Constructor(s) ---
36  
37      protected ServerMessage(int type, String data, int argc)
38  	throws InvalidMessageException
39      {
40  	super(type);
41  
42  	this.data = data;
43  
44  	QuotedStringTokenizer t = new QuotedStringTokenizer(data);
45  
46  	if (t.countTokens() < argc) {
47  	    throw new InvalidMessageException("Wrong number of arguments.");
48  	}
49  
50  	try {
51  	    parse(t);
52  	}
53  	catch (Exception e) {
54  	    throw new InvalidMessageException("Wrong type of argument.");
55  	}
56      }
57  
58      //--- Method(s) ---
59  
60      /*** 
61       * Tell message to handle itself.
62       */
63      public void received()
64      {
65      }
66  
67      /***
68       * OvernetMessage can be consumed: if the right listener gets the message, he
69       * consumes it and the other listeners won't get it.
70       */
71      public void consume()
72      {
73  	consumed = true;
74      }
75  
76      /***
77       * See if message is already consumed.
78       */
79      public boolean isConsumed()
80      {
81  	return consumed;
82      }
83  
84      public OpenNapServer getServer() 
85      {
86  	return server;
87      }
88      
89      public void setServer(OpenNapServer newValue)
90      {
91  	server = newValue;
92      }
93  
94      public String toString()
95      {
96  	return data;
97      }
98  
99      protected void parse(QuotedStringTokenizer t) throws Exception
100     {
101     }
102     
103 }