KickJava   Java API By Example, From Geeks To Geeks.

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


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 import sync4j.framework.engine.MessageSizeCalculator;
26
27 /**
28  * Utility class for calculate the XML size and WBXML size of framework Objects
29  *
30  * @author Luigia Fassina @ Funambol
31  * @version $Id: WBXMLSizeCalculator.java,v 1.8 2005/04/29 15:32:51 nichele Exp $
32  */

33 public class WBXMLSizeCalculator
34 implements MessageSizeCalculator {
35
36     // ---------------------------------------------------------- Public methods
37

38     // ------------------------------------------------------------------ SyncML
39

40     /**
41      * Returns the default WBXML overhead for the SyncML message
42      *
43      * @return overhead for SyncML message
44      */

45     public long getMsgSizeOverhead() {
46         return 500;
47     }
48
49     /**
50      * Returns the WBXML overhead for SyncML object
51      * sizeof(<SyncML xmlns='SYNCML:SYNCML1.1'>\n</SyncML>\n)
52      *
53      * @return overhead for SyncML object
54      */

55     public long getSyncMLOverhead() {
56         return 29;
57     }
58
59     /**
60      * Returns the WBXML size of the SyncML object
61      *
62      * @param syncML the SyncML element
63      *
64      * @return size the WBXML size of the SyncML element
65      */

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

84     public long getSize(SyncHdr syncHdr) {
85         VerDTD verDTD = syncHdr.getVerDTD() ;
86         VerProto verProto = syncHdr.getVerProto() ;
87         SessionID sessionID = syncHdr.getSessionID();
88         String JavaDoc msgID = syncHdr.getMsgID() ;
89         Target target = syncHdr.getTarget() ;
90         Source source = syncHdr.getSource() ;
91         String JavaDoc respURI = syncHdr.getRespURI() ;
92         boolean noResp = syncHdr.isNoResp() ;
93         Cred cred = syncHdr.getCred() ;
94         Meta meta = syncHdr.getMeta() ;
95
96         return 4
97              + ((verDTD != null) ? getSize(verDTD) : 0)
98              + ((verProto != null) ? getSize(verProto) : 0)
99              + ((sessionID != null) ? getSize(sessionID) : 0)
100              + ((msgID != null) ? 4 + msgID.length() : 0)
101              + ((target != null) ? getSize(target) : 0)
102              + ((source != null) ? getSize(source) : 0)
103              + ((respURI != null) ? 4 + respURI.length(): 80)
104              + (noResp ? 1 : 0)
105              + ((cred != null) ? getSize(cred) : 0)
106              + ((meta != null) ? getSize(meta) : 0)
107              ;
108     }
109     
110     
111     /**
112      * Returns the WBXML overhead of the RespURI element.
113      *
114      * @return the WBXML overhead of the RespURI element.
115      */

116     public long getRespURIOverhead() {
117         return 150;
118     }
119
120     // ---------------------------------------------------------------- SyncBody
121

122     /**
123      * Returns the WBXML overhead for SyncBody object
124      * sizeof(<SyncBody>\n</SyncBody>\n)
125      *
126      * @return overhead for SyncBody object
127      */

128     public long getSyncBodyOverhead() {
129         return 4;
130     }
131     /**
132      * Returns the WBXML size of the SyncBody object
133      *
134      * @param syncBody the SyncBody element
135      *
136      * @return size the WBXML size of the SyncBody element
137      */

138     public long getSize(SyncBody syncBody) {
139         ArrayList JavaDoc commands = syncBody.getCommands();
140
141         long size = 4
142                   + ((syncBody.isFinalMsg()) ? 1 : 0)
143                   ;
144
145        for (int i=0; i<commands.size(); ++i) {
146            size += getCommandSize((AbstractCommand)commands.get(i));
147        }
148        return size;
149     }
150
151     // ------------------------------------------------------------------ VerDTD
152

153     /**
154      * Returns the WBXML size of VerDTD object
155      *
156      * @return the WBXML size of VerDTD object
157      */

158     public long getSize(VerDTD verDTD) {
159         return 4
160              + verDTD.getValue().length()
161              ;
162     }
163
164     // ---------------------------------------------------------------- VerProto
165
/**
166      * Returns the WBXML size of VerProto object
167      *
168      * @return the WBXML size of VerProto object
169      */

170     public long getSize(VerProto verProto) {
171         return 4
172              + verProto.getVersion().length()
173              ;
174     }
175
176     // --------------------------------------------------------------- SessionID
177
/**
178      * Returns the WBXML size of SessionID object
179      *
180      * @return the WBXML size of SessionID object
181      */

182     public long getSize(SessionID sessionID) {
183         return 4
184              + sessionID.getSessionID().length()
185              ;
186     }
187
188     // ------------------------------------------------------------------ Target
189
/**
190      * Returns the WBXML size of this element.
191      * @return the WBXML size of this element
192      */

193     public long getSize(Target target) {
194         String JavaDoc locURI = target.getLocURI() ;
195         String JavaDoc locName = target.getLocName();
196
197         return 4
198              + ((locURI != null) ? (4 + locURI.length() ) : 0)
199              + ((locName != null) ? (4 + locName.length()) : 0)
200              ;
201     }
202
203     // ------------------------------------------------------------------ Source
204
/**
205      * Returns the WBXML size of this element.
206      * @return the WBXML size of this element
207      */

208     public long getSize(Source source) {
209         String JavaDoc locURI = source.getLocURI() ;
210         String JavaDoc locName = source.getLocName();
211
212         return 4
213              + ((locURI != null) ? (4 + locURI.length() ) : 0)
214              + ((locName != null) ? (4 + locName.length()) : 0)
215              ;
216     }
217
218     // -------------------------------------------------------------------- Cred
219

220     /**
221      * Returns the WBXML size of this element.
222      * @return the WBXML size of this element
223      */

224     public long getSize(Cred cred) {
225         Authentication auth = cred.getAuthentication();
226         Meta meta = auth.getMeta();
227         String JavaDoc data = cred.getData();
228
229         return 4
230              + ((meta != null) ? getSize(meta) : 0)
231              + ((data != null) ? 4 + data.length() : 0)
232              ;
233     }
234
235     // -------------------------------------------------------------------- Meta
236

237     /**
238      * Returns the WBXML size of this object.
239      *
240      * @return the WBXML size of this object
241      */

242     public long getSize(Meta meta) {
243         long sizeMeta = 0;
244
245         String JavaDoc format = meta.getFormat() ;
246         String JavaDoc type = meta.getType() ;
247         String JavaDoc mark = meta.getMark() ;
248         Long JavaDoc size = meta.getSize() ;
249         Anchor anchor = meta.getAnchor() ;
250         String JavaDoc version = meta.getVersion() ;
251         NextNonce nextNonce = meta.getNextNonce() ;
252         Long JavaDoc maxMsgSize = meta.getMaxMsgSize();
253         Long JavaDoc maxObjSize = meta.getMaxObjSize();
254         ArrayList JavaDoc emi = meta.getEMI() ;
255         Mem mem = meta.getMem() ;
256
257         sizeMeta = 4
258                  + ((format != null) ? 4 + format.length() : 0)
259                  + ((type != null) ? 4 + type.length() : 0)
260                  + ((mark != null) ? 4 + mark.length() : 0)
261                  + ((size != null) ? 4 + String.valueOf(size).length() : 0)
262                  + ((anchor != null) ? getSize(anchor) : 0)
263                  + ((version != null) ? 4 + version.length() : 0)
264                  + ((nextNonce != null) ? getSize(nextNonce) : 0)
265                  + ((maxMsgSize!= null) ? 4 + String.valueOf(maxMsgSize).length() : 0)
266                  + ((maxObjSize!= null) ? 4 + String.valueOf(maxObjSize).length() : 0)
267                  + ((mem != null) ? getSize(mem) : 0)
268                  ;
269
270     for (int i=0; emi != null && i < emi.size(); i++) {
271             sizeMeta += getSize((EMI)emi.get(i));
272         }
273
274        return sizeMeta;
275     }
276
277     // ------------------------------------------------------------------ Anchor
278

279     /**
280      * Returns the WBXML size of this element.
281      *
282      * @return the WBXML size of this element
283      */

284     public long getSize(Anchor anchor) {
285         String JavaDoc last = anchor.getLast();
286         String JavaDoc next = anchor.getNext();
287
288         return 25
289              + ((last != null) ? 4 + last.length() : 0)
290              + ((next != null) ? 4 + next.length() : 0)
291              ;
292     }
293
294     // --------------------------------------------------------------------- EMI
295
/**
296      * Returns the WBXML size of EMI element.
297      *
298      * @return the WBXML size of EMI element
299      */

300     public long getSize(EMI emi) {
301         return 4
302              + emi.getValue().length()
303              ;
304     }
305
306     // --------------------------------------------------------------- NextNonce
307
/**
308      * Returns the WBXML size of NextNonce element.
309      *
310      * @return the WBXML size of NextNonce element
311      */

312     public long getSize(NextNonce nextNonce) {
313         return 4
314              + nextNonce.getValueAsBase64().length()
315              ;
316     }
317
318     // --------------------------------------------------------------------- Mem
319
/**
320      * Returns the WBXML size of Mem object.
321      *
322      * @return the WBXML size of Mem object
323      */

324     public long getSize(Mem mem) {
325         boolean sharedMem = mem.isSharedMem();
326         long freeMem = mem.getFreeMem() ;
327         long freeID = mem.getFreeID() ;
328
329         return 4
330              + ((sharedMem) ? 1 : 0)
331              + ((freeMem != 0) ? 4 + String.valueOf(freeMem).length() : 0)
332              + ((freeID != 0) ? 4 + String.valueOf(freeID).length() : 0)
333              ;
334     }
335
336     // --------------------------------------------------------- AbstractCommand
337
/**
338      * Returns the WBXML size of AbstractCommand object.
339      * @return the WBXML size of AbstractCommand object
340      */

341     public long getSize(AbstractCommand command) {
342         CmdID cmdID = command.getCmdID();
343         Cred cred = command.getCred() ;
344
345         return ((cmdID != null) ? getSize(cmdID) : 0)
346              + ((command.isNoResp()) ? 1 : 0)
347              + ((cred != null) ? getSize(cred) : 0)
348              ;
349     }
350
351     /**
352      * Gets the XML size of the command
353      *
354      * @return the XML size of the command
355      */

356     public long getCommandSize(AbstractCommand command) {
357         long size = 0;
358         if (command instanceof Add) {
359             size = getSize((Add)command);
360         } else if (command instanceof Alert) {
361             size = getSize((Alert)command);
362         } else if (command instanceof Atomic) {
363             size = getSize((Atomic)command);
364         } else if (command instanceof Copy) {
365             size = getSize((Copy)command);
366         } else if (command instanceof Delete) {
367             size = getSize((Delete)command);
368         } else if (command instanceof Exec) {
369             size = getSize((Exec)command);
370         } else if (command instanceof Get) {
371             size = getSize((Get)command);
372         } else if (command instanceof Map) {
373             size = getSize((Map)command);
374         } else if (command instanceof Put) {
375             size = getSize((Put)command);
376         } else if (command instanceof Replace) {
377             size = getSize((Replace)command);
378         } else if (command instanceof Results) {
379             size = getSize((Results)command);
380         } else if (command instanceof Search) {
381             size = getSize((Search)command);
382         } else if (command instanceof Sequence) {
383             size = getSize((Sequence)command);
384         } else if (command instanceof Status) {
385             size = getSize((Status)command);
386         } else if (command instanceof Sync) {
387             size = getSize((Sync)command);
388         }
389
390         return size;
391     }
392
393     // ------------------------------------------------------------------- CmdID
394
/**
395      * Returns the WBXML size of CmdID element.
396      * @return the WBXML size of CmdID element
397      */

398     public long getSize(CmdID cmdID) {
399         return 2
400              + cmdID.getCmdID().length();
401     }
402
403     // --------------------------------------------------------------------- Add
404
/**
405      * Returns the WBXML size of Add element.
406      *
407      * @return the WBXML size of Add element
408      */

409     public long getSize(Add add) {
410         Meta meta = add.getMeta() ;
411         ArrayList JavaDoc items = add.getItems();
412
413         long size = 4
414                   + getSize((AbstractCommand)add)
415                   + ((meta != null) ? getSize(meta) : 0)
416                   ;
417         for (int i=0; items != null && i<items.size(); i++) {
418             size += getSize((Item)items.get(i));
419         }
420         return size;
421     }
422
423     // -------------------------------------------------------------------- Item
424
/**
425      * Returns the WBXML size of Item element.
426      * @return the WBXML size of Item element
427      */

428     public long getSize(Item item) {
429         Target target = item.getTarget();
430         Source source = item.getSource();
431         Meta meta = item.getMeta() ;
432         ComplexData data = item.getData() ;
433
434         return 4
435              + ((target != null) ? getSize(target) : 0)
436              + ((source != null) ? getSize(source) : 0)
437              + ((meta != null) ? getSize(meta) : 0)
438              + ((data != null) ? getSize(data) : 0)
439              + ((item.isMoreData()) ? 1 : 0)
440              ;
441     }
442
443     // ------------------------------------------------------------- ComplexData
444
/**
445      * Returns the WBXML size of ComplexData element.
446      *
447      * @return the WBXML size of ComplexData element
448      */

449     public long getSize(ComplexData complexData) {
450         String JavaDoc data = complexData.getData() ;
451         Anchor anchor = complexData.getAnchor();
452         DevInf devInf = complexData.getDevInf();
453
454         return 4
455              + ((data != null) ? data.length() :0)
456              + ((anchor != null) ? getSize(anchor) :0)
457              + ((devInf != null) ? getSize(devInf) :0)
458              ;
459     }
460
461     // -------------------------------------------------------------------- Data
462
/**
463      * Returns the WBXML size of Data element.
464      *
465      * @return the WBXML size of Data element
466      */

467     public long getSize(Data data) {
468         return 4
469              + data.getData().length();
470     }
471
472     // -------------------------------------------------------------- DevInfData
473
/**
474      * Returns the WBXML size of DevInfData element.
475      *
476      * @return the WBXML size of DevInfData element
477      */

478     public long getSize(DevInfData devInfData) {
479         DevInf devInf = devInfData.getDevInf();
480         return 4
481              + ((devInf != null) ? getSize(devInf) : 0)
482              ;
483     }
484
485     // ------------------------------------------------------------------ DevInf
486
/**
487      * Returns the WBXML size of DevInf element.
488      *
489      * @return the WBXML size of DevInf element
490      */

491     public long getSize(DevInf devInf) {
492         VerDTD verDTD = devInf.getVerDTD() ;
493         String JavaDoc man = devInf.getMan() ;
494         String JavaDoc mod = devInf.getMod() ;
495         String JavaDoc oem = devInf.getOEM() ;
496         String JavaDoc fwV = devInf.getFwV() ;
497         String JavaDoc swV = devInf.getSwV() ;
498         String JavaDoc hwV = devInf.getHwV() ;
499         String JavaDoc devID = devInf.getDevID() ;
500         String JavaDoc devTyp = devInf.getDevTyp() ;
501         ArrayList JavaDoc dataStores = devInf.getDataStore();
502         ArrayList JavaDoc ctCaps = devInf.getCTCap() ;
503         ArrayList JavaDoc exts = devInf.getExt() ;
504
505         long size = 0;
506
507         for (int i=0; dataStores != null && i<dataStores.size(); i++) {
508             size += getSize((DataStore)dataStores.get(i));
509         }
510         for (int i=0; ctCaps != null && i<ctCaps.size(); i++) {
511             size += getSize((CTCap)ctCaps.get(i));
512         }
513         for (int i=0; exts != null && i<exts.size(); i++) {
514             size += getSize((Ext)exts.get(i));
515         }
516
517         return 4
518              + ((verDTD != null) ? getSize(verDTD) : 0)
519              + ((man != null) ? 4 + man.length() : 0)
520              + ((mod != null) ? 4 + mod.length() : 0)
521              + ((oem != null) ? 4 + oem.length() : 0)
522              + ((fwV != null) ? 4 + fwV.length() : 0)
523              + ((swV != null) ? 4 + swV.length() : 0)
524              + ((hwV != null) ? 4 + hwV.length() : 0)
525              + ((devID != null) ? 4 + devID.length() : 0)
526              + ((devTyp != null) ? 4 + devTyp.length() : 0)
527              + ((devInf.isUTC()) ? 1 : 0)
528              + ((devInf.isSupportLargeObjs()) ? 1 : 0)
529              + ((devInf.isSupportNumberOfChanges()) ? 1 : 0)
530              + size;
531     }
532
533     // --------------------------------------------------------------- DataStore
534
/**
535      * Returns the WBXML size of DataStore element.
536      *
537      * @return the WBXML size of DataStore element
538      */

539     public long getSize(DataStore dataStore) {
540         SourceRef sourceRef = dataStore.getSourceRef() ;
541         String JavaDoc displayName = dataStore.getDisplayName();
542         long maxGUIDSize = dataStore.getMaxGUIDSize();
543         ContentTypeInfo rxPref = dataStore.getRxPref() ;
544         ArrayList JavaDoc rxs = dataStore.getRx() ;
545         ContentTypeInfo txPref = dataStore.getTxPref() ;
546         ArrayList JavaDoc txs = dataStore.getTx() ;
547         DSMem dsMem = dataStore.getDSMem() ;
548         SyncCap syncCap = dataStore.getSyncCap() ;
549
550         long size = 0;
551
552         for (int i=0; rxs != null && i<rxs.size(); i++) {
553             size += 4 + getSize((ContentTypeInfo)rxs.get(i));
554         }
555         for (int i=0; txs != null && i<txs.size(); i++) {
556             size += 4 + getSize((ContentTypeInfo)txs.get(i));
557         }
558
559         return 4
560              + ((sourceRef != null) ? getSize(sourceRef) : 0)
561              + ((displayName != null && displayName.length() != 0)
562                              ? 1 + displayName.length() : 0)
563              + ((maxGUIDSize > 0)
564                              ? 4 + String.valueOf(maxGUIDSize).length() : 0)
565              + ((rxPref != null) ? 4 + getSize(rxPref) : 0)
566              + ((txPref != null) ? 4 + getSize(txPref) : 0)
567              + ((dsMem != null) ? getSize(dsMem) : 0)
568              + ((syncCap != null) ? getSize(syncCap) : 0)
569              + size
570              ;
571     }
572
573     // --------------------------------------------------------- ContentTypeInfo
574
/**
575      * Returns the WBXML size of ContentTypeInfo element.
576      *
577      * @return the WBXML size of ContentTypeInfo element
578      */

579     public long getSize(ContentTypeInfo contentTypeInfo) {
580         String JavaDoc ctType = contentTypeInfo.getCTType();
581         String JavaDoc verCT = contentTypeInfo.getVerCT() ;
582
583         return ((ctType != null) ? 4 + ctType.length() : 0)
584              + ((verCT != null) ? 4 + verCT.length() : 0)
585              ;
586     }
587
588     // --------------------------------------------------------------- SourceRef
589
/**
590      * Returns the WBXML size of SourceRef element.
591      * @return the WBXML size of SourceRef element
592      */

593     public long getSize(SourceRef sourceRef) {
594         String JavaDoc value = sourceRef.getValue() ;
595         Source source = sourceRef.getSource();
596
597         return 4
598              + ((value != null) ? value.length() : 0)
599              + ((source != null) ? getSize(source) : 0)
600              ;
601     }
602
603     // ------------------------------------------------------------------- DSMem
604
/**
605      * Returns the WBXML size of DSMem element
606      *
607      * @return the WBXML size of DSMem element
608      */

609     public long getSize(DSMem dsMem) {
610         long maxMem = dsMem.getMaxMem();
611         long maxID = dsMem.getMaxID() ;
612
613         return 4
614              + ((dsMem.isSharedMem()) ? 1 :0)
615              + ((maxMem >=0) ? 4 + String.valueOf(maxMem).length() :0)
616              + ((maxID >=0) ? 4 + String.valueOf(maxID).length() :0)
617              ;
618     }
619
620     // ----------------------------------------------------------------- SyncCap
621
/**
622      * Returns the WBXML size of SyncCap object.
623      *
624      * @return the WBXML size of SyncCap object
625      */

626     public long getSize(SyncCap syncCap) {
627         ArrayList JavaDoc syncTypes = syncCap.getSyncType();
628         long size = 4;
629
630         for (int i=0; i<syncTypes.size(); ++i) {
631             size += getSize((SyncType)syncTypes.get(i));
632         }
633         return size;
634     }
635
636     // ---------------------------------------------------------------- SyncType
637
/**
638      * Returns the WBXML size of SyncType object.
639      *
640      * @return the WBXML size of SyncType object
641      */

642     public long getSize(SyncType syncType) {
643        return 4
644             + String.valueOf(syncType.getType()).length()
645             ;
646     }
647
648     // ------------------------------------------------------------------- CTCap
649
/**
650      * Returns the WBXML size of CTCap element.
651      *
652      * @return the WBXML size of CTCap element
653      */

654     public long getSize(CTCap ctCap) {
655         ArrayList JavaDoc ctTypeSup = ctCap.getCTTypeSupported();
656         long size = 4;
657
658         for (int i=0; ctTypeSup != null && i<ctTypeSup.size(); i++) {
659             size += getSize((CTTypeSupported)ctTypeSup.get(i));
660         }
661         return size;
662     }
663
664     // --------------------------------------------------------- CTTypeSupported
665
/**
666      * Returns the WBXML size of this element.
667      *
668      * @return the WBXML size of this element
669      */

670     public long getSize(CTTypeSupported ctTypeSupported) {
671         String JavaDoc ctType = ctTypeSupported.getCTType() ;
672         ArrayList JavaDoc ctPropParams = ctTypeSupported.getCTPropParams();
673         long size = 0;
674
675         for (int i=0; ctPropParams != null && i<ctPropParams.size(); i++) {
676             size += getSize((CTPropParam)ctPropParams.get(i));
677         }
678         return ((ctType != null) ? 4 + ctType.length() : 0)
679              + size
680              ;
681     }
682
683     // ------------------------------------------------------------- CTPropParam
684
/**
685      * Returns the WBXML size of CTPropParam element.
686      *
687      * @return the WBXML size of CTPropParam element
688      */

689     public long getSize(CTPropParam ctPropParam) {
690         String JavaDoc propName = ctPropParam.getPropName() ;
691         ArrayList JavaDoc valEnums = ctPropParam.getValEnum() ;
692         String JavaDoc dataType = ctPropParam.getDataType() ;
693         int size = ctPropParam.getSize() ;
694         String JavaDoc displayName = ctPropParam.getDisplayName() ;
695         ArrayList JavaDoc ctParameters = ctPropParam.getContentTypeParameters();
696
697         long sizeCTPP = 0;
698         for (int i=0; valEnums != null && i<valEnums.size(); i++) {
699             sizeCTPP += 4 + ((String JavaDoc)valEnums.get(i)).length();
700         }
701
702         for (int i=0; ctParameters!=null && i<ctParameters.size(); i++) {
703             sizeCTPP += getSize((ContentTypeParameter)ctParameters.get(i));
704         }
705
706         return ((propName != null) ? 4 + propName.length() : 0)
707              + ((dataType != null) ? 4 + dataType.length() : 0)
708              + ((size != 0 ) ? 4 + String.valueOf(size).length() : 0)
709              + ((displayName != null) ? 4 + displayName.length() : 0)
710              + sizeCTPP
711              ;
712     }
713
714     // ---------------------------------------------------- ContentTypeParameter
715
/**
716      * Returns the WBXML size of ContentTypeParameter element.
717      *
718      * @return the WBXML size of ContentTypeParameter element
719      */

720     public long getSize(ContentTypeParameter ctParameter) {
721         String JavaDoc paramName = ctParameter.getParamName() ;
722         ArrayList JavaDoc valEnums = ctParameter.getValEnum() ;
723         String JavaDoc dataType = ctParameter.getDataType() ;
724         int size = ctParameter.getSize() ;
725         String JavaDoc displayName = ctParameter.getDisplayName();
726         long sizeCTP = 0;
727
728         for (int i=0; valEnums != null && i<valEnums.size(); i++) {
729             sizeCTP += 4 + ((String JavaDoc)valEnums.get(i)).length();
730         }
731
732         return ((paramName != null) ? 4 + paramName.length() : 0)
733              + ((dataType != null) ? 4 + dataType.length() : 0)
734              + ((size != 0 ) ? 4 + String.valueOf(size).length() : 0)
735              + ((displayName != null) ? 4 + displayName.length() : 0)
736              + sizeCTP
737              ;
738     }
739
740     // --------------------------------------------------------------------- Ext
741
/**
742      * Returns the WBXML size of Ext element.
743      *
744      * @return the WBXML size of Ext element
745      */

746     public long getSize(Ext ext) {
747         String JavaDoc name = ext.getXNam();
748         ArrayList JavaDoc values = ext.getXVal();
749         long size = 4;
750
751         for (int i=0; values != null && i<values.size(); i++) {
752             size += 4 + ((String JavaDoc)values.get(i)).length();
753         }
754
755         return ((name != null) ? 4 + name.length() : 0)
756              + size
757              ;
758     }
759     // ------------------------------------------------------------------- Alert
760
/**
761      * Returns the WBXML size of Alert element.
762      *
763      * @return the WBXML size of Alert element
764      */

765     public long getSize(Alert alert) {
766         int data = alert.getData() ;
767         ArrayList JavaDoc items = alert.getItems();
768
769         long size = 4
770                   + getSize((AbstractCommand)alert)
771                   + ((data != 0) ? 2 + String.valueOf(data).length() : 0)
772                   ;
773         for (int i=0; items != null && i<items.size(); i++) {
774             size += getSize((Item)items.get(i));
775         }
776         return size;
777     }
778
779     // ------------------------------------------------------------------ Atomic
780
/**
781      * Returns the WBXML size of Atomic element.
782      *
783      * @return the WBXML size of Atomic element
784      */

785     public long getSize(Atomic atomic) {
786         Meta meta = atomic.getMeta() ;
787         ArrayList JavaDoc commands = atomic.getCommands();
788
789         long size = 4
790                   + getSize((AbstractCommand)atomic)
791                   + ((meta != null) ? getSize(meta) : 0)
792                   ;
793         for (int i=0; commands != null && i<commands.size(); i++) {
794             size += getCommandSize((AbstractCommand)commands.get(i));
795         }
796         return size;
797     }
798
799     // -------------------------------------------------------------------- Copy
800
/**
801      * Returns the WBXML size of Copy element.
802      *
803      * @return the WBXML size of Copy element
804      */

805     public long getSize(Copy copy) {
806         Meta meta = copy.getMeta() ;
807         ArrayList JavaDoc items = copy.getItems();
808
809         long size = 4
810                   + getSize((AbstractCommand)copy)
811                   + ((meta != null) ? getSize(meta) : 0)
812                   ;
813         for (int i=0; items != null && i<items.size(); i++) {
814             size += getSize((Item)items.get(i));
815         }
816         return size;
817     }
818
819     // ------------------------------------------------------------------ Delete
820
/**
821      * Returns the WBXML size of Delete element.
822      *
823      * @return the WBXML size of Delete element
824      */

825     public long getSize(Delete delete) {
826         Meta meta = delete.getMeta() ;
827         ArrayList JavaDoc items = delete.getItems();
828
829         long size = 4
830                   + getSize((AbstractCommand)delete)
831                   + ((delete.isArchive()) ? 1 : 0)
832                   + ((delete.isSftDel() ) ? 1 : 0)
833                   + ((meta != null ) ? getSize(meta) : 0)
834                   ;
835         for (int i=0; items != null && i<items.size(); i++) {
836             size += getSize((Item)items.get(i));
837         }
838         return size;
839     }
840
841     // -------------------------------------------------------------------- Exec
842
/**
843      * Returns the WBXML size of Exec element.
844      *
845      * @return the WBXML size of Exec element
846      */

847     public long getSize(Exec exec) {
848         ArrayList JavaDoc items = exec.getItems();
849
850         long size = 4
851                   + getSize((AbstractCommand)exec)
852                   ;
853         for (int i=0; items != null && i<items.size(); i++) {
854             size += getSize((Item)items.get(i));
855         }
856         return size;
857     }
858
859     // --------------------------------------------------------------------- Get
860
/**
861      * Returns the WBXML size of Get element.
862      *
863      * @return the WBXML size of Get element
864      */

865     public long getSize(Get get) {
866         String JavaDoc lang = get.getLang();
867         Meta meta = get.getMeta() ;
868         ArrayList JavaDoc items = get.getItems();
869
870         long size = 4
871                   + getSize((AbstractCommand)get)
872                   + ((lang != null) ? 1 + lang.length() : 0)
873                   + ((meta != null) ? getSize(meta) : 0)
874                   ;
875         for (int i=0; items != null && i<items.size(); i++) {
876             size += getSize((Item)items.get(i));
877         }
878         return size;
879     }
880
881     // --------------------------------------------------------------------- Map
882
/**
883      * Returns the WBXML size of Map element.
884      *
885      * @return the WBXML size of Map element
886      */

887     public long getSize(Map map) {
888         Target target = map.getTarget();
889         Source source = map.getSource();
890         Meta meta = map.getMeta() ;
891         ArrayList JavaDoc mapItems = map.getMapItems();
892
893         long size = 4
894                   + getSize((AbstractCommand)map)
895                   + ((target != null) ? getSize(target) : 0)
896                   + ((source != null) ? getSize(source) : 0)
897                   + ((meta != null) ? getSize(meta) : 0)
898                   ;
899         for (int i=0; mapItems != null && i<mapItems.size(); i++) {
900             size += getSize((MapItem)mapItems.get(i));
901         }
902         return size;
903     }
904
905     // ----------------------------------------------------------------- MapItem
906
/**
907      * Returns the WBXML size of MapItem element.
908      *
909      * @return the WBXML size of MapItem element
910      */

911     public long getSize(MapItem mapItem) {
912         Target target = mapItem.getTarget();
913         Source source = mapItem.getSource();
914
915         return 2
916              + ((target != null) ? getSize(target) : 0)
917              + ((source != null) ? getSize(source) : 0)
918              ;
919     }
920
921     // --------------------------------------------------------------------- Put
922
/**
923      * Returns the WBXML size of Put element.
924      *
925      * @return the WBXML size of Put element
926      */

927     public long getSize(Put put) {
928         String JavaDoc lang = put.getLang();
929         Meta meta = put.getMeta() ;
930         ArrayList JavaDoc devInfItems = put.getItems();
931
932         long size = 4
933                   + getSize((AbstractCommand)put)
934                   + ((lang != null) ? 1 + lang.length() : 0)
935                   + ((meta != null) ? getSize(meta) : 0)
936                   ;
937         for (int i=0; devInfItems != null && i<devInfItems.size(); i++) {
938             size += getSize((DevInfItem)devInfItems.get(i));
939         }
940         return size;
941     }
942
943     // -------------------------------------------------------------- DevInfItem
944
/**
945      * Returns the WBXML size of Item element.
946      * @return the WBXML size of Item element
947      */

948     public long getSize(DevInfItem devInfItem) {
949         Target target = devInfItem.getTarget() ;
950         Source source = devInfItem.getSource() ;
951         Meta meta = devInfItem.getMeta() ;
952         DevInfData devInfData = devInfItem.getDevInfData();
953
954         return 4
955              + ((target != null) ? getSize(target) : 0)
956              + ((source != null) ? getSize(source) : 0)
957              + ((meta != null) ? getSize(meta) : 0)
958              + ((devInfData != null) ? getSize(devInfData) : 0)
959              ;
960     }
961
962     // ----------------------------------------------------------------- Replace
963
/**
964      * Returns the WBXML size of Replace element.
965      *
966      * @return the WBXML size of Replace element
967      */

968     public long getSize(Replace replace) {
969         Meta meta = replace.getMeta() ;
970         ArrayList JavaDoc items = replace.getItems();
971
972         long size = 4
973                   + getSize((AbstractCommand)replace)
974                   + ((meta != null) ? getSize(meta) : 0)
975                   ;
976         for (int i=0; items != null && i<items.size(); i++) {
977             size += getSize((Item)items.get(i));
978         }
979         return size;
980     }
981
982     // ----------------------------------------------------------------- Results
983
/**
984      * Returns the WBXML size of Results element.
985      *
986      * @return the WBXML size of Results element
987      */

988     public long getSize(Results results) {
989         String JavaDoc msgRef = results.getMsgRef() ;
990         String JavaDoc cmdRef = results.getCmdRef() ;
991         Meta meta = results.getMeta() ;
992         ArrayList JavaDoc targetRefs = results.getTargetRef();
993         ArrayList JavaDoc sourceRefs = results.getSourceRef();
994         ArrayList JavaDoc items = results.getItems() ;
995
996         long size = 4
997                   + getSize((AbstractCommand)results)
998                   + ((msgRef != null) ? 4 + msgRef.length() : 0)
999                   + ((cmdRef != null) ? 4 + cmdRef.length() : 0)
1000                  + ((meta != null) ? getSize(meta) : 0)
1001                  ;
1002        for (int i=0; targetRefs != null && i<targetRefs.size(); i++) {
1003            size += getSize((TargetRef)targetRefs.get(i));
1004        }
1005        for (int i=0; sourceRefs != null && i<sourceRefs.size(); i++) {
1006            size += getSize((SourceRef)sourceRefs.get(i));
1007        }
1008        for (int i=0; items != null && i<items.size(); i++) {
1009            size += getSize((Item)items.get(i));
1010        }
1011        return size;
1012    }
1013
1014    // --------------------------------------------------------------- TargetRef
1015
/**
1016     * Returns the WBXML size of TargetRef element.
1017     * @return the WBXML size of TargetRef element
1018     */

1019    public long getSize(TargetRef targetRef) {
1020        String JavaDoc value = targetRef.getValue() ;
1021        Target target = targetRef.getTarget();
1022
1023        return 4
1024             + ((value != null) ? value.length() : 0)
1025             + ((target != null) ? getSize(target) : 0)
1026             ;
1027    }
1028
1029    // ------------------------------------------------------------------ Search
1030
/**
1031     * Returns the WBXML size of Search element.
1032     *
1033     * @return the WBXML size of Search element
1034     */

1035    public long getSize(Search search) {
1036        Target target = search.getTarget() ;
1037        ArrayList JavaDoc sources = search.getSources();
1038        String JavaDoc lang = search.getLang() ;
1039        Meta meta = search.getMeta() ;
1040        Data data = search.getData() ;
1041
1042        long size =
1043                  + getSize((AbstractCommand)search)
1044                  + ((search.isNoResults()) ? 1 : 0)
1045                  + ((target != null) ? getSize(target) : 0)
1046                  + ((lang != null) ? 1 + lang.length() : 0)
1047                  + ((meta != null) ? getSize(meta) : 0)
1048                  + ((data != null) ? getSize(data) : 0)
1049                  ;
1050        for (int i=0; sources != null && i<sources.size(); i++) {
1051            size += getSize((Source)sources.get(i));
1052        }
1053        return size;
1054    }
1055
1056    // ---------------------------------------------------------------- Sequence
1057
/**
1058     * Returns the WBXML size of Sequence element.
1059     *
1060     * @return the WBXML size of Sequence element
1061     */

1062    public long getSize(Sequence sequence) {
1063        Meta meta = sequence.getMeta() ;
1064        ArrayList JavaDoc commands = sequence.getCommands();
1065
1066        long size = 4
1067                  + getSize((AbstractCommand)sequence)
1068                  + ((meta != null) ? getSize(meta) : 0)
1069                  ;
1070        for (int i=0; commands != null && i<commands.size(); i++) {
1071            size += getCommandSize((AbstractCommand)commands.get(i));
1072        }
1073        return size;
1074    }
1075
1076    // ------------------------------------------------------------------ Status
1077
/**
1078     * Returns the WBXML size of Status element.
1079     *
1080     * @return the WBXML size of Status element
1081     */

1082    public long getSize(Status status) {
1083        CmdID cmdID = status.getCmdID() ;
1084        String JavaDoc msgRef = status.getMsgRef() ;
1085        String JavaDoc cmdRef = status.getCmdRef() ;
1086        String JavaDoc cmd = status.getCmd() ;
1087        ArrayList JavaDoc targetRefs = status.getTargetRef();
1088        ArrayList JavaDoc sourceRefs = status.getSourceRef();
1089        Cred cred = status.getCred() ;
1090        Chal chal = status.getChal() ;
1091        Data data = status.getData() ;
1092        ArrayList JavaDoc items = status.getItems() ;
1093
1094        long size = 4
1095                  + ((cmdID != null) ? getSize(cmdID) : 0)
1096                  + ((msgRef != null) ? 4 + msgRef.length() : 0)
1097                  + ((cmdRef != null) ? 4 + cmdRef.length() : 0)
1098                  + ((cmd != null) ? 4 + cmd.length() : 0)
1099                  + ((cred != null) ? getSize(cred) : 0)
1100                  + ((chal != null) ? getSize(chal) : 0)
1101                  + ((data != null) ? getSize(data) : 0)
1102                  ;
1103        for (int i=0; targetRefs != null && i<targetRefs.size(); i++) {
1104            size += getSize((TargetRef)targetRefs.get(i));
1105        }
1106        for (int i=0; sourceRefs != null && i<sourceRefs.size(); i++) {
1107            size += getSize((SourceRef)sourceRefs.get(i));
1108        }
1109        for (int i=0; items != null && i<items.size(); i++) {
1110            size += getSize((Item)items.get(i));
1111        }
1112        return size;
1113    }
1114    // -------------------------------------------------------------------- Chal
1115
/**
1116     * Returns the WBXML size of Chal element.
1117     *
1118     * @return the WBXML size of Chal element
1119     */

1120    public long getSize(Chal chal) {
1121        Meta meta = chal.getMeta();
1122
1123        return 4
1124             + ((meta != null) ? getSize(meta) : 0)
1125             ;
1126    }
1127
1128    // -------------------------------------------------------------------- Sync
1129
/**
1130     * Returns the WBXML size of Sync element.
1131     *
1132     * @return the WBXML size of Sync element
1133     */

1134    public long getSize(Sync sync) {
1135        Target target = sync.getTarget() ;
1136        Source source = sync.getSource() ;
1137        Meta meta = sync.getMeta() ;
1138        Long JavaDoc numberOfChanges = sync.getNumberOfChanges();
1139        ArrayList JavaDoc commands = sync.getCommands() ;
1140        
1141        long size = 4
1142                  + getSize((AbstractCommand)sync)
1143                  + ((target != null) ? getSize(target) : 0)
1144                  + ((source != null) ? getSize(source) : 0)
1145                  + ((meta != null) ? getSize(meta) : 0)
1146                  + ((numberOfChanges != null) ? 4 : 0)
1147                  ;
1148        for (int i=0; commands != null && i<commands.size(); i++) {
1149            size += getCommandSize((AbstractCommand)commands.get(i));
1150        }
1151        return size;
1152    }
1153
1154    // --------------------------------------------------------- ItemizedCommand
1155
/**
1156     * Returns the WBXML size of the ItemizedCommand element
1157     */

1158    public long getSize(ItemizedCommand itemCmd) {
1159        Meta meta = itemCmd.getMeta() ;
1160        ArrayList JavaDoc items = itemCmd.getItems();
1161        long size = 0;
1162
1163        size = getSize((AbstractCommand)itemCmd)
1164             + ((meta != null) ? getSize(meta) : 0)
1165             ;
1166
1167        for (int i=0; items != null && i<items.size(); i++) {
1168            size += getSize((Item)items.get(i));
1169        }
1170        return size;
1171    }
1172
1173    // ----------------------------------------------------- ModificationCommand
1174
/**
1175     * Returns the WBXML size of ModificationCommand object.
1176     *
1177     * @return the WBXML size of ModificationCommand object
1178     */

1179    public long getSize(ModificationCommand modCmd) {
1180        return getSize((ItemizedCommand)modCmd);
1181    }
1182
1183    // --------------------------------------------------------- ResponseCommand
1184
/**
1185     * Returns the WBXML size of ResponseCommand object.
1186     *
1187     * @return the WBXML size of ResponseCommand object
1188     */

1189    public long getSize(ResponseCommand responseCmd) {
1190        String JavaDoc msgRef = responseCmd.getMsgRef() ;
1191        String JavaDoc cmdRef = responseCmd.getCmdRef() ;
1192        ArrayList JavaDoc targetRefs = responseCmd.getTargetRef();
1193        ArrayList JavaDoc sourceRefs = responseCmd.getSourceRef();
1194        long size = 0;
1195
1196        size = getSize((ItemizedCommand)responseCmd)
1197             + ((msgRef != null) ? 4 + msgRef.length() : 0)
1198             + ((cmdRef != null) ? 4 + cmdRef.length() : 0)
1199             ;
1200
1201        for (int i=0; targetRefs != null && i<targetRefs.size(); ++i) {
1202            size += getSize((TargetRef)targetRefs.get(i));
1203        }
1204        for (int i=0; sourceRefs != null && i<sourceRefs.size(); ++i) {
1205            size += getSize((SourceRef)sourceRefs.get(i));
1206        }
1207        return size;
1208    }
1209}
1210
Popular Tags