Saturday, September 28. 2013
WBXML stream: Version 0.1.0
If you remember I was developing a wbxml parser and encoder for Java. This was motivated by another idea that I think is not going to be productive, but, at least, I wanted to complete this first step. The wbxml-stream is the result of all this work, it is a StAX (Streaming API for XML) for the JavaSE to deal with WBXML (WAP Binary XML). This week the first version 0.1.0 was released and it is a complete StAX implementation.
The WBXML is a standard which is defined in this document by the Open Mobile Alliance. In order to develop the library the java implementation is based on the C project libwbxml, which is the only implementation that I know of the WBXML format. Nevertheless the java library is quite tricky and different, its main features are the following:
In WBXML all the common elements of XML (element, attributes,... ) are mapped to an integer token (that is why it is called binary). This mapping data and some other information compose what is called a language (examples of languages are SyncML or Wireless Village).
The main feature of this implementation is to be generic, i.e., valid for any WBXML language. This way the wbxml-stream project loads a language from a properties definition file and the implementation does not deal with any special language tricks (thing that happens in libwbxml all the time). The definition part is managed in the library by the es.rickyepoderi.wbxml.definition package.
By default some language definitions are located and loaded at initialization in version 0.1.0 (ActiveSync, CONML, DevInf 1.1, DevInf 1.2, DMDDF 1.2, drmrel 1.0, EMN 1.0, OTA, PROV 1.0, SI 1.0, SL 1.0, SyncML 1.1, SyncML 1.2 and WV CSP 1.1). If you need to add a new definition the project wiki explains how a definition file is organized and presents a working example of a dummy new one.
The main idea of parsing and decoding is that an intermediary java structure is used. This way, when a WBXML is read (parsed), those intermediary objects are first created (memory representation of the WBXML document) and then the StAX reader iterates over the structure. In a writing (encoding) process the operations are reversed, the StAX writer constructs the object representation and it writes the binary stream at the end.
I know this idea means more memory and not a real streaming (StAX) way of working. But WBXML is a quite weird format (please check the pdf presented before) and there are several characteristics that convinced me to do it simple at first (this handicap could be a good improvement for next versions).
The objects of this intermediary representation are placed inside the es.rickyepoderi.wbxml.document package. The WbXmlEncoder and the WbXmlParser are the main classes to encode and parse a WBXML document respectively.
Finally the package es.rickyepoderi.wbxml.stream contains the StAX implementation. I tried to fully cover the standard, there are implementations for XMLStreamReader, XMLStreamWriter, XMLEventReader, XMLEventWriter, XMLInputFactory and XMLOutputFactory. In order to create the readers and writers the factories are recommended, see some examples in the wiki pages.
For some time I decided to only implement the stream classes and use internal java implementation for event reader and writer (a event reader can use a stream reader) but I finally decided to go all the way. Now the library only depends in JavaSE, no other dependency is needed. Even the logging is performed using the java.util.logging classes.
I think this first version is more or less usable. It contains several languages (only a few of the languages that libwbxml supports are not defined in wbxml-stream) and it is quite well tested (all the xml and wbxml files that libwbxml uses for testing are also tested with wbxml-stream). Besides I have been using it against a Microsoft Exchange Server (ActiveSync language) without problems in the communication.
If you need to use it please go ahead and share your feelings with me. Remember that WBXML is a very odd format and it is almost impossible to deal with it without understanding its specification. So although wbxml-stream lets you manage WBXML documents exactly as a XML one, it is convenient that you read the standard before. In case you have to define a new language it is compulsory. If any bug or problem is detected please inform me using this blog or github.
Enjoy wbxml-stream!
Comments