KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > tools > SizeCalculator


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.tools;
19
20 import java.io.*;
21 import java.util.ArrayList JavaDoc;
22
23 import sync4j.framework.core.*;
24
25 /**
26  * Utility class for calculate the XML size and WBXML size of framework Objects
27  *
28  * @author Luigia Fassina @ Funambol
29  * @version $Id: SizeCalculator.java,v 1.1 2005/05/16 17:32:56 nichele Exp $
30  */

31 public class SizeCalculator {
32
33     // ---------------------------------------------------------- Public methods
34

35     // ------------------------------------------------------------------ SyncML
36
/**
37      * Returns the XML overhead for SyncML object
38      * sizeof(<SyncML xmlns='SYNCML:SYNCML1.1'>\n</SyncML>\n)
39      *
40      * @return overhead for SyncML object
41      */

42     public static long getXMLOverheadSyncML() {
43         return 43;
44     }
45     
46     /**
47      * Returns the WBXML overhead for SyncML object
48      * sizeof(<SyncML xmlns='SYNCML:SYNCML1.1'>\n</SyncML>\n)
49      *
50      * @return overhead for SyncML object
51      */

52     public static long getWBXMLOverheadSyncML() {
53         return 29;
54     }
55     
56     /**
57      * Returns the XML size of the SyncML object
58      * sizeof(<SyncML xmlns='SYNCML:SYNCML1.1'>\n) +
59      * sizeof(syncHdr) +
60      * sizeof(syncBody) +
61      * sizeof(</SyncML>)
62      *
63      * @param syncML the SyncML element
64      *
65      * @return size the XML size of the SyncML element
66      */

67     public static long getXMLSize(SyncML syncML) {
68         SyncHdr syncHdr = syncML.getSyncHdr() ;
69         SyncBody syncBody = syncML.getSyncBody();
70
71         return 43
72              + getXMLSize(syncHdr )
73              + getXMLSize(syncBody)
74              ;
75     }
76
77     /**
78      * Returns the WBXML size of the SyncML object
79      *
80      * @param syncML the SyncML element
81      *
82      * @return size the WBXML size of the SyncML element
83      */

84     public static long getWBXMLSize(SyncML syncML) {
85         SyncHdr syncHdr = syncML.getSyncHdr() ;
86         SyncBody syncBody = syncML.getSyncBody();
87
88         return 29
89              + getWBXMLSize(syncHdr )
90              + getWBXMLSize(syncBody)
91              ;
92     }
93
94     // ----------------------------------------------------------------- SyncHdr
95
/**
96      * Returns the XML size of SyncHdr element as:
97      * sizeof(<SyncHdr>\n) +
98      * if verDTD != null
99      * sizeof(verDTD) +
100      * if verProto != null
101      * sizeof(verProto) +
102      * if sessionID != null
103      * sizeof(<SessionID>) +
104      * if msgId != null
105      * sizeof(<MsgID>) +
106      * msgId.length +
107      * sizeof(</MsgID>\n) +
108      * if target != null
109      * sizeof(target) +
110      * if source != null
111      * sizeof(source) +
112      * if respURI
113      * sizeof(<RespURI>) +
114      * sizeof(respURI) +
115      * sizeof(</RespURI>\n) +
116      * if noResp
117      * sizeof(<NoResp></NoResp>\n) +
118      * if cred != null
119      * sizeof(cred) +
120      * if meta != null
121      * sizeof(meta) +
122      * sizeof(</SyncHdr>\n) +
123      *
124      * @return the XML size of this element
125      */

126     public static long getXMLSize(SyncHdr syncHdr) {
127
128         VerDTD verDTD = syncHdr.getVerDTD() ;
129         VerProto verProto = syncHdr.getVerProto() ;
130         SessionID sessionID = syncHdr.getSessionID();
131         String JavaDoc msgID = syncHdr.getMsgID() ;
132         Target target = syncHdr.getTarget() ;
133         Source source = syncHdr.getSource() ;
134         String JavaDoc respURI = syncHdr.getRespURI() ;
135         boolean noResp = syncHdr.isNoResp() ;
136         Cred cred = syncHdr.getCred() ;
137         Meta meta = syncHdr.getMeta() ;
138
139         return 21
140              + ((verDTD != null) ? getXMLSize(verDTD) : 0)
141              + ((verProto != null) ? getXMLSize(verProto) : 0)
142              + ((sessionID != null) ? getXMLSize(sessionID) : 0)
143              + ((msgID != null) ? 16 + msgID.length() : 0)
144              + ((target != null) ? getXMLSize(target) : 0)
145              + ((source != null) ? getXMLSize(source) : 0)
146              + ((respURI != null) ? 19 + respURI.length() : 90)
147              + (noResp ? 18 : 0)
148              + ((cred != null) ? getXMLSize(cred) : 0)
149              + ((meta != null) ? getXMLSize(meta) : 0)
150              ;
151     }
152
153     /**
154      * Returns the WBXML size of the SyncHdr object
155      *
156      * @param syncHdr the SyncHdr element
157      *
158      * @return size the WBXML size of the SyncHdr element
159      */

160     public static long getWBXMLSize(SyncHdr syncHdr) {
161         VerDTD verDTD = syncHdr.getVerDTD() ;
162         VerProto verProto = syncHdr.getVerProto() ;
163         SessionID sessionID = syncHdr.getSessionID();
164         String JavaDoc msgID = syncHdr.getMsgID() ;
165         Target target = syncHdr.getTarget() ;
166         Source source = syncHdr.getSource() ;
167         String JavaDoc respURI = syncHdr.getRespURI() ;
168         boolean noResp = syncHdr.isNoResp() ;
169         Cred cred = syncHdr.getCred() ;
170         Meta meta = syncHdr.getMeta() ;
171
172         return 4
173              + ((verDTD != null) ? getWBXMLSize(verDTD) : 0)
174              + ((verProto != null) ? getWBXMLSize(verProto) : 0)
175              + ((sessionID != null) ? getWBXMLSize(sessionID) : 0)
176              + ((msgID != null) ? 4 + msgID.length() : 0)
177              + ((target != null) ? getWBXMLSize(target) : 0)
178              + ((source != null) ? getWBXMLSize(source) : 0)
179              + ((respURI != null) ? 4 + respURI.length() : 80)
180              + (noResp ? 1 : 0)
181              + ((cred != null) ? getWBXMLSize(cred) : 0)
182              + ((meta != null) ? getWBXMLSize(meta) : 0)
183              ;
184     }
185
186     // ---------------------------------------------------------------- SyncBody
187
/**
188      * Returns the XML overhead for SyncBody object
189      * sizeof(<SyncBody>\n</SyncBody>\n)
190      *
191      * @return overhead for SyncBody object
192      */

193     public static long getXMLOverheadSyncBody() {
194         return 23;
195     }
196     
197     /**
198      * Returns the WBXML overhead for SyncBody object
199      * sizeof(<SyncBody>\n</SyncBody>\n)
200      *
201      * @return overhead for SyncBody object
202      */

203     public static long getWBXMLOverheadSyncBody() {
204         return 4;
205     }
206     
207     /**
208      * Returns the XML size of the SyncBody object
209      *
210      * sizeof(<SyncBody>\n) +
211      * for (i=0; i<commands.size(); i++)
212      * sizeof(commands[i]) +
213      * if final
214      * sizeof(<Final></Final>\n) +
215      * sizeof(</SyncBody>\n) +
216      * @param syncBody the SyncBody element
217      *
218      * @return size the XML size of the SyncBody element
219      */

220     public static long getXMLSize(SyncBody syncBody) {
221         ArrayList JavaDoc commands = syncBody.getCommands();
222
223         long size = 23
224                   + ((syncBody.isFinalMsg()) ? 16 : 0)
225                   ;
226
227         for (int i=0; i<commands.size(); i++) {
228             size += getCommandXMLSize((AbstractCommand)commands.get(i));
229         }
230         return size;
231     }
232
233     /**
234      * Returns the WBXML size of the SyncBody object
235      *
236      * @param syncBody the SyncBody element
237      *
238      * @return size the WBXML size of the SyncBody element
239      */

240     public static long getWBXMLSize(SyncBody syncBody) {
241         ArrayList JavaDoc commands = syncBody.getCommands();
242
243         long size = 4
244                   + ((syncBody.isFinalMsg()) ? 1 : 0)
245                   ;
246
247        for (int i=0; i<commands.size(); ++i) {
248            size += getCommandWBXMLSize((AbstractCommand)commands.get(i));
249        }
250        return size;
251     }
252
253     // ------------------------------------------------------------------ VerDTD
254
/**
255      * Returns the XML size of VerDTD object:
256      * sizeof(<VerDTD>) +
257      * sizeof(value) +
258      * sizeof(</VerDTD>\n)
259      *
260      * @return the XML size of VerDTD object
261      */

262     public static long getXMLSize(VerDTD verDTD) {
263         return 18
264              + verDTD.getValue().length()
265              ;
266     }
267
268     /**
269      * Returns the WBXML size of VerDTD object
270      *
271      * @return the WBXML size of VerDTD object
272      */

273     public static long getWBXMLSize(VerDTD verDTD) {
274         return 4
275              + verDTD.getValue().length()
276              ;
277     }
278
279     // ---------------------------------------------------------------- VerProto
280
/**
281      * Returns the XML size of VerProto object:
282      * sizeof("<VerProto>") +
283      * sizeof(version) +
284      * sizeof("</VerProto>\n")
285      *
286      * @return the XML size of this object
287      */

288     public static long getXMLSize(VerProto verProto) {
289         return 22
290              + verProto.getVersion().length()
291              ;
292     }
293
294     /**
295      * Returns the WBXML size of VerProto object
296      *
297      * @return the WBXML size of VerProto object
298      */

299     public static long getWBXMLSize(VerProto verProto) {
300         return 4
301              + verProto.getVersion().length()
302              ;
303     }
304
305     // --------------------------------------------------------------- SessionID
306
/**
307      * Returns the XML size of SessionID element as:
308      * sizeof("<SessionID>") +
309      * sizeof(sessionID) +
310      * sizeof("</SessionID>\n")
311      *
312      * @return the XML size of this element
313      */

314     public static long getXMLSize(SessionID sessionID) {
315         return 24
316              + sessionID.getSessionID().length()
317              ;
318     }
319
320     /**
321      * Returns the WBXML size of SessionID object
322      *
323      * @return the WBXML size of SessionID object
324      */

325     public static long getWBXMLSize(SessionID sessionID) {
326         return 4
327              + sessionID.getSessionID().length()
328              ;
329     }
330
331     // ------------------------------------------------------------------ Target
332
/**
333      * Returns the XML size of Target element:
334      * sizeof(<Target>\n) +
335      * if locURI != null
336      * sizeof(<LocURI>) +
337      * sizeof(locURI) +
338      * sizeof(</LocURI>\n) +
339      * if locName != null
340      * sizeof(<LocName>) +
341      * sizeof(locName) +
342      * sizeof(</LocName>\n) +
343      * sizeof(</Target>\n)
344      *
345      * @return the XML size of this element
346      */

347     public static long getXMLSize(Target target) {
348         String JavaDoc locURI = target.getLocURI() ;
349         String JavaDoc locName = target.getLocName();
350
351         return 19
352              + ((locURI != null) ? (18 + locURI.length() ) : 0)
353              + ((locName != null) ? (20 + locName.length()) : 0)
354              ;
355     }
356     /**
357      * Returns the WBXML size of this element.
358      * @return the WBXML size of this element
359      */

360     public static long getWBXMLSize(Target target) {
361         String JavaDoc locURI = target.getLocURI() ;
362         String JavaDoc locName = target.getLocName();
363
364         return 4
365              + ((locURI != null) ? (4 + locURI.length() ) : 0)
366              + ((locName != null) ? (4 + locName.length()) : 0)
367              ;
368     }
369
370     // ------------------------------------------------------------------ Source
371
/**
372      * Returns the XML size of Source element:
373      * sizeof(<Source>\n) +
374      * if locURI != null
375      * sizeof(<LocURI>) +
376      * sizeof(locURI) +
377      * sizeof(</LocURI>\n) +
378      * if locName != null
379      * sizeof(<LocName>) +
380      * sizeof(locName) +
381      * sizeof(</LocName>\n) +
382      * sizeof(</Source>\n)
383      *
384      * @return the XML size of this element
385      */

386     public static long getXMLSize(Source source) {
387         String JavaDoc locURI = source.getLocURI() ;
388         String JavaDoc locName = source.getLocName();
389
390         return 19
391              + ((locURI != null) ? (18 + locURI.length() ) : 0)
392              + ((locName != null) ? (20 + locName.length()) : 0)
393              ;
394     }
395     /**
396      * Returns the WBXML size of this element.
397      * @return the WBXML size of this element
398      */

399     public static long getWBXMLSize(Source source) {
400         String JavaDoc locURI = source.getLocURI() ;
401         String JavaDoc locName = source.getLocName();
402
403         return 4
404              + ((locURI != null) ? (4 + locURI.length() ) : 0)
405              + ((locName != null) ? (4 + locName.length()) : 0)
406              ;
407     }
408
409     // -------------------------------------------------------------------- Cred
410
/**
411      * Returns the XML size of Cred element as:
412      * sizeof(<Cred>\n) +
413      * if meta != null
414      * sizeof(meta) +
415      * if data != null
416      * sizeof(<Data>) +
417      * sizeof(data) +
418      * sizeof(</Data>\n) +
419      * sizeof(</Cred>\n)
420      *
421      * @return the XML size of this element
422      */

423     public static long getXMLSize(Cred cred) {
424         Authentication auth = cred.getAuthentication();
425         Meta meta = auth.getMeta();
426         String JavaDoc data = cred.getData();
427
428         return 15
429              + ((meta != null) ? getXMLSize(meta) : 0)
430              + ((data != null) ? 14 + data.length() : 0)
431              ;
432     }
433
434     /**
435      * Returns the WBXML size of this element.
436      * @return the WBXML size of this element
437      */

438     public static long getWBXMLSize(Cred cred) {
439         Authentication auth = cred.getAuthentication();
440         Meta meta = auth.getMeta();
441         String JavaDoc data = cred.getData();
442
443         return 4
444              + ((meta != null) ? getWBXMLSize(meta) : 0)
445              + ((data != null) ? 4 + data.length() : 0)
446              ;
447     }
448
449     // -------------------------------------------------------------------- Meta
450
/**
451      * Returns the XML size of Meta object.
452      * sizeof(<Meta>\n) +
453      * if format != null
454      * sizeof(<Format>) +
455      * sizeof(format) +
456      * sizeof(</Format>\n) +
457      * if type != null
458      * sizeof(<Type>) +
459      * sizeof(type) +
460      * sizeof(</Type>\n) +
461      * if mark != null
462      * sizeof(mark) +
463      * if size != null
464      * sizeof(<Size>) +
465      * sizeof(size) +
466      * sizeof(</Size>\n) +
467      * if anchor != null
468      * sizeof(anchor) +
469      * if version != null
470      * sizeof(<Version>) +
471      * sizeof(version) +
472      * sizeof(</Version>\n) +
473      * if nextNonce != null
474      * sizeof(nextNonce) +
475      * if maxMsgSize != null
476      * sizeof(<MaxMsgSize>) +
477      * sizeof(maxMsgSize) +
478      * sizeof(</MaxMsgSize>\n) +
479      * if maxObjSize != null
480      * sizeof(<MaxObjSize>) +
481      * sizeof(maxObjSize) +
482      * sizeof(</MaxObjSize>\n) +
483      * for (i=0; emi != null && i<emi.size(); i++)
484      * sizeof(emi[i] +
485      * if mem != null
486      * sizeof(mem) +
487      * sizeof(</Meta>\n)
488      * @return the XML size of Meta object
489      */

490     public static long getXMLSize(Meta meta) {
491         long sizeMeta = 0;
492
493         String JavaDoc format = meta.getFormat() ;
494         String JavaDoc type = meta.getType() ;
495         String JavaDoc mark = meta.getMark() ;
496         Long JavaDoc size = meta.getSize() ;
497         Anchor anchor = meta.getAnchor() ;
498         String JavaDoc version = meta.getVersion() ;
499         NextNonce nextNonce = meta.getNextNonce() ;
500         Long JavaDoc maxMsgSize = meta.getMaxMsgSize();
501         Long JavaDoc maxObjSize = meta.getMaxObjSize();
502         ArrayList JavaDoc emi = meta.getEMI() ;
503         Mem mem = meta.getMem() ;
504
505         sizeMeta = 37
506                  + ((format != null) ? 18 + format.length() : 0)
507                  + ((type != null) ? 14 + type.length() : 0)
508                  + ((mark != null) ? 14 + mark.length() : 0)
509                  + ((size != null) ? 14 + String.valueOf(size).length(): 0)
510                  + ((anchor != null) ? getXMLSize(anchor) : 0)
511                  + ((version != null) ? 20 + version.length() : 0)
512                  + ((nextNonce != null) ? getXMLSize(nextNonce) : 0)
513                  + ((maxMsgSize!= null) ? 26 + String.valueOf(maxMsgSize).length() : 0)
514                  + ((maxObjSize!= null) ? 26 + String.valueOf(maxObjSize).length() : 0)
515                  + ((mem != null) ? getXMLSize(mem) : 0)
516                  ;
517
518     for (int i=0; emi != null && i < emi.size(); i++) {
519             sizeMeta += getXMLSize((EMI)emi.get(i));
520         }
521
522        return sizeMeta;
523     }
524
525
526
527     /**
528      * Returns the WBXML size of this object.
529      *
530      * @return the WBXML size of this object
531      */

532     public static long getWBXMLSize(Meta meta) {
533         long sizeMeta = 0;
534
535         String JavaDoc format = meta.getFormat() ;
536         String JavaDoc type = meta.getType() ;
537         String JavaDoc mark = meta.getMark() ;
538         Long JavaDoc size = meta.getSize() ;
539         Anchor anchor = meta.getAnchor() ;
540         String JavaDoc version = meta.getVersion() ;
541         NextNonce nextNonce = meta.getNextNonce() ;
542         Long JavaDoc maxMsgSize = meta.getMaxMsgSize();
543         Long JavaDoc maxObjSize = meta.getMaxObjSize();
544         ArrayList JavaDoc emi = meta.getEMI() ;
545         Mem mem = meta.getMem() ;
546
547         sizeMeta = 4
548                  + ((format != null) ? 4 + format.length() : 0)
549                  + ((type != null) ? 4 + type.length() : 0)
550                  + ((mark != null) ? 4 + mark.length() : 0)
551                  + ((size != null) ? 4 + String.valueOf(size).length() : 0)
552                  + ((anchor != null) ? getWBXMLSize(anchor) : 0)
553                  + ((version != null) ? 4 + version.length() : 0)
554                  + ((nextNonce != null) ? getWBXMLSize(nextNonce) : 0)
555                  + ((maxMsgSize!= null) ? 4 + String.valueOf(maxMsgSize).length() : 0)
556                  + ((maxObjSize!= null) ? 4 + String.valueOf(maxObjSize).length() : 0)
557                  + ((mem != null) ? getWBXMLSize(mem) : 0)
558                  ;
559
560     for (int i=0; emi != null && i < emi.size(); i++) {
561             sizeMeta += getWBXMLSize((EMI)emi.get(i));
562         }
563
564        return sizeMeta;
565     }
566
567     // ------------------------------------------------------------------ Anchor
568
/**
569      * Returns the XML size of Anchor element as:
570      * sizeof(<Anchor xmlns='syncml:metinf'>\n) +
571      * if last != null
572      * sizeof(<Last>) +
573      * sizeof(last) +
574      * sizeof(</Last>\n) +
575      * if next != null
576      * sizeof(<Next>) +
577      * sizeof(next) +
578      * sizeof(</Next>\n) +
579      * sizeof(</Anchor>\n) +
580      *
581      * @return the XML size of this element
582      */

583     public static long getXMLSize(Anchor anchor) {
584         String JavaDoc last = anchor.getLast();
585         String JavaDoc next = anchor.getNext();
586
587         return 41
588              + ((last != null) ? 14 + last.length() : 0)
589              + ((next != null) ? 14 + next.length() : 0)
590              ;
591     }
592
593     /**
594      * Returns the WBXML size of this element.
595      *
596      * @return the WBXML size of this element
597      */

598     public static long getWBXMLSize(Anchor anchor) {
599         String JavaDoc last = anchor.getLast();
600         String JavaDoc next = anchor.getNext();
601
602         return 25
603              + ((last != null) ? 4 + last.length() : 0)
604              + ((next != null) ? 4 + next.length() : 0)
605              ;
606     }
607
608     // --------------------------------------------------------------------- EMI
609
/**
610      * Returns the XML size of EMI element as:
611      * sizeof(<EMI>) +
612      * sizeof(value) +
613      * sizeof(</EMI>\n)
614      *
615      * @return the XML size of this element
616      */

617     public static long getXMLSize(EMI emi) {
618         return 12
619              + emi.getValue().length()
620              ;
621     }
622
623     /**
624      * Returns the WBXML size of EMI element.
625      *
626      * @return the WBXML size of EMI element
627      */

628     public static long getWBXMLSize(EMI emi) {
629         return 4
630              + emi.getValue().length()
631              ;
632     }
633
634     // --------------------------------------------------------------- NextNonce
635
/**
636      * Returns the XML size of NextNonce element as:
637      * sizeof(<NextNonce>) +
638      * sizeof(value) +
639      * sizeof(</NextNonce>\n)
640      *
641      * @return the XML size of NextNonce element
642      */

643     public static long getXMLSize(NextNonce nextNonce) {
644         return 24
645              + nextNonce.getValueAsBase64().length()
646              ;
647     }
648
649     /**
650      * Returns the WBXML size of NextNonce element.
651      *
652      * @return the WBXML size of NextNonce element
653      */

654     public static long getWBXMLSize(NextNonce nextNonce) {
655         return 4
656              + nextNonce.getValueAsBase64().length()
657              ;
658     }
659
660     // --------------------------------------------------------------------- Mem
661
/**
662      * Returns the XML size of Mem element as:
663      * sizeof("<Mem>\n") +
664      * if sharedMem
665      * sizeof("<Shared></Shared>\n") +
666      * if freeMem
667      * sizeof("<FreeMem>") +
668      * sizeof(freeMem) +
669      * sizeof("</FreeMem>\n") +
670      * if freeID
671      * sizeof("<FreeID>") +
672      * sizeof(freeID) +
673      * sizeof("</FreeID>\n") +
674      * sizeof("</Mem>\n")
675      *
676      * @return the XML size of Mem element
677      */

678     public static long getXMLSize(Mem mem) {
679         boolean sharedMem = mem.isSharedMem();
680         long freeMem = mem.getFreeMem() ;
681         long freeID = mem.getFreeID() ;
682
683         return 13
684              + ((sharedMem) ? 18 : 0)
685              + ((freeMem != 0) ? 20 + String.valueOf(freeMem).length() : 0)
686              + ((freeID != 0) ? 18 + String.valueOf(freeID).length() : 0)
687              ;
688     }
689
690     /**
691      * Returns the WBXML size of Mem object.
692      *
693      * @return the WBXML size of Mem object
694      */

695     public static long getWBXMLSize(Mem mem) {
696         boolean sharedMem = mem.isSharedMem();
697         long freeMem = mem.getFreeMem() ;
698         long freeID = mem.getFreeID() ;
699
700         return 4
701              + ((sharedMem) ? 1 : 0)
702              + ((freeMem != 0) ? 4 + String.valueOf(freeMem).length() : 0)
703              + ((freeID != 0) ? 4 + String.valueOf(freeID).length() : 0)
704              ;
705     }
706
707     // --------------------------------------------------------- AbstractCommand
708
/**
709      * Gets the XML size of all element of AbstractCommand
710      * if cmdID != null
711      * sizeof(cmdID) +
712      * if noResp
713      * sizeof(<NoResp></NoResp>\n) +
714      * if cred != null
715      * sizeof(cred) +
716      * @return the XML size of all element of AbstractCommand
717      */

718     public static long getXMLSize(AbstractCommand command) {
719         CmdID cmdID = command.getCmdID();
720         Cred cred = command.getCred() ;
721
722         return ((cmdID != null) ? getXMLSize(cmdID) : 0)
723              + ((command.isNoResp()) ? 18 : 0)
724              + ((cred != null) ? getXMLSize(cred) : 0)
725              ;
726     }
727
728     /**
729      * Returns the WBXML size of AbstractCommand object.
730      * @return the WBXML size of AbstractCommand object
731      */

732     public static long getWBXMLSize(AbstractCommand command) {
733         CmdID cmdID = command.getCmdID();
734         Cred cred = command.getCred() ;
735
736         return ((cmdID != null) ? getWBXMLSize(cmdID) : 0)
737              + ((command.isNoResp()) ? 1 : 0)
738              + ((cred != null) ? getWBXMLSize(cred) : 0)
739              ;
740     }
741
742     /**
743      * Gets the XML size of the command
744      *
745      * @return the XML size of the command
746      */

747     public static long getCommandXMLSize(AbstractCommand command) {
748         long size = 0;
749         if (command instanceof Add) {
750             size = getXMLSize((Add)command);
751         } else if (command instanceof Alert) {
752             size = getXMLSize((Alert)command);
753         } else if (command instanceof Atomic) {
754             size = getXMLSize((Atomic)command);
755         } else if (command instanceof Copy) {
756             size = getXMLSize((Copy)command);
757         } else if (command instanceof Delete) {
758             size = getXMLSize((Delete)command);
759         } else if (command instanceof Exec) {
760             size = getXMLSize((Exec)command);
761         } else if (command instanceof Get) {
762             size = getXMLSize((Get)command);
763         } else if (command instanceof Map) {
764             size = getXMLSize((Map)command);
765         } else if (command instanceof Put) {
766             size = getXMLSize((Put)command);
767         } else if (command instanceof Replace) {
768             size = getXMLSize((Replace)command);
769         } else if (command instanceof Results) {
770             size = getXMLSize((Results)command);
771         } else if (command instanceof Search) {
772             size = getXMLSize((Search)command);
773         } else if (command instanceof Sequence) {
774             size = getXMLSize((Sequence)command);
775         } else if (command instanceof Status) {
776             size = getXMLSize((Status)command);
777         } else if (command instanceof Sync) {
778             size = getXMLSize((Sync)command);
779         }
780
781         return size;
782     }
783
784     /**
785      * Gets the XML size of the command
786      *
787      * @return the XML size of the command
788      */

789     public static long getCommandWBXMLSize(AbstractCommand command) {
790         long size = 0;
791         if (command instanceof Add) {
792             size = getWBXMLSize((Add)command);
793         } else if (command instanceof Alert) {
794             size = getWBXMLSize((Alert)command);
795         } else if (command instanceof Atomic) {
796             size = getWBXMLSize((Atomic)command);
797         } else if (command instanceof Copy) {
798             size = getWBXMLSize((Copy)command);
799         } else if (command instanceof Delete) {
800             size = getWBXMLSize((Delete)command);
801         } else if (command instanceof Exec) {
802             size = getWBXMLSize((Exec)command);
803         } else if (command instanceof Get) {
804             size = getWBXMLSize((Get)command);
805         } else if (command instanceof Map) {
806             size = getWBXMLSize((Map)command);
807         } else if (command instanceof Put) {
808             size = getWBXMLSize((Put)command);
809         } else if (command instanceof Replace) {
810             size = getWBXMLSize((Replace)command);
811         } else if (command instanceof Results) {
812             size = getWBXMLSize((Results)command);
813         } else if (command instanceof Search) {
814             size = getWBXMLSize((Search)command);
815         } else if (command instanceof Sequence) {
816             size = getWBXMLSize((Sequence)command);
817         } else if (command instanceof Status) {
818             size = getWBXMLSize((Status)command);
819         } else if (command instanceof Sync) {
820             size = getWBXMLSize((Sync)command);
821         }
822
823         return size;
824     }
825
826     // ------------------------------------------------------------------- CmdID
827
/**
828      * Returns the XML size of CmdID element as:
829      * sizeof(<CmdID>) +
830      * sizeof(cmdID) +
831      * sizeof(</CmdID>\n)
832      *
833      * @return the XML size of CmdID element
834      */

835     public static long getXMLSize(CmdID cmdID) {
836         return 16
837              + cmdID.getCmdID().length();
838     }
839
840     /**
841      * Returns the WBXML size of CmdID element.
842      * @return the WBXML size of CmdID element
843      */

844     public static long getWBXMLSize(CmdID cmdID) {
845         return 2
846              + cmdID.getCmdID().length();
847     }
848
849     // --------------------------------------------------------------------- Add
850
/**
851      * Returns the XML size of Add element as:
852      * sizeof(<Add>\n) +
853      * if cmdID != null
854      * sizeof(cmdID) +
855      * if noResp
856      * sizeof(<NoResp></NoResp>\n) +
857      * if cred != null
858      * sizeof(cred) +
859      * if meta != null
860      * sizeof(meta) +
861      * for (int i=0; items != null && i<items.size(); i++)
862      * sizeof(items[i]) +
863      * sizeof(</Add>\n)
864      *
865      * @return the XML size of Add element
866      */

867     public static long getXMLSize(Add add) {
868         Meta meta = add.getMeta() ;
869         ArrayList JavaDoc items = add.getItems();
870
871         long size = 13
872                   + getXMLSize((AbstractCommand)add)
873                   + ((meta != null) ? getXMLSize(meta) : 0)
874                   ;
875         for (int i=0; items != null && i<items.size(); i++) {
876             size += getXMLSize((Item)items.get(i));
877         }
878         return size;
879     }
880
881     /**
882      * Returns the WBXML size of Add element.
883      *
884      * @return the WBXML size of Add element
885      */

886     public static long getWBXMLSize(Add add) {
887         Meta meta = add.getMeta() ;
888         ArrayList JavaDoc items = add.getItems();
889
890         long size = 4
891                   + getWBXMLSize((AbstractCommand)add)
892                   + ((meta != null) ? getWBXMLSize(meta) : 0)
893                   ;
894         for (int i=0; items != null && i<items.size(); i++) {
895             size += getWBXMLSize((Item)items.get(i));
896         }
897         return size;
898     }
899
900     // -------------------------------------------------------------------- Item
901
/**
902      * Returns the XML size of Item element as:
903      * sizeof(<Item>\n) +
904      * if target != null
905      * sizeof(target) +
906      * if source != null
907      * sizeof(source) +
908      * if meta != null
909      * sizeof(meta) +
910      * if data != null
911      * sizeof(data) +
912      * if moreData
913      * sizeof(<MoreData></MoreData>\n) +
914      * sizeof(</Item>\n)
915      *
916      * @return the XML size of Item element
917      */

918     public static long getXMLSize(Item item) {
919         Target target = item.getTarget();
920         Source source = item.getSource();
921         Meta meta = item.getMeta() ;
922         ComplexData data = item.getData() ;
923
924         return 15
925              + ((target != null) ? getXMLSize(target) : 0)
926              + ((source != null) ? getXMLSize(source) : 0)
927              + ((meta != null) ? getXMLSize(meta) : 0)
928              + ((data != null) ? getXMLSize(data) : 0)
929       &nb