Table of Contents
There are two ways of constructing a software design; one way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
When designing the core library, several different aspects had to be taken care of. This chapter describes which problem occurred and how the design decisions are made.
There are two common methods of parsing incoming XML messages.
One is to parse the document word by word and take all XML tags as events. An event handler is called for every item: tag open, tag close and text. This is a fairly easy approach with a low memory footprint. However, it has some drawbacks: There is no guarantee that the parsed document is actually valid in the XML sense. Nodes could be opened and never closed.
The other approach is to parse the whole document, building up a tree in memory and then passing it to the program. This approach makes handling the contents very easy: We can freely move along the data. And the tree in memory is always valid. However, this method has other drawbacks: The first one is memory usage: A whole packet has to be kept in memory. This is acceptable for desktop computers and servers, but removes the possibility to use the software on thin hand-held devices. The other problem is that some events should be handled as soon as they are received.
So, what is the solution? It is a combined approach: Take advantage of both and leave out the disadvantages. We take a standard XML parser and use it to receive the XML events. With this information a tree is build in memory. As soon as an event is received completely it is handled if possible. After that the used information in the tree is freed.
A single sync session with a single database would be no problem. Unfortunately, there might be multiple sync sessions going on at the same time or multiple databases on one server. Figure 9.1, “Overview of SMLSingle/MultiThread, SMLSession, SMLSessionHandler and SMLDatabase” shows how this is represented in the class model.