Title: XML in the J2METM
1XML in the J2METM
- September 29, 2002
- from Yongwoos Park
2Acknowledgements
- JavaTM Technology and XML Programming for
Wireless Devices - A Primer, TS-1137, JavaOne
2002 - Srikanth Raju
- Raghavan "Rags" Srinivas
- Technology Evangelists
- Sun Microsystems, Inc.
- Parsing XML in the JavaTM 2 Platform, Micro
Edition (J2METM) - XML in a MIDP Environment,
Session 2716, JavaOne 2002 - Jonathan Knudsen
- Technical Writer
- Sun Microsystems, Inc.
3JavaTM Technology and XML Programming for
Wireless Devices A Primer
- TS-1137, JavaOne 2002
- Srikanth Raju
- Raghavan Rags Srinivas
4The J2ME Platform, CLDC and MIDP Overview
5Java 2 Platform
6J2ME Configuration
- A configuration for the J2ME platform ("J2ME
configuration") defines a minimum Java platform
for - Broad range of devices in different areas
- Similar requirements of memory size and
processing capabilities - A configuration defines
- Minimum Java technology libraries
- Virtual machine capabilities
- Platform Security Model
- Defined through the Java Community ProcessSM
(JCP) program - Subject to compatibility tests
7CLDC (Connected, Limited Device Configuration)
- Targeted at devices with
- 160KB to 512KB total memory available for Java
technology - Limited power (often battery)
- Limited, perhaps intermittent connectivity to a
network (often wireless) - Extremely constrained UIs, small screens
8(MIDP) Mobile information Device Profile
- Targets mobile two-way devices implementing "J2ME
CLDC" (CLDC for the J2ME platform) - Profile addresses
- Display toolkit, User input methods
- Persistent data storage using simple
record-oriented database model - HTTP 1.1-based networking using CLDC Generic
Connection framework - MIDP 1.0.3 spec and implementation available for
download now - MIDP Next Generation in progress via the JCP
program
9Example J2ME Platform-based Wireless Device Stack
10CLDC Networking and I/O
- Standard networking for the J2SE platform, I/O,
and storage libraries - Are too large for CLDC devices
- Assume TCP/IP is available
- CLDC specifies a Generic Connection framework,
which enables - Consistent way of supporting various protocols
- Improved portability of applications
- Smaller footprint
- Usage General form
- Connector.open("//")
11Scope of the MIDP Specification
- Application model (lifecycle, packaging)
- javax.microedition.midlet.MIDlet
- Persistent storage
- javax.microedition.rms
- Networking
- Implements CLDC Generic Connections
- javax.microedition.io
- User interface support
- javax.microedition.lcdui
12MIDP Networking
- MIDP devices must implement client portion of
HTTP 1.1 protocol - May or may not use IP-based transport underneath
13MIDP UI Design Principles
- Must be usable in all devices
- One handed, two handed, stylus operation
- Small screens (tens of pixels by tens of pixels)
- Not all devices have a pointing device
- Must constantly think of end users
- Mobile Information Devices are consumer products,
not desktop computers - MIDP applications should use simple traversing
and selection metaphors - MIDP applications and native apps should look and
behave consistently on any given device
14MIDP UI A Tale of Two Layers
- Use the MIDP High-level UI APIs for portability
- Apps run in all MIDP compliant devices
- No direct access to native device features
- High-level UI screens are based upon
- javax.microedition.lcdui.Screen
- Low-level APIs ("Game" APIs)
- Provide access to native drawing primitives,
device key events, native input devices, etc. - Allow developers to choose to compromise
portability for user experience, if required - Handle low level events and drive graphics via
- javax.microedition.lcdui.Canvas
15XML Overview
16Java 2 Platform and the Web Services Model
17SAX Simple API for XML
18DOM Document Object Model
19XML Transformations
- XML separates content from presentation
- Transformations can be used to convert from XML
to some other format including a new XML file - Transformations can be used to style XML
documents - Example of XML transformation
20XSLT Processor
21Using XML in Enterprise Applications for the java
platform (Enterprise Java Application)
22Using Applets With XML
- Applets can provide client-side processing of
documents - Applets can use DOM to create XML documents and
send them to a server - All validation, parsing and transformation can be
handled by the client - Any XSL stylesheets or DTDs would also have to be
delivered along with classes - Use a jar file for packaging
- Apache Xalan can be used from within an applet
23Using Servlets With XML
- Java Servlet API-based components
("Servlets")could provide server-side processing
of documents - A client could send data via a form that could
then be used to construct an XML document - Servlets eliminate the need for clients to be
XML-aware - Clients would just see transformed and styled
output (like HTML) - Apache Xalan can be used within a servlet
24Using JSP(JavaServer Pages) Technology With XML
- The JSP specification-based page ("JSP page") can
handle the task of presentation (the view) - A JavaBeans specification-based component
("JavaBeans component") can be used from the JSP
page to handle client interaction (the
controller) - Business methods of the component can manipulate
XML documents (the model) - By ensuring the use of JavaBeans components, a
cleaner separation of view from controller/model
is possible - Use the jspuseBean tag or custom tags to
manipulate XML documents
25The JMS(Java Message Service) API and XML
- The JMS API is a Java technology API to a message
service - The JMS API supports both publish/subscribe and
point-to-point - TransportMessage in the JMS API is designed for
XML - By utilizing XML, the data is as transparent as
the messaging system
26Using XML With Databases
- XML is a great fit for representing database
content - Tables map directly to an XML element tree
- Complex joins could be represented with element
nesting or attributes - The XML tree could be a logical representation of
the data - Each database query could be an XML document
- Each database result could become an XML document
27MIDlet Development Steps
- Here are the steps to follow to create and
execute your MIDlet - Write the "Java code" (Java programming
language-based code) - Compile it
- Preverify the class
- Create a Manifest file
- Package it into a Jar file
- Create the MIDlet Descriptor file
- Run the MIDlet on the emulator
28Compiling the Source
29Preverifying the Class
30Jar Up the Preverified Class
31Create the MIDlet Descriptor File
32Running the MIDlet
33The J2ME Wireless Toolkit
- Provides two GUI-based development environments
with a choice of emulators - Ktoolbar
- The Forte For Java IDE
- URL
- http//java.sun.com/products/j2mewtoolkit
- kToolBar IDE in the J2ME Wireless Toolkit
- Use kToolBar to compile, build, and execute a
MIDlet with the Emulator - Use your own editor
- Simple to use
34kToolBar (in the J2ME Wireless Toolkit, v.1.0.4)
35Parsing XML in the JavaTM 2 Platform, Micro
Edition (J2METM) - XML in a MIDP Environment
- Session 2716, JavaOne 2002
- Jonathan Knudsen
36Multi-tier System Architecture
373-tier System Architecture
38Everything Is Small in MIDP
- Network setup is slow
- Data rates are slow
- Processor is slow
- Memory is scarce
39MIDP Clients Need Server Support
- No HTML browsers here
- No complex protocols no JNDI, no RMI
- Server steps up to the plate
- Mashes data into formats the client understands
- Handles complex protocols for the client
40Three Tiers With MIDP
41Parser Roundup
42Don't Supersize Me
- Code size is constrained
- JAR size maximum is about 50 kB (varies by
carrier, manufacturer) - Available memory is generally small
- Open Source is attractive
- Customizable in size and features
- Fixable
43Parser Types
- Model
- Creates an object representation of a document in
memory (e.g., DOM) - Push
- Parses through an entire document, spitting out
events to registered listeners (e.g., SAX) - Pull
- Parses a little at a time, returning a single
element or tag
44The Small Parser Lineup
45Links
46Near Misses
- NanoXML 2.2 Lite
- 6 kB
- http//nanoxml.sourceforge.net/
- XMLtp 1.7
- 25 kB
- http//members.tripod.de/xmltp/
47Porting Techniques
- Remove features you dont need
- Supply missing classes
- java. naming is questionable
- Dummy classes or real implementations
- Rewrite unavailable functionality
48Performance Consideration
49Overview
- Not specific to XML applications
- An XML parser may push you to the wall
- Runtime performance
- Connection setup number of documents
- Connection speed document size
- User perception
- Deployment
- Code size
50Document Design
- Connection setup time is long
- Make each document count
- Perhaps aggregate documents on the server
- Connection speed is slow
- Only send essential information
- Make documents as short as possible
51Threading
- Network activity has to go in a separate thread
- Don't lock up the application's interface
- Ideally, allow the user to do other work while
network activity occurs in the background - Parsing should likely occur in a separate thread
- Depends on your parser
- Depends on your document
52Code Size
- Carriers or devices may impose restrictions on
code size - Nextel/Motorola 50 kB (soft)
- Devices don't have much storage space
- Wireless bandwidth is small
- Code size refers to the size of the MIDlet suite
JAR - .class files
- Resource files (images, icons, others)
- Use an obfuscator to reduce class file size
53What Does an Obfuscator Do?
- Depends on the product read the documentation
- Original purpose was to render code impervious to
decompilation - Some possibilities
- Removes unused classes
- Removes unused methods and variables
- Renames classes, packages and variables
- Adds illegal stuff that confuses decompilers
54Using an Obfuscator
- The obfuscator may not play nicely with your
development environment - Build without obfuscation
- Compile ? Preverify ? JAR
- Build with obfuscation
- Compile ? Obfuscate ? Preverify ? JAR
- Another possibility
- Compile ? Preverify ? JAR4Obfuscate ? Preverify ?
JAR
55Some Free Stuff
- JAX
- http//www.alphaworks.ibm.com/tech/JAX/
- Removes unused classes and interfaces
- Prunes unused methods and variables
- Shortens internal method and field names
- Retroguard
- http//www.retrologic.com/retroguard-main.html
- Renames class, method, and field names
56DEMO
57An example of the output from Meerkat
58RSSPaser.java and RSSListener.java
59RSSMIDlet.java
60DEMO
- Sample XML Midlet Interaction with the
Middle-tier
61MIDP and XML-Issues to Be Aware of
- MIDP networking allows access to data formats
such as XML, WML, etc. - XML Parsing Heavy String Manipulation
- Adding XML parser adds to footprint
- MIDP_NG proposal calls for an XML parser
- Of course, as always think about alternatives
- Example
- XML parsing on the Server instead of the MIDP
Client
62ServletXML.java
63ServletXML.java
64ServletXML.java
65HelloMIDlet.java
66HelloMIDlet.java
67HelloMIDlet.java
68HelloMIDlet.java
69HelloMIDlet.java
70HelloMIDlet.java
71Summary
- MIDlet and XML
- The J2ME platform, CLDC, and MIDP Technical
Overview - XML Overview and XML in enterprise Java
technology - Developing a MIDlet - Steps
- MIDlet accessing XML data in enterprise Java
technology - Three-tier application architecture
- May include XML and transformations for different
client types - May make sense to send XML to a MIDP client
- Various small parsers exist
- Differentiated by execution model, license, size
- Optimizations
- Document size, network connections
- Code size
72Resources
- Parsing XML in J2ME
- http//wireless.java.sun.com/midp/articles/parsing
xml/ - Connected, Limited Device Configuration
- http//java.sun.com/products/cldc
- Mobile Information Device Profile
- http//java.sun.com/products/midp
- Download the Sun J2ME Wireless Toolkit
- http//java.sun.com/products/j2mewtoolkit
- The J2ME Platform and Wireless Webcasts
- http//java.sun.com/jdc/onlineTraining/webcasts
73?? ??
74Questions
from Yongwoos Park ywoopark_at_penta.co.kr