}
try {
lastTimestamp = dataStore.getLastTimestamp();
} catch (DataAccessException e) {
throw new SyncException(e.getMessage());
}
nextTimestamp = System.currentTimeMillis();
try {
loadResources();
sdh.loadLanguage(this.getClass());
sdh.loadDefaultValue();
} catch (IOException e) {
throw new UpdateException( "Error: ("
+ e.getClass().getName()
+ "): "
+ e.getMessage()
);
}
if (sessionID == null) {
sessionID = String.valueOf(System.currentTimeMillis());
//to be used in static context in SyncMLClientImpl
session_id = sessionID;
}
encryptType = sdh.getEncryptDefault();
prepareInizializationMessage();
StaticDataHelper.log("\n\n\n");
StaticDataHelper.log("sending:\n" + clientInitXML);
response = syncInitialization();
StaticDataHelper.log(response);
checkServerAlerts(response);
// start debug
StaticDataHelper.log("\n\n\n");
String keyStr = "";
Enumeration keys = serverAlerts.keys();
while (keys.hasMoreElements()) {
keyStr = (String)keys.nextElement();
StaticDataHelper.log("source - Name: " + keyStr + " | Status: " + serverAlerts.get(keyStr));
}
dataStore.setAlertCode((String)serverAlerts.get(keyStr));
// end debug
StaticDataHelper.log("\n\n\n");
StaticDataHelper.log("receiving\n:" + response);
serverUrlStatus = serverUrl;
serverUrl = response.substring(response.indexOf("<RespURI>") + 9,
response.indexOf("</RespURI>"));
if (!DeviceInfo.isSimulator()) {
serverUrl += gatewayUrl;
}
//
// execute init dataStore operation
//
dataStore.startDSOperations();
//
// Notifies the sources that the synchronization is going to begin
//
boolean sendingClientModifications = true ;
boolean done = false;
// ================================================================
/*
* the implementation of the client/server multi-messaging
* through a do while loop
*/
do {
int alertCode = -1;
response = null;
// --------------------------------------------------------
sendingClientModifications =
prepareModificationMessage(sendingClientModifications);
// --------------------------------------------------------
StaticDataHelper.log("\n\n\n\n\n\n\n");
StaticDataHelper.log("sending\n:" + modificationsXML);
response = syncModifications();
StaticDataHelper.log("\n\n\n\n\n\n\n");
StaticDataHelper.log("receiving\n:" + response);
processModifications(response);
done = ((response.indexOf("<Final/>") >= 0) ||
(response.indexOf("</Final>") >= 0));
}
while (!done);
// ================================================================
//
// We still have to send the latest mappings
//
prepareMappingMessage();
StaticDataHelper.log("\n\n\n\n\n\n\n");
StaticDataHelper.log("sending\n:" + mappingXML);
response = syncMapping();
StaticDataHelper.log("\n\n\n\n\n\n\n");
StaticDataHelper.log("receiving\n:" + response);
//
// Set the last anchor to the next timestamp for all the sources that
// has been synchronized
//
try {
dataStore.commitDSOperations();
dataStore.setLastTimestamp(nextTimestamp);
} catch (DataAccessException e) {
throw new SyncException(e.getMessage());
}
}