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 XMLSizeCalculator 34 implements MessageSizeCalculator { 35 36 42 public long getMsgSizeOverhead() { 43 return 500; 44 } 45 46 53 public long getSyncMLOverhead() { 54 return 43; 55 } 56 57 68 public long getSize(SyncML syncML) { 69 SyncHdr syncHdr = syncML.getSyncHdr() ; 70 SyncBody syncBody = syncML.getSyncBody(); 71 72 return 43 73 + getSize(syncHdr ) 74 + getSize(syncBody) 75 ; 76 } 77 78 110 public long getSize(SyncHdr syncHdr) { 111 112 VerDTD verDTD = syncHdr.getVerDTD() ; 113 VerProto verProto = syncHdr.getVerProto() ; 114 SessionID sessionID = syncHdr.getSessionID(); 115 String msgID = syncHdr.getMsgID() ; 116 Target target = syncHdr.getTarget() ; 117 Source source = syncHdr.getSource() ; 118 String respURI = syncHdr.getRespURI() ; 119 boolean noResp = syncHdr.isNoResp() ; 120 Cred cred = syncHdr.getCred() ; 121 Meta meta = syncHdr.getMeta() ; 122 123 return 21 124 + ((verDTD != null) ? getSize(verDTD) : 0) 125 + ((verProto != null) ? getSize(verProto) : 0) 126 + ((sessionID != null) ? getSize(sessionID) : 0) 127 + ((msgID != null) ? 16 + msgID.length() : 0) 128 + ((target != null) ? getSize(target) : 0) 129 + ((source != null) ? getSize(source) : 0) 130 + ((respURI != null) ? 19 + respURI.length() : 90) 131 + (noResp ? 18 : 0) 132 + ((cred != null) ? getSize(cred) : 0) 133 + ((meta != null) ? getSize(meta) : 0) 134 ; 135 } 136 137 142 public long getRespURIOverhead() { 143 return 150; 144 } 145 146 153 public long getSyncBodyOverhead() { 154 return 23; 155 } 156 157 170 public long getSize(SyncBody syncBody) { 171 ArrayList commands = syncBody.getCommands(); 172 173 long size = 23 174 + ((syncBody.isFinalMsg()) ? 16 : 0) 175 ; 176 177 for (int i=0; i<commands.size(); i++) { 178 size += getCommandSize((AbstractCommand)commands.get(i)); 179 } 180 return size; 181 } 182 183 192 public long getSize(VerDTD verDTD) { 193 return 18 194 + verDTD.getValue().length() 195 ; 196 } 197 198 207 public long getSize(VerProto verProto) { 208 return 22 209 + verProto.getVersion().length() 210 ; 211 } 212 213 222 public long getSize(SessionID sessionID) { 223 return 24 224 + sessionID.getSessionID().length() 225 ; 226 } 227 228 244 public long getSize(Target target) { 245 String locURI = target.getLocURI() ; 246 String locName = target.getLocName(); 247 248 return 19 249 + ((locURI != null) ? (18 + locURI.length() ) : 0) 250 + ((locName != null) ? (20 + locName.length()) : 0) 251 ; 252 } 253 269 public long getSize(Source source) { 270 String locURI = source.getLocURI() ; 271 String locName = source.getLocName(); 272 273 return 19 274 + ((locURI != null) ? (18 + locURI.length() ) : 0) 275 + ((locName != null) ? (20 + locName.length()) : 0) 276 ; 277 } 278 292 public long getSize(Cred cred) { 293 Authentication auth = cred.getAuthentication(); 294 Meta meta = auth.getMeta(); 295 String data = cred.getData(); 296 297 return 15 298 + ((meta != null) ? getSize(meta) : 0) 299 + ((data != null) ? 14 + data.length() : 0) 300 ; 301 } 302 303 344 public long getSize(Meta meta) { 345 long sizeMeta = 0; 346 347 String format = meta.getFormat() ; 348 String type = meta.getType() ; 349 String mark = meta.getMark() ; 350 Long size = meta.getSize() ; 351 Anchor anchor = meta.getAnchor() ; 352 String version = meta.getVersion() ; 353 NextNonce nextNonce = meta.getNextNonce() ; 354 Long maxMsgSize = meta.getMaxMsgSize(); 355 Long maxObjSize = meta.getMaxObjSize(); 356 ArrayList emi = meta.getEMI() ; 357 Mem mem = meta.getMem() ; 358 359 sizeMeta = 37 360 + ((format != null) ? 18 + format.length() : 0) 361 + ((type != null) ? 14 + type.length() : 0) 362 + ((mark != null) ? 14 + mark.length() : 0) 363 + ((size != null) ? 14 + String.valueOf(size).length(): 0) 364 + ((anchor != null) ? getSize(anchor) : 0) 365 + ((version != null) ? 20 + version.length() : 0) 366 + ((nextNonce != null) ? getSize(nextNonce) : 0) 367 + ((maxMsgSize!= null) ? 26 + String.valueOf(maxMsgSize).length() : 0) 368 + ((maxObjSize!= null) ? 26 + String.valueOf(maxObjSize).length() : 0) 369 + ((mem != null) ? getSize(mem) : 0) 370 ; 371 372 for (int i=0; emi != null && i < emi.size(); i++) { 373 sizeMeta += getSize((EMI)emi.get(i)); 374 } 375 376 return sizeMeta; 377 } 378 379 380 381 397 public long getSize(Anchor anchor) { 398 String last = anchor.getLast(); 399 String next = anchor.getNext(); 400 401 return 41 402 + ((last != null) ? 14 + last.length() : 0) 403 + ((next != null) ? 14 + next.length() : 0) 404 ; 405 } 406 407 416 public long getSize(EMI emi) { 417 return 12 418 + emi.getValue().length() 419 ; 420 } 421 422 431 public long getSize(NextNonce nextNonce) { 432 return 24 433 + nextNonce.getValueAsBase64().length() 434 ; 435 } 436 437 455 public long getSize(Mem mem) { 456 boolean sharedMem = mem.isSharedMem(); 457 long freeMem = mem.getFreeMem() ; 458 long freeID = mem.getFreeID() ; 459 460 return 13 461 + ((sharedMem) ? 18 : 0) 462 + ((freeMem != 0) ? 20 + String.valueOf(freeMem).length() : 0) 463 + ((freeID != 0) ? 18 + String.valueOf(freeID).length() : 0) 464 ; 465 } 466 467 478 public long getSize(AbstractCommand command) { 479 CmdID cmdID = command.getCmdID(); 480 Cred cred = command.getCred() ; 481 482 return ((cmdID != null) ? getSize(cmdID) : 0) 483 + ((command.isNoResp()) ? 18 : 0) 484 + ((cred != null) ? getSize(cred) : 0) 485 ; 486 } 487 488 493 public long getCommandSize(AbstractCommand command) { 494 long size = 0; 495 if (command instanceof Add) { 496 size = getSize((Add)command); 497 } else if (command instanceof Alert) { 498 size = getSize((Alert)command); 499 } else if (command instanceof Atomic) { 500 size = getSize((Atomic)command); 501 } else if (command instanceof Copy) { 502 size = getSize((Copy)command); 503 } else if (command instanceof Delete) { 504 size = getSize((Delete)command); 505 } else if (command instanceof Exec) { 506 size = getSize((Exec)command); 507 } else if (command instanceof Get) { 508 size = getSize((Get)command); 509 } else if (command instanceof Map) { 510 size = getSize((Map)command); 511 } else if (command instanceof Put) { 512 size = getSize((Put)command); 513 } else if (command instanceof Replace) { 514 size = getSize((Replace)command); 515 } else if (command instanceof Results) { 516 size = getSize((Results)command); 517 } else if (command instanceof Search) { 518 size = getSize((Search)command); 519 } else if (command instanceof Sequence) { 520 size = getSize((Sequence)command); 521 } else if (command instanceof Status) { 522 size = getSize((Status)command); 523 } else if (command instanceof Sync) { 524 size = getSize((Sync)command); 525 } 526 527 return size; 528 } 529 530 539 public long getSize(CmdID cmdID) { 540 return 16 541 + cmdID.getCmdID().length(); 542 } 543 544 562 public long getSize(Add add) { 563 Meta meta = add.getMeta() ; 564 ArrayList items = add.getItems(); 565 566 long size = 13 567 + getSize((AbstractCommand)add) 568 + ((meta != null) ? getSize(meta) : 0) 569 ; 570 for (int i=0; items != null && i<items.size(); i++) { 571 size += getSize((Item)items.get(i)); 572 } 573 return size; 574 } 575 576 594 public long getSize(Item item) { 595 Target target = item.getTarget(); 596 Source source = item.getSource(); 597 Meta meta = item.getMeta() ; 598 ComplexData data = item.getData() ; 599 600 return 15 601 + ((target != null) ? getSize(target) : 0) 602 + ((source != null) ? getSize(source) : 0) 603 + ((meta != null) ? getSize(meta) : 0) 604 + ((data != null) ? getSize(data) : 0) 605 + ((item.isMoreData()) ? 22 : 0) 606 ; 607 } 608 609 622 public long getSize(ComplexData complexData) { 623 String data = complexData.getData() ; 624 Anchor anchor = complexData.getAnchor(); 625 DevInf devInf = complexData.getDevInf(); 626 627 return 15 628 + ((data != null) ? data.length() :0) 629 + ((anchor != null) ? getSize(anchor) :0) 630 + ((devInf != null) ? getSize(devInf) :0) 631 ; 632 } 633 634 643 public long getSize(Data data) { 644 return 14 645 + data.getData().length(); 646 } 647 648 658 public long getSize(DevInfData devInfData) { 659 DevInf devInf = devInfData.getDevInf(); 660 return 15 661 + ((devInf != null) ? getSize(devInf) : 0) 662 ; 663 } 664 665 719 public long getSize(DevInf devInf) { 720 VerDTD verDTD = devInf.getVerDTD() ; 721 String man = devInf.getMan() ; 722 String mod = devInf.getMod() ; 723 String oem = devInf.getOEM() ; 724 String fwV = devInf.getFwV() ; 725 String swV = devInf.getSwV() ; 726 String hwV = devInf.getHwV() ; 727 String devID = devInf.getDevID() ; 728 String devTyp = devInf.getDevTyp() ; 729 ArrayList dataStores = devInf.getDataStore(); 730 ArrayList ctCaps = devInf.getCTCap() ; 731 ArrayList exts = devInf.getExt() ; 732 733 long size = 0; 734 735 for (int i=0; dataStores != null && i<dataStores.size(); i++) { 736 size += getSize((DataStore)dataStores.get(i)); 737 } 738 for (int i=0; ctCaps != null && i<ctCaps.size(); i++) { 739 size += getSize((CTCap)ctCaps.get(i)); 740 } 741 for (int i=0; exts != null && i<exts.size(); i++) { 742 size += getSize((Ext)exts.get(i)); 743 } 744 745 return 41 746 + ((verDTD != null) ? getSize(verDTD) : 0) 747 + ((man != null) ? 12 + man.length() : 0) 748 + ((mod != null) ? 12 + mod.length() : 0) 749 + ((oem != null) ? 12 + oem.length() : 0) 750 + ((fwV != null) ? 12 + fwV.length() : 0) 751 + ((swV != null) ? 12 + swV.length() : 0) 752 + ((hwV != null) ? 12 + hwV.length() : 0) 753 + ((devID != null) ? 16 + devID.length() : 0) 754 + ((devTyp != null) ? 18 + devTyp.length() : 0) 755 + ((devInf.isUTC()) ? 12 : 0) 756 + ((devInf.isSupportLargeObjs()) ? 38 : 0) 757 + ((devInf.isSupportNumberOfChanges()) ? 50 : 0) 758 + size; 759 } 760 761 799 public long getSize(DataStore dataStore) { 800 SourceRef sourceRef = dataStore.getSourceRef() ; 801 String displayName = dataStore.getDisplayName(); 802 long maxGUIDSize = dataStore.getMaxGUIDSize(); 803 ContentTypeInfo rxPref = dataStore.getRxPref() ; 804 ArrayList rxs = dataStore.getRx() ; 805 ContentTypeInfo txPref = dataStore.getTxPref() ; 806 ArrayList txs = dataStore.getTx() ; 807 DSMem dsMem = dataStore.getDSMem() ; 808 SyncCap syncCap = dataStore.getSyncCap() ; 809 810 long size = 0; 811 812 for (int i=0; rxs != null && i<rxs.size(); i++) { 813 size += 11 + getSize((ContentTypeInfo)rxs.get(i)); 814 } 815 for (int i=0; txs != null && i<txs.size(); i++) { 816 size += 11 + getSize((ContentTypeInfo)txs.get(i)); 817 } 818 819 return 25 820 + ((sourceRef != null) ? getSize(sourceRef) : 0) 821 + ((displayName != null && displayName.length() != 0) 822 ? 28 + displayName.length() : 0) 823 + ((maxGUIDSize > 0) 824 ? 28 + String.valueOf(maxGUIDSize).length() : 0) 825 + ((rxPref != null) ? 21 + getSize(rxPref) : 0) 826 + ((txPref != null) ? 21 + getSize(txPref) : 0) 827 + ((dsMem != null) ? getSize(dsMem) : 0) 828 + ((syncCap != null) ? getSize(syncCap) : 0) 829 + size 830 ; 831 } 832 833 847 public long getSize(ContentTypeInfo contentTypeInfo) { 848 String ctType = contentTypeInfo.getCTType(); 849 String verCT = contentTypeInfo.getVerCT() ; 850 851 return ((ctType != null) ? 18 + ctType.length() : 0) 852 + ((verCT != null) ? 16 + verCT.length() : 0) 853 ; 854 } 855 856 868 public long getSize(SourceRef sourceRef) { 869 String value = sourceRef.getValue() ; 870 Source source = sourceRef.getSource(); 871 872 return 24 873 + ((value != null) ? value.length() : 0) 874 + ((source != null) ? getSize(source) : 0) 875 ; 876 } 877 878 896 public long getSize(DSMem dsMem) { 897 long maxMem = dsMem.getMaxMem(); 898 long maxID = dsMem.getMaxID() ; 899 900 return 17 901 + ((dsMem.isSharedMem()) ? 24 :0) 902 + ((maxMem>=0) ? 18 + String.valueOf(maxMem).length() :0) 903 + ((maxID >=0) ? 16 + String.valueOf(maxID).length() :0) 904 ; 905 } 906 907 917 public long getSize(SyncCap syncCap) { 918 ArrayList syncTypes = syncCap.getSyncType(); 919 long size = 21; 920 921 for (int i=0; i<syncTypes.size(); ++i) { 922 size += getSize((SyncType)syncTypes.get(i)); 923 } 924 return size; 925 } 926 927 936 public long getSize(SyncType syncType) { 937 return 22 938 + String.valueOf(syncType.getType()).length() 939 ; 940 } 941 942 952 public long getSize(CTCap ctCap) { 953 ArrayList ctTypeSup = ctCap.getCTTypeSupported(); 954 long size = 17; 955 956 for (int i=0; ctTypeSup != null && i<ctTypeSup.size(); i++) { 957 size += getSize((CTTypeSupported)ctTypeSup.get(i)); 958 } 959 return size; 960 } 961 962 972 public long getSize(CTTypeSupported ctTypeSupported) { 973 String ctType = ctTypeSupported.getCTType() ; 974 ArrayList ctPropParams = ctTypeSupported.getCTPropParams(); 975 long size = 0; 976 977 for (int i=0; ctPropParams != null && i<ctPropParams.size(); i++) { 978 size += getSize((CTPropParam)ctPropParams.get(i)); 979 } 980 return ((ctType != null) ? 18 + ctType.length() : 0) 981 + size 982 ; 983 } 984 985 986 1012 public long getSize(CTPropParam ctPropParam) { 1013 String propName = ctPropParam.getPropName() ; 1014 ArrayList valEnums = ctPropParam.getValEnum() ; 1015 String dataType = ctPropParam.getDataType() ; 1016 int size = ctPropParam.getSize() ; 1017 String displayName = ctPropParam.getDisplayName() ; 1018 ArrayList ctParameters = ctPropParam.getContentTypeParameters(); 1019 1020 long sizeCTPP = 0; 1021 for (int i=0; valEnums != null && i<valEnums.size(); i++) { 1022 sizeCTPP += 20 + ((String )valEnums.get(i)).length(); 1023 } 1024 1025 for (int i=0; ctParameters!=null && i<ctParameters.size(); i++) { 1026 sizeCTPP += getSize((ContentTypeParameter)ctParameters.get(i)); 1027 } 1028 1029 return ((propName != null) ? 22 + propName.length() : 0) 1030 + ((dataType != null) ? 22 + dataType.length() : 0) 1031 + ((size != 0 ) ? 14 + String.valueOf(size).length() : 0) 1032 + ((displayName != null) ? 28 + displayName.length() : 0) 1033 + sizeCTPP 1034 ; 1035 } 1036 1037 1062 public long getSize(ContentTypeParameter ctParameter) { 1063 String paramName = ctParameter.getParamName() ; 1064 ArrayList valEnums = ctParameter.getValEnum() ; 1065 String dataType = ctParameter.getDataType() ; 1066 int size = ctParameter.getSize() ; 1067 String displayName = ctParameter.getDisplayName(); 1068 long sizeCTP = 0; 1069 1070 for (int i=0; valEnums != null && i<valEnums.size(); i++) { 1071 sizeCTP += 20 + ((String )valEnums.get(i)).length(); 1072 } 1073 1074 return ((paramName != null) ? 24 + paramName.length() : 0) 1075 + ((dataType != null) ? 22 + dataType.length() : 0) 1076 + ((size != 0 ) ? 14 + String.valueOf(size).length() : 0) 1077 + ((displayName != null) ? 28 + displayName.length() : 0) 1078 + sizeCTP 1079 ; 1080 } 1081 1082 1098 public long getSize(Ext ext) { 1099 String name = ext.getXNam(); 1100 ArrayList values = ext.getXVal(); 1101 long size = 13; 1102 1103 for (int i=0; values != null && i<values.size(); i++) { 1104 size += 14 + ((String )values.get(i)).length(); 1105 } 1106 1107 return ((name != null) ? 14 + name.length() : 0) 1108 + size 1109 ; 1110 } 1111 1131 public long getSize(Alert alert) { 1132 int data = alert.getData() ; 1133 ArrayList items = alert.getItems(); 1134 1135 long size = 17 1136 + getSize((AbstractCommand)alert) 1137 + ((data != 0) ? 14 + String.valueOf(data).length() : 0) 1138 ; 1139 for (int i=0; items != null && i<items.size(); i++) { 1140 size += getSize((Item)items.get(i)); 1141 } 1142 return size; 1143 } 1144 1145 1163 public long getSize(Atomic atomic) { 1164 Meta meta = atomic.getMeta() ; 1165 ArrayList commands = atomic.getCommands(); 1166 1167 long size = 19 1168 + getSize((AbstractCommand)atomic) 1169 + ((meta != null) ? getSize(meta) : 0) 1170 ; 1171 for (int i=0; commands != null && i<commands.size(); i++) { 1172 size += getCommandSize((AbstractCommand)commands.get(i)); 1173 } 1174 return size; 1175 } 1176 1177 1195 public long getSize(Copy copy) { 1196 Meta meta = copy.getMeta() ; 1197 ArrayList items = copy.getItems(); 1198 1199 long size = 13 1200 + getSize((AbstractCommand)copy) 1201 + ((meta != null) ? getSize(meta) : 0) 1202 ; 1203 for (int i=0; items != null && i<items.size(); i++) { 1204 size += getSize((Item)items.get(i)); 1205 } 1206 return size; 1207 } 1208 1209 1231 public long getSize(Delete delete) { 1232 Meta meta = delete.getMeta() ; 1233 ArrayList items = delete.getItems(); 1234 1235 long size = 20 1236 + getSize((AbstractCommand)delete) 1237 + ((delete.isArchive()) ? 20 : 0) 1238 + ((delete.isSftDel() ) ? 18 : 0) 1239 + ((meta != null ) ? getSize(meta) : 0) 1240 ; 1241 for (int i=0; items != null && i<items.size(); i++) { 1242 size += getSize((Item)items.get(i)); 1243 } 1244 return size; 1245 } 1246 1247 1263 public long getSize(Exec exec) { 1264 ArrayList items = exec.getItems(); 1265 1266 long size = 14 1267 + getSize((AbstractCommand)exec) 1268 ; 1269 for (int i=0; items != null && i<items.size(); i++) { 1270 size += getSize((Item)items.get(i)); 1271 } 1272 return size; 1273 } 1274 1275 1297 public long getSize(Get get) { 1298 String lang = get.getLang(); 1299 Meta meta = get.getMeta() ; 1300 ArrayList items = get.getItems(); 1301 1302 long size = 13 1303 + getSize((AbstractCommand)get) 1304 + ((lang != null) ? 14 + lang.length() : 0) 1305 + ((meta != null) ? getSize(meta) : 0) 1306 ; 1307 for (int i=0; items != null && i<items.size(); i++) { 1308 size += getSize((Item)items.get(i)); 1309 } 1310 return size; 1311 } 1312 1313 1335 public long getSize(Map map) { 1336 Target target = map.getTarget(); 1337 Source source = map.getSource(); 1338 Meta meta = map.getMeta() ; 1339 ArrayList mapItems = map.getMapItems(); 1340 1341 long size = 13 1342 + getSize((AbstractCommand)map) 1343 + ((target != null) ? getSize(target) : 0) 1344 + ((source != null) ? getSize(source) : 0) 1345 + ((meta != null) ? getSize(meta) : 0) 1346 ; 1347 for (int i=0; mapItems != null && i<mapItems.size(); i++) { 1348 size += getSize((MapItem)mapItems.get(i)); 1349 } 1350 return size; 1351 } 1352 1353 1365 public long getSize(MapItem mapItem) { 1366 Target target = mapItem.getTarget(); 1367 Source source = mapItem.getSource(); 1368 1369 return 21 1370 + ((target != null) ? getSize(target) : 0) 1371 + ((source != null) ? getSize(source) : 0) 1372 ; 1373 } 1374 1375 1397 public long getSize(Put put) { 1398 String lang = put.getLang(); 1399 Meta meta = put.getMeta() ; 1400 ArrayList devInfItems = put.getItems(); 1401 1402 long size = 14 1403 + getSize((AbstractCommand)put) 1404 + ((lang != null) ? 14 + lang.length() : 0) 1405 + ((meta != null) ? getSize(meta) : 0) 1406 ; 1407 for (int i=0; devInfItems != null && i<devInfItems.size(); i++) { 1408 size += getSize((DevInfItem)devInfItems.get(i)); 1409 } 1410 return size; 1411 } 1412 1413 1429 public long getSize(DevInfItem devInfItem) { 1430 Target target = devInfItem.getTarget() ; 1431 Source source = devInfItem.getSource() ; 1432 Meta meta = devInfItem.getMeta() ; 1433 DevInfData devInfData = devInfItem.getDevInfData(); 1434 1435 return 15 1436 + ((target != null) ? getSize(target) : 0) 1437 + ((source != null) ? getSize(source) : 0) 1438 + ((meta != null) ? getSize(meta) : 0) 1439 + ((devInfData != null) ? getSize(devInfData) : 0) 1440 ; 1441 } 1442 1443 1461 public long getSize(Replace replace) { 1462 Meta meta = replace.getMeta() ; 1463 ArrayList items = replace.getItems(); 1464 1465 long size = 21 1466 + getSize((AbstractCommand)replace) 1467 + ((meta != null) ? getSize(meta) : 0) 1468 ; 1469 for (int i=0; items != null && i<items.size(); i++) { 1470 size += getSize((Item)items.get(i)); 1471 } 1472 return size; 1473 } 1474 1475 1505 public long getSize(Results results) { 1506 String msgRef = results.getMsgRef() ; 1507 String cmdRef = results.getCmdRef() ; 1508 Meta meta = results.getMeta() ; 1509 ArrayList targetRefs = results.getTargetRef(); 1510 ArrayList sourceRefs = results.getSourceRef(); 1511 ArrayList items = results.getItems() ; 1512 1513 long size = 21 1514 + getSize((AbstractCommand)results) 1515 + ((msgRef != null) ? 18 + msgRef.length() : 0) 1516 + ((cmdRef != null) ? 18 + cmdRef.length() : 0) 1517 + ((meta != null) ? getSize(meta) : 0) 1518 ; 1519 for (int i=0; targetRefs != null && i<targetRefs.size(); i++) { 1520 size += getSize((TargetRef)targetRefs.get(i)); 1521 } 1522 for (int i=0; sourceRefs != null && i<sourceRefs.size(); i++) { 1523 size += getSize((SourceRef)sourceRefs.get(i)); 1524 } 1525 for (int i=0; items != null && i<items.size(); i++) { 1526 size += getSize((Item)items.get(i)); 1527 } 1528 return size; 1529 } 1530 1531 1543 public long getSize(TargetRef targetRef) { 1544 String value = targetRef.getValue() ; 1545 Target target = targetRef.getTarget(); 1546 1547 return 24 1548 + ((value != null) ? value.length() : 0) 1549 + ((target != null) ? getSize(target) : 0) 1550 ; 1551 } 1552 1553 1581 public long getSize(Search search) { 1582 Target target = search.getTarget() ; 1583 ArrayList sources = search.getSources(); 1584 String lang = search.getLang() ; 1585 Meta meta = search.getMeta() ; 1586 Data data = search.getData() ; 1587 1588 long size = 1589 + getSize((AbstractCommand)search) 1590 + ((search.isNoResults()) ? 24 : 0) 1591 + ((target != null) ? getSize(target) : 0) 1592 + ((lang != null) ? 14 + lang.length() : 0) 1593 + ((meta != null) ? getSize(meta) : 0) 1594 + ((data != null) ? getSize(data) : 0) 1595 ; 1596 for (int i=0; sources != null && i<sources.size(); i++) { 1597 size += getSize((Source)sources.get(i)); 1598 } 1599 return size; 1600 } 1601 1602 1620 public long getSize(Sequence sequence) { 1621 Meta meta = sequence.getMeta() ; 1622 ArrayList commands = sequence.getCommands(); 1623 1624 long size = 23 1625 + getSize((AbstractCommand)sequence) 1626 + ((meta != null) ? getSize(meta) : 0) 1627 ; 1628 for (int i=0; commands != null && i<commands.size(); i++) { 1629 size += getCommandSize((AbstractCommand)commands.get(i)); 1630 } 1631 return size; 1632 } 1633 1634 1668 public long getSize(Status status) { 1669 CmdID cmdID = status.getCmdID() ; 1670 String msgRef = status.getMsgRef() ; 1671 String cmdRef = status.getCmdRef() ; 1672 String cmd = status.getCmd() ; 1673 ArrayList targetRefs = status.getTargetRef(); 1674 ArrayList sourceRefs = status.getSourceRef(); 1675 Cred cred = status.getCred() ; 1676 Chal chal = status.getChal() ; 1677 Data data = status.getData() ; 1678 ArrayList items = status.getItems() ; 1679 1680 long size = 19 1681 + ((cmdID != null) ? getSize(cmdID) : 0) 1682 + ((msgRef != null) ? 18 + msgRef.length() : 0) 1683 + ((cmdRef != null) ? 18 + cmdRef.length() : 0) 1684 + ((cmd != null) ? 12 + cmd.length() : 0) 1685 + ((cred != null) ? getSize(cred) : 0) 1686 + ((chal != null) ? getSize(chal) : 0) 1687 + ((data != null) ? getSize(data) : 0) 1688 ; 1689 for (int i=0; targetRefs != null && i<targetRefs.size(); i++) { 1690 size += getSize((TargetRef)targetRefs.get(i)); 1691 } 1692 for (int i=0; sourceRefs != null && i<sourceRefs.size(); i++) { 1693 size += getSize((SourceRef)sourceRefs.get(i)); 1694 } 1695 for (int i=0; items != null && i<items.size(); i++) { 1696 size += getSize((Item)items.get(i)); 1697 } 1698 return size; 1699 } 1700 1710 public long getSize(Chal chal) { 1711 Meta meta = chal.getMeta(); 1712 1713 return 15 1714 + ((meta != null) ? getSize(meta) : 0) 1715 ; 1716 } 1717 1718 1744 public long getSize(Sync sync) { 1745 Target target = sync.getTarget() ; 1746 Source source = sync.getSource() ; 1747 Meta meta = sync.getMeta() ; 1748 Long numberOfChanges = sync.getNumberOfChanges(); 1749 ArrayList commands = sync.getCommands() ; 1750 1751 long size = 15 1752 + getSize((AbstractCommand)sync) 1753 + ((target != null) ? getSize(target) : 0) 1754 + ((source != null) ? getSize(source) : 0) 1755 + ((meta != null) ? getSize(meta) : 0) 1756 + ((numberOfChanges != null) ? 36 : 0) 1757 ; 1758 for (int i=0; commands != null && i<commands.size(); i++) { 1759 size += getCommandSize((AbstractCommand)commands.get(i)); 1760 } 1761 return size; 1762 } 1763 1764 1768 public long getSize(ItemizedCommand itemCmd) { 1769 Meta meta = itemCmd.getMeta() ; 1770 ArrayList items = itemCmd.getItems(); 1771 long size = 0; 1772 1773 size = getSize((AbstractCommand)itemCmd) 1774 + ((meta != null) ? getSize(meta) : 0) 1775 ; 1776 1777 for (int i=0; items != null && i<items.size(); i++) { 1778 size += getSize((Item)items.get(i)); 1779 } 1780 return size; 1781 } 1782 1783 1789 public long getSize(ModificationCommand modCmd) { 1790 return getSize((ItemizedCommand)modCmd); 1791 } 1792 1793 1799 public long getSize(ResponseCommand responseCmd) { 1800 String msgRef = responseCmd.getMsgRef() ; 1801 String cmdRef = responseCmd.getCmdRef() ; 1802 ArrayList targetRefs = responseCmd.getTargetRef(); 1803 ArrayList sourceRefs = responseCmd.getSourceRef(); 1804 long size = 0; 1805 1806 size = getSize((ItemizedCommand)responseCmd) 1807 + ((msgRef != null) ? 18 + msgRef.length() : 0) 1808 + ((cmdRef != null) ? 18 + cmdRef.length() : 0) 1809 ; 1810 1811 for (int i=0; targetRefs != null && i<targetRefs.size(); ++i) { 1812 size += getSize((TargetRef)targetRefs.get(i)); 1813 } 1814 for (int i=0; sourceRefs != null && i<sourceRefs.size(); ++i) { 1815 size += getSize((SourceRef)sourceRefs.get(i)); 1816 } 1817 return size; 1818 } 1819 1820} 1821 | Popular Tags |