Java Reference
In-Depth Information
The code begins with static definitions of the various fields the object now stores,
along with static String declarations for the various bits of XML the code uses when
building up its XML representation. Much of the class remains unchanged from Chapter 6,
except the addition of new fields and accessor/mutator methods for these fields; the
toBytes and fromBytes methods have changed to serialize the new fields using the same
tag-value system I introduced in the discussion about record stores in Chapter 6. The
toXml method constructs the XML in a StringBuffer instance by appending the preamble
and bits of static XML along with the values of each member variable. This technique is
crude, but it works well; depending on the kind of object you want to represent as XML,
you can often streamline the code a bit, such as when you have vectors of similar objects.
If you've spent a fair amount of time using Java, you might look at the toXml method
and be tempted to do something similar with Java reflection, creating a generic XML
encoder object that takes an instance of an object, interrogates the object for member
fields, and writes XML based on the type and contents of each field. This is an excellent
approach for Java SE, because Java SE provides reflection, but unfortunately the
approach falls short on Java ME devices, because as I discuss in Chapter 2, the CLDC
lacks support for reflection. If your code is destined to run only on the CDC, a reflection-
oriented approach may well make sense.
Introducing the J2ME Web Services Specification
The J2ME Web Services Specification (as its name indicates, its development predates the
Java ME platform, and it's an option for both CLDC- and CDC-based devices) that JSR
172 describes provides two additions to the Java ME platform: access to remote SOAP-
based web services, and a push XML parser. These additions—collectively called the
optional Web Services Specification—are both optional; a platform implementing JSR
172 can offer SOAP-based web services support, a push XML parser, or both. Many
advanced mobile devices today include both portions of JSR 172, although it's not avail-
able everywhere; as with other optional specifications, it's important to confirm the
availability of the specified API on your device targets early in product development.
The implementation of SOAP-based web services support is a subset of Java API for
XML-based RPC ( JAX-RPC), the Java interface to web-based RPC services. This subset
provides the client implementation of JAX-RPC, including marshalling and
unmarshalling (between Java and SOAP) of boolean , byte , short , int , long , String , arrays,
and complex types and static stub-based invocation of RPC calls by the client. Due to
platform limitations, it's not a full implementation of JAX-RPC; devices implementing the
specification cannot offer service end points or use extensible type mapping.
Applications using the JAX-RPC support must follow these steps:
1. At compile time, define and generate a stub from the WSDL description of the
service.
2. At runtime, instantiate an instance of the stub.
 
Search WWH ::




Custom Search