Source code: mas_gui/SessionState.java
1 /* Copyright 1998 - 2003: Jim Cochrane - see file forum.txt */
2
3 package mas_gui;
4
5 import common.*;
6 import java.io.*;
7 import java.util.*;
8
9 class SessionState implements NetworkProtocol {
10 // `response_string' is the string sent by the server in response to
11 // a login request.
12 SessionState(String response_string) throws IOException {
13 StringTokenizer t = new StringTokenizer(response_string,
14 Output_field_separator);
15 String s = null;
16 if (! t.hasMoreTokens()) {
17 throw new IOException("Received empty key from server.");
18 }
19 // Obtain the session key.
20 try {
21 s = t.nextToken();
22 _session_key = Integer.valueOf(s).intValue();
23 }
24 catch (Exception e) {
25 throw new IOException("Received invalid key from " +
26 "server: " + s + " - " + e);
27 }
28 // Obtain any session state information sent by the server.
29 while (t.hasMoreTokens()) {
30 s = t.nextToken();
31 if (s.equals(No_open_session_state)) {
32 _open_field = false;
33 }
34 }
35 }
36
37 // The "session key" - used for requests to the server
38 public int session_key() {
39 return _session_key;
40 }
41
42 // Is there an open field in the data recevied from the server?
43 public boolean open_field() {
44 return _open_field;
45 }
46
47 // Specify whether there is an open field in the data recevied from
48 // the server.
49 // Postcondition: open_field() == value
50 public void set_open_field(boolean value) {
51 _open_field = value;
52 }
53
54 private int _session_key;
55
56 private boolean _open_field = true;
57 }