Search This Blog

Wednesday, October 24, 2007

XML Data Interchange in Java ME Applications

In this article the author shows how the Data Transfer Object design
pattern is implemented in Java ME architectures and why you might want
to use XML-based DTOs rather than Java beans for faster data interchange
between tiers. Author Mario La Menza presents an example architecture
that supports the use of XML-based DTOs and also introduces MockMe, a
free tool for generating XML-based mock objects so you can test the
presentation layer of your Java mobile applications without waiting for
server-side data. While many Java mobile application developers do go
the route of serializing DTOs, this approach is limited by the fact that
DTOs by definition have no logic, and Java ME does not support object
serialization. Without support for serialization it is not possible to
make an object exchange transparent. An alternative approach is to use
XML to encode the objects to be exchanged. In addition to the fact that
an object-XML-object mechanism doesn't differ much from object
serialization, it is readable by both computers and humans, unlike a
serialized object. Human readability simplifies the process of debugging
application code because generating different instances of the same
object is just a matter of editing an XML file. Furthermore, you can use
any browser to send a request to the server and observe its response.
Finally, using XML for data interchange means that your application can
interact with clients built using different technologies, not just Java
ME but also Java Standard Edition and .Net, for example. On the other
hand, the almost universally recognized downside of using XML for data
interchange is the inherent parsing processes and syntactic analysis
involved. Rather than spending a lot of time on this aspect of your code,
or being frustrated by Java ME's lack of support for XML, you can use
a small-memory XML parser. Examples later in this article are based on
the KXML library. More Information

No comments: