KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > server > session > ManagementState


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.framework.server.session;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.LinkedList JavaDoc;
22 import java.util.List JavaDoc;
23
24 import sync4j.framework.core.*;
25 import sync4j.framework.engine.dm.DeviceDMState;
26 import sync4j.framework.security.SecurityConstants;
27 import sync4j.framework.security.Sync4jPrincipal;
28 import sync4j.framework.server.SyncTimestamp;
29 import sync4j.framework.server.Sync4jDevice;
30 import sync4j.framework.protocol.ProtocolUtil;
31 import sync4j.framework.core.dm.ddf.DevInfo;
32
33
34 /**
35  * This class keeps state information of a device management session.
36  *
37  * @author Stefano Fornari @ funambol.com
38  * @version $Id: ManagementState.java,v 1.1 2005/05/16 17:32:56 nichele Exp $
39  */

40 public class ManagementState
41 implements SecurityConstants {
42
43     // --------------------------------------------------------------- Constants
44

45     // ------------------------------------------------------------ Private data
46

47     /**
48      * Cache AbstractCommands (Alert, Put, Get)
49      */

50     private ArrayList JavaDoc clientCommands;
51
52     // ------------------------------------------------------------- Public data
53

54     /**
55      * Cache the devInf replace command
56      */

57     public Replace devInfReplaceCommand;
58
59     /**
60      * Cache the device info
61      */

62     public DevInf deviceInfo;
63
64     /**
65      * Cache the Sync4jDevice object (it contains Sync4j information and nonces
66      */

67     public Sync4jDevice device;
68
69     /**
70      * Cache the device DM state
71      */

72     public DeviceDMState dmstate;
73
74     /**
75      * The management session id
76      */

77     public String JavaDoc sessionId;
78
79     /**
80      * Authenticated credential. If null no credential has authenticated.
81      */

82     public Cred loggedCredential;
83
84     /**
85      * Authenticated principal. If null, no principal has authenticated
86      */

87     public Sync4jPrincipal loggedPrincipal;
88
89     /**
90      * The Last message Id from the client
91      */

92     public String JavaDoc lastMsgIdFromClient;
93
94     /**
95      * Timestamps of the last management session
96      */

97     public SyncTimestamp lastTimestamp;
98
99     /**
100      * Timestamps of the current management session
101      */

102     public SyncTimestamp nextTimestamp;
103
104     /**
105      * Authentication state. One of the following values:
106      * <ul>
107      * <li>AUTH_UNAUTHENTICATED</li>
108      * <li>AUTH_MISSING_CREDENTIALS</li>
109      * <li>AUTH_INVALID_CREDENTIALS</li>
110      * <li>AUTH_AUTHENTICATED</li>
111      * </ul>
112      */

113     public int authenticationState;
114
115     /**
116      * Server authentication state. One of the following values:
117      * <ul>
118      * <li>AUTH_UNAUTHENTICATED</li>
119      * <li>AUTH_RETRY_1</li>
120      * <li>AUTH_RETRY_2</li>
121      * </ul>
122      */

123     public int serverAuthenticationState;
124
125     /**
126      * Management session type (@see AlertCode)
127      */

128     public int type;
129
130     /**
131      * Has the session been started ?
132      */

133     public boolean started;
134
135
136     /**
137      * Cache the SyncML Protocol version used by device
138      */

139     public String JavaDoc syncMLVerProto;
140
141
142     /**
143      * Cache the maximum message size
144      */

145     private long maxMsgSize = 0;
146     public void setMaxMsgSize(long value) {
147         maxMsgSize = value;
148     }
149
150     public long getMaxMsgSize() {
151         return maxMsgSize;
152     }
153
154     /**
155      * Cache the maximum object size
156      */

157     private long maxObjSize = 0;
158     public long getMaxObjSize() {
159         return this.maxObjSize;
160     }
161     public void setMaxObjSize(long maxObjSize) {
162         this.maxObjSize = maxObjSize;
163     }
164
165
166     /**
167      * Cache overhead for SyncHdr object
168      */

169     private long overheadHdr = 0;
170     public long getOverheadHdr() {
171         return this.overheadHdr;
172     }
173     public void setOverheadHdr(long overheadHdr) {
174         this.overheadHdr = overheadHdr;
175     }
176
177
178     /**
179      * Cache the Status command presents in the response message
180      */

181     private LinkedList JavaDoc listStatusCmdOut = new LinkedList JavaDoc();
182
183     public void addStatusCmdOut(List JavaDoc statusList) {
184         listStatusCmdOut.addAll(statusList);
185     }
186
187     public LinkedList JavaDoc getStatusCmdOut() {
188         return listStatusCmdOut;
189     }
190
191     public void removeStatusCmdOut(List JavaDoc statusCommand) {
192         listStatusCmdOut.removeAll(statusCommand);
193     }
194
195
196     /**
197      * Cache the Alert command presents in the response message
198      */

199     private LinkedList JavaDoc listAlertCmdOut = new LinkedList JavaDoc();
200
201     public void addAlertCmdOut(List JavaDoc alertList) {
202         listAlertCmdOut.addAll(alertList);
203     }
204
205     public LinkedList JavaDoc getAlertCmdOut() {
206         return listAlertCmdOut;
207     }
208
209     public void removeAlertCmdOut(List JavaDoc alertList) {
210         listAlertCmdOut.removeAll(alertList);
211     }
212
213
214     /**
215      * Cache cmd splitted in more message (Large Object)
216      */

217     private AbstractCommand splittedCommand = null;
218
219     public AbstractCommand getSplittedCommand() {
220         return splittedCommand;
221     }
222
223     public void setSplittedCommand(AbstractCommand splittedCommand) {
224         this.splittedCommand = splittedCommand;
225     }
226
227
228     /**
229      * Cache received large object
230      */

231     private String JavaDoc receivedLargeObject = null;
232
233     public String JavaDoc getReceivedLargeObject() {
234         return receivedLargeObject;
235     }
236
237     public void setReceivedLargeObject(String JavaDoc receivedLargeObject) {
238         this.receivedLargeObject = receivedLargeObject;
239     }
240
241     /**
242      * Cache size of received large object
243      */

244     private Long JavaDoc sizeOfReceivedLargeObject = null;
245
246     public void setSizeOfReceivedLargeObject(Long JavaDoc size) {
247         this.sizeOfReceivedLargeObject = size;
248     }
249
250     public Long JavaDoc getSizeOfReceivedLargeObject() {
251         return sizeOfReceivedLargeObject;
252     }
253
254
255     /**
256      * Cache data to send in next messages (Large Object)
257      */

258     private String JavaDoc nextDataToSend = null;
259
260     public String JavaDoc getNextDataToSend() {
261         return nextDataToSend;
262     }
263
264     public void setNextDataToSend(String JavaDoc nextDataToSend) {
265         this.nextDataToSend = nextDataToSend;
266     }
267
268
269
270     /**
271      * Cache the AbstractCommand presents in the response message
272      */

273     private LinkedList JavaDoc listCmdOut = new LinkedList JavaDoc();
274
275     public void addCmdOut(List JavaDoc cmdList) {
276         listCmdOut.addAll(cmdList);
277     }
278
279     public void addCmdOut(int index, List JavaDoc cmdList) {
280          listCmdOut.addAll(index, cmdList);
281      }
282
283     public LinkedList JavaDoc getCmdOut() {
284         return listCmdOut;
285     }
286
287     public void removeCmdOut(List JavaDoc abstractCommandsList) {
288         listCmdOut.removeAll(abstractCommandsList);
289     }
290
291     public void removeCmdOut(AbstractCommand abstractCommand) {
292         listCmdOut.remove(abstractCommand);
293     }
294
295
296     /**
297      * Cache overhead of Status for SyncHdr
298      */

299     private long sizeStatusSyncHdr = 0;
300     public long getSizeStatusSyncHdr() {
301         return this.sizeStatusSyncHdr;
302     }
303
304     public void setSizeStatusSyncHdr(long sizeStatusSyncHdr) {
305          this.sizeStatusSyncHdr = sizeStatusSyncHdr;
306      }
307
308      /**
309       * Cache Status for SyncHdr
310       */

311      private Status statusSyncHdr;
312      public void setStatusSyncHdr(Status statusSyncHdr) {
313          this.statusSyncHdr = statusSyncHdr;
314      }
315
316      public Status getStatusSyncHdr() {
317          return this.statusSyncHdr;
318      }
319
320
321     // ------------------------------------------------------------ Constructors
322

323     /**
324      * Creates a new management state object associated to the given session id
325      *
326      * @param sessionId the sessionId
327      */

328     public ManagementState(String JavaDoc sessionId) {
329         this();
330         this.sessionId = sessionId;
331     }
332
333     /**
334      * Creates a new management state object with empty state and not associated
335      * to any session id.
336      */

337     public ManagementState() {
338         reset();
339     }
340
341
342
343     // ---------------------------------------------------------- Public Methods
344

345     public void addClientCommands(AbstractCommand[] commands) {
346         for (int i=0; ((commands != null) && (i<commands.length)); i++) {
347             if (ProtocolUtil.hasLargeObject(commands[i])) {
348                 // commands with large object don't come cached
349
continue;
350             }
351             clientCommands.add(commands[i]);
352         }
353     }
354
355     public AbstractCommand[] getClientCommands() {
356         return (AbstractCommand[])clientCommands.toArray(new AbstractCommand[clientCommands.size()]);
357     }
358
359     public void clearClientCommands() {
360         clientCommands.clear();
361     }
362
363
364     /**
365      * Sets sessionId
366      *
367      * @param sessionId the management session id
368      */

369     protected void setSessionId(String JavaDoc sessionId) {
370         this.sessionId = sessionId;
371     }
372
373     /**
374      * Returns the management session id
375      *
376      * @return the management session id
377      */

378     public String JavaDoc getSessionId() {
379         return sessionId;
380     }
381
382     /**
383      * Reset this object to an initial state
384      */

385     public void reset() {
386         loggedCredential = null;
387         loggedPrincipal = null;
388         lastMsgIdFromClient = null;
389         sessionId = null;
390         lastTimestamp = null;
391         nextTimestamp = null;
392
393         started = false;
394
395         type = AlertCode.UNKNOWN;
396
397         authenticationState = AUTH_UNAUTHENTICATED;
398
399         serverAuthenticationState = AUTH_UNAUTHENTICATED;
400
401         clientCommands = new ArrayList JavaDoc();
402     }
403 }
Popular Tags