1 18 package sync4j.framework.server.session; 19 20 import java.util.*; 21 22 import sync4j.framework.core.*; 23 import sync4j.framework.security.Sync4jPrincipal; 24 import sync4j.framework.security.SecurityConstants; 25 import sync4j.framework.server.Sync4jDevice; 26 27 35 public class SyncState 36 implements SecurityConstants { 37 38 40 43 public Sync4jDevice device; 44 45 48 public Cred loggedCredential; 49 50 53 public Sync4jPrincipal loggedPrincipal; 54 55 64 public int authenticationState; 65 66 74 public int serverAuthenticationState; 75 76 79 public boolean started; 80 81 84 public String syncMLVerProto; 85 86 89 public boolean syncWithInit; 90 91 94 public SyncML responseInit; 95 96 100 public long maxMsgSize = Long.MAX_VALUE; 101 102 105 public long overheadHdr; 106 107 110 public long sizeStatusSyncHdr; 111 112 115 public Status statusSyncHdr; 116 117 120 public long maxObjSize = 6000; 121 122 125 public String receivedLargeObject; 126 127 130 public Long sizeOfReceivedLargeObject; 131 132 137 public String syncLocURI; 138 public String itemLocURI; 139 140 143 public String sendingLOURI; 144 145 148 public ArrayList cmdCache1; 149 150 153 public ArrayList cmdCache3; 154 155 159 public DevInf devInf; 160 161 163 public SyncState() { 164 reset(); 165 } 166 167 170 public void reset() { 171 device = null ; 172 loggedCredential = null ; 173 loggedPrincipal = null ; 174 authenticationState = AUTH_UNAUTHENTICATED; 175 serverAuthenticationState = AUTH_UNAUTHENTICATED; 176 started = false ; 177 syncMLVerProto = null ; 178 syncWithInit = false ; 179 responseInit = null ; 180 maxMsgSize = Integer.MAX_VALUE ; 181 overheadHdr = 0 ; 182 sizeStatusSyncHdr = 0 ; 183 statusSyncHdr = null ; 184 maxObjSize = 0 ; 185 receivedLargeObject = null ; 186 sizeOfReceivedLargeObject = null ; 187 syncLocURI = null ; 188 itemLocURI = null ; 189 sendingLOURI = null ; 190 cmdCache1 = new ArrayList() ; 191 cmdCache3 = new ArrayList() ; 192 devInf = null ; 193 } 194 195 198 private ArrayList listClientAlerts = new ArrayList(); 199 200 public void addClientAlerts(Alert[] clientAlerts) { 201 for (int i=0; ((clientAlerts != null) && (i<clientAlerts.length)); i++) { 202 listClientAlerts.add(clientAlerts[i]); 203 } 204 } 205 206 public void removeClientAlert(Alert alert) { 207 listClientAlerts.remove(alert); 208 } 209 210 public Alert[] getClientAlerts() { 211 return (Alert[])listClientAlerts.toArray(new Alert[listClientAlerts.size()]); 212 } 213 214 218 private ArrayList listServerModifications = new ArrayList(); 219 220 public void setServerModifications(AbstractCommand[] serverModifications) { 221 222 int size = listServerModifications.size(); 223 224 for (int i=0; ((serverModifications != null) && (i<serverModifications.length)); i++) { 225 boolean isAdded = false; 226 Sync sync = (Sync)serverModifications[i]; 227 228 for (int y=0; y<size; y++) { 229 Sync syncOld = (Sync)listServerModifications.get(y); 230 231 if (sync.getTarget().getLocURI().equalsIgnoreCase(syncOld.getTarget().getLocURI()) && 232 sync.getSource().getLocURI().equalsIgnoreCase(syncOld.getSource().getLocURI()) ) { 233 234 syncOld.getCommands().addAll(sync.getCommands()); 235 isAdded = true; 236 break; 237 } 238 } 239 if (!isAdded) { 240 listServerModifications.add(serverModifications[i]); 241 } 242 } 243 } 244 245 public AbstractCommand[] getServerModifications() { 246 return (AbstractCommand[])listServerModifications.toArray( 247 new AbstractCommand[listServerModifications.size()] 248 ); 249 } 250 251 public void clearServerModifications() { 252 listServerModifications.clear(); 253 } 254 255 258 private LinkedList listStatusCmdOut = new LinkedList(); 259 260 public void addStatusCmdOut(List statusList) { 261 listStatusCmdOut.addAll(statusList); 262 } 263 264 public LinkedList getStatusCmdOut() { 265 return listStatusCmdOut; 266 } 267 268 public void removeStatusCmdOut(List statusCommand) { 269 listStatusCmdOut.removeAll(statusCommand); 270 } 271 272 275 private LinkedList listMapStatusOut = new LinkedList(); 276 277 public void addMapStatusOut(List mapStatusList) { 278 listMapStatusOut.addAll(mapStatusList); 279 } 280 281 public LinkedList getMapStatusOut() { 282 return listMapStatusOut; 283 } 284 285 public void removeMapStatusOut(List mapStatus) { 286 listMapStatusOut.removeAll(mapStatus); 287 } 288 289 292 private LinkedList listAlertCmdOut = new LinkedList(); 293 294 public void addAlertCmdOut(List alertList) { 295 listAlertCmdOut.addAll(alertList); 296 } 297 298 public void addAlertCmdOut(Alert alert) { 299 listAlertCmdOut.add(alert); 300 } 301 302 public LinkedList getAlertCmdOut() { 303 return listAlertCmdOut; 304 } 305 306 public void removeAlertCmdOut(List alertList) { 307 listAlertCmdOut.removeAll(alertList); 308 } 309 310 313 private LinkedList listCmdOut = new LinkedList(); 314 315 public void addCmdOut(List cmdList) { 316 listCmdOut.addAll(cmdList); 317 } 318 319 public LinkedList getCmdOut() { 320 return listCmdOut; 321 } 322 323 public void removeCmdOut(List abstractCommand) { 324 listCmdOut.removeAll(abstractCommand); 325 } 326 327 public void removeCmdOut(AbstractCommand abstractCommand) { 328 listCmdOut.remove(abstractCommand); 329 } 330 331 334 private LinkedList listStatusCmdNotProcessed = null; 335 public void addStatusCmdNotProcessed(Status status) { 336 if (listStatusCmdNotProcessed == null) { 337 listStatusCmdNotProcessed = new LinkedList(); 338 } 339 listStatusCmdNotProcessed.add(status); 340 } 341 public LinkedList getListStatusCmdNotProcessed() { 342 return listStatusCmdNotProcessed; 343 } 344 public void clearListStatusCmdNotProcessed() { 345 listStatusCmdNotProcessed.clear(); 346 } 347 348 351 private LinkedList cmdsNotSent = new LinkedList(); 352 public void setCmdsNotSent(List cmdsNotSent) { 353 this.cmdsNotSent.clear(); 354 this.cmdsNotSent.addAll(cmdsNotSent); 355 } 356 public LinkedList getCmdsNotSent() { 357 return this.cmdsNotSent; 358 } 359 360 363 private Sync syncSplittedToSend = null; 364 public void setSyncSplittedToSend(Sync syncSplittedToSend) { 365 AbstractCommand[] cmds = 366 (AbstractCommand[])this.getCmdsNotSent().toArray( 367 new AbstractCommand[0] 368 ); 369 this.syncSplittedToSend = new Sync( 370 syncSplittedToSend.getCmdID(), 371 syncSplittedToSend.isNoResp(), 372 syncSplittedToSend.getCred(), 373 syncSplittedToSend.getTarget(), 374 syncSplittedToSend.getSource(), 375 syncSplittedToSend.getMeta(), 376 syncSplittedToSend.getNumberOfChanges(), 377 cmds 378 ); 379 } 380 public Sync getSyncSplittedToSend() { 381 return this.syncSplittedToSend; 382 } 383 } 384 | Popular Tags |