KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > org > quickserver > net > server > TestCommandHandler


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package test.org.quickserver.net.server;
16
17 import org.quickserver.net.server.*;
18 import java.io.*;
19 import java.net.*;
20
21 /**
22  * TestEventHandler for QuickServer
23  */

24 public class TestCommandHandler implements ClientCommandHandler {
25     private static int handleCommandFlag;
26     private static String JavaDoc response;
27     private static String JavaDoc request;
28
29     public void handleCommand(ClientHandler handler, String JavaDoc command)
30             throws SocketTimeoutException, IOException {
31         handleCommandFlag++;
32         request = command;
33         //System.out.println("Got->"+command+"<-");
34
if(response!=null) {
35             if(response.toLowerCase().equals("quit")) {
36                 handler.closeConnection();
37                 response = null;
38             } else {
39                 handler.sendClientMsg(response);
40                 response = null;
41             }
42         }
43     }
44
45     public static String JavaDoc getRequest() {
46         return request;
47     }
48
49     public static String JavaDoc getResponse() {
50         return response;
51     }
52     public static void setResponse(String JavaDoc res) {
53         response = res;
54     }
55
56     public static int getHandleCommandFlag() {
57         return handleCommandFlag;
58     }
59     public static void reset() {
60         handleCommandFlag = 0;
61     }
62 }
Popular Tags