1 18 package sync4j.framework.tools; 19 20 import java.io.*; 21 import java.util.ArrayList ; 22 23 import sync4j.framework.core.*; 24 25 import sync4j.framework.engine.MessageSizeCalculator; 26 27 33 public class WBXMLSizeCalculator 34 implements MessageSizeCalculator { 35 36 38 40 45 public long getMsgSizeOverhead() { 46 return 500; 47 } 48 49 55 public long getSyncMLOverhead() { 56 return 29; 57 } 58 59 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 84 public long getSize(SyncHdr syncHdr) { 85 VerDTD verDTD = syncHdr.getVerDTD() ; 86 VerProto verProto = syncHdr.getVerProto() ; 87 SessionID sessionID = syncHdr.getSessionID(); 88 String msgID = syncHdr.getMsgID() ; 89 Target target = syncHdr.getTarget() ; 90 Source source = syncHdr.getSource() ; 91 String 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 116 public long getRespURIOverhead() { 117 return 150; 118 } 119 120 122 128 public long getSyncBodyOverhead() { 129 return 4; 130 } 131 138 public long getSize(SyncBody syncBody) { 139 ArrayList 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 153 158 public long getSize(VerDTD verDTD) { 159 return 4 160 + verDTD.getValue().length() 161 ; 162 } 163 164 170 public long getSize(VerProto verProto) { 171 return 4 172 + verProto.getVersion().length() 173 ; 174 } 175 176 182 public long getSize(SessionID sessionID) { 183 return 4 184 + sessionID.getSessionID().length() 185 ; 186 } 187 188 193 public long getSize(Target target) { 194 String locURI = target.getLocURI() ; 195 String 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 208 public long getSize(Source source) { 209 String locURI = source.getLocURI() ; 210 String 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 220 224 public long getSize(Cred cred) { 225 Authentication auth = cred.getAuthentication(); 226 Meta meta = auth.getMeta(); 227 String data = cred.getData(); 228 229 return 4 230 + ((meta != null) ? getSize(meta) : 0) 231 + ((data != null) ? 4 + data.length() : 0) 232 ; 233 } 234 235 237 242 public long getSize(Meta meta) { 243 long sizeMeta = 0; 244 245 String format = meta.getFormat() ; 246 String type = meta.getType() ; 247 String mark = meta.getMark() ; 248 Long size = meta.getSize() ; 249 Anchor anchor = meta.getAnchor() ; 250 String version = meta.getVersion() ; 251 NextNonce nextNonce = meta.getNextNonce() ; 252 Long maxMsgSize = meta.getMaxMsgSize(); 253 Long maxObjSize = meta.getMaxObjSize(); 254 ArrayList 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 279 284 public long getSize(Anchor anchor) { 285 String last = anchor.getLast(); 286 String 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 300 public long getSize(EMI emi) { 301 return 4 302 + emi.getValue().length() 303 ; 304 } 305 306 312 public long getSize(NextNonce nextNonce) { 313 return 4 314 + nextNonce.getValueAsBase64().length() 315 ; 316 } 317 318 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 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 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 398 public long getSize(CmdID cmdID) { 399 return 2 400 + cmdID.getCmdID().length(); 401 } 402 403 409 public long getSize(Add add) { 410 Meta meta = add.getMeta() ; 411 ArrayList 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 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 449 public long getSize(ComplexData complexData) { 450 String 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 467 public long getSize(Data data) { 468 return 4 469 + data.getData().length(); 470 } 471 472 478 public long getSize(DevInfData devInfData) { 479 DevInf devInf = devInfData.getDevInf(); 480 return 4 481 + ((devInf != null) ? getSize(devInf) : 0) 482 ; 483 } 484 485 491 public long getSize(DevInf devInf) { 492 VerDTD verDTD = devInf.getVerDTD() ; 493 String man = devInf.getMan() ; 494 String mod = devInf.getMod() ; 495 String oem = devInf.getOEM() ; 496 String fwV = devInf.getFwV() ; 497 String swV = devInf.getSwV() ; 498 String hwV = devInf.getHwV() ; 499 String devID = devInf.getDevID() ; 500 String devTyp = devInf.getDevTyp() ; 501 ArrayList dataStores = devInf.getDataStore(); 502 ArrayList ctCaps = devInf.getCTCap() ; 503 ArrayList 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 539 public long getSize(DataStore dataStore) { 540 SourceRef sourceRef = dataStore.getSourceRef() ; 541 String displayName = dataStore.getDisplayName(); 542 long maxGUIDSize = dataStore.getMaxGUIDSize(); 543 ContentTypeInfo rxPref = dataStore.getRxPref() ; 544 ArrayList rxs = dataStore.getRx() ; 545 ContentTypeInfo txPref = dataStore.getTxPref() ; 546 ArrayList 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 579 public long getSize(ContentTypeInfo contentTypeInfo) { 580 String ctType = contentTypeInfo.getCTType(); 581 String verCT = contentTypeInfo.getVerCT() ; 582 583 return ((ctType != null) ? 4 + ctType.length() : 0) 584 + ((verCT != null) ? 4 + verCT.length() : 0) 585 ; 586 } 587 588 593 public long getSize(SourceRef sourceRef) { 594 String 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 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 626 public long getSize(SyncCap syncCap) { 627 ArrayList 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 642 public long getSize(SyncType syncType) { 643 return 4 644 + String.valueOf(syncType.getType()).length() 645 ; 646 } 647 648 654 public long getSize(CTCap ctCap) { 655 ArrayList 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 670 public long getSize(CTTypeSupported ctTypeSupported) { 671 String ctType = ctTypeSupported.getCTType() ; 672 ArrayList 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 689 public long getSize(CTPropParam ctPropParam) { 690 String propName = ctPropParam.getPropName() ; 691 ArrayList valEnums = ctPropParam.getValEnum() ; 692 String dataType = ctPropParam.getDataType() ; 693 int size = ctPropParam.getSize() ; 694 String displayName = ctPropParam.getDisplayName() ; 695 ArrayList ctParameters = ctPropParam.getContentTypeParameters(); 696 697 long sizeCTPP = 0; 698 for (int i=0; valEnums != null && i<valEnums.size(); i++) { 699 sizeCTPP += 4 + ((String )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 720 public long getSize(ContentTypeParameter ctParameter) { 721 String paramName = ctParameter.getParamName() ; 722 ArrayList valEnums = ctParameter.getValEnum() ; 723 String dataType = ctParameter.getDataType() ; 724 int size = ctParameter.getSize() ; 725 String displayName = ctParameter.getDisplayName(); 726 long sizeCTP = 0; 727 728 for (int i=0; valEnums != null && i<valEnums.size(); i++) { 729 sizeCTP += 4 + ((String )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 746 public long getSize(Ext ext) { 747 String name = ext.getXNam(); 748 ArrayList values = ext.getXVal(); 749 long size = 4; 750 751 for (int i=0; values != null && i<values.size(); i++) { 752 size += 4 + ((String )values.get(i)).length(); 753 } 754 755 return ((name != null) ? 4 + name.length() : 0) 756 + size 757 ; 758 } 759 765 public long getSize(Alert alert) { 766 int data = alert.getData() ; 767 ArrayList 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 785 public long getSize(Atomic atomic) { 786 Meta meta = atomic.getMeta() ; 787 ArrayList 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 805 public long getSize(Copy copy) { 806 Meta meta = copy.getMeta() ; 807 ArrayList 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 825 public long getSize(Delete delete) { 826 Meta meta = delete.getMeta() ; 827 ArrayList 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 847 public long getSize(Exec exec) { 848 ArrayList 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 865 public long getSize(Get get) { 866 String lang = get.getLang(); 867 Meta meta = get.getMeta() ; 868 ArrayList 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 887 public long getSize(Map map) { 888 Target target = map.getTarget(); 889 Source source = map.getSource(); 890 Meta meta = map.getMeta() ; 891 ArrayList 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 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 927 public long getSize(Put put) { 928 String lang = put.getLang(); 929 Meta meta = put.getMeta() ; 930 ArrayList 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 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 968 public long getSize(Replace replace) { 969 Meta meta = replace.getMeta() ; 970 ArrayList 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 988 public long getSize(Results results) { 989 String msgRef = results.getMsgRef() ; 990 String cmdRef = results.getCmdRef() ; 991 Meta meta = results.getMeta() ; 992 ArrayList targetRefs = results.getTargetRef(); 993 ArrayList sourceRefs = results.getSourceRef(); 994 ArrayList 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 1019 public long getSize(TargetRef targetRef) { 1020 String 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 1035 public long getSize(Search search) { 1036 Target target = search.getTarget() ; 1037 ArrayList sources = search.getSources(); 1038 String 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 1062 public long getSize(Sequence sequence) { 1063 Meta meta = sequence.getMeta() ; 1064 ArrayList 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 1082 public long getSize(Status status) { 1083 CmdID cmdID = status.getCmdID() ; 1084 String msgRef = status.getMsgRef() ; 1085 String cmdRef = status.getCmdRef() ; 1086 String cmd = status.getCmd() ; 1087 ArrayList targetRefs = status.getTargetRef(); 1088 ArrayList sourceRefs = status.getSourceRef(); 1089 Cred cred = status.getCred() ; 1090 Chal chal = status.getChal() ; 1091 Data data = status.getData() ; 1092 ArrayList 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 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 1134 public long getSize(Sync sync) { 1135 Target target = sync.getTarget() ; 1136 Source source = sync.getSource() ; 1137 Meta meta = sync.getMeta() ; 1138 Long numberOfChanges = sync.getNumberOfChanges(); 1139 ArrayList 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 1158 public long getSize(ItemizedCommand itemCmd) { 1159 Meta meta = itemCmd.getMeta() ; 1160 ArrayList 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 1179 public long getSize(ModificationCommand modCmd) { 1180 return getSize((ItemizedCommand)modCmd); 1181 } 1182 1183 1189 public long getSize(ResponseCommand responseCmd) { 1190 String msgRef = responseCmd.getMsgRef() ; 1191 String cmdRef = responseCmd.getCmdRef() ; 1192 ArrayList targetRefs = responseCmd.getTargetRef(); 1193 ArrayList 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 |