XML in the J2METM - PowerPoint PPT Presentation

1 / 74
About This Presentation
Title:

XML in the J2METM

Description:

Sun ... http://java.sun.com/products/j2mewtoolkit. kToolBar IDE in the J2ME ... http://wireless.java.sun.com/midp/articles/parsingxml/ Connected, Limited ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 75
Provided by: Narci
Category:
Tags: j2metm | xml | bbs | sun

less

Transcript and Presenter's Notes

Title: XML in the J2METM


1
XML in the J2METM
  • September 29, 2002
  • from Yongwoos Park

2
Acknowledgements
  • 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.

3
JavaTM Technology and XML Programming for
Wireless Devices A Primer
  • TS-1137, JavaOne 2002
  • Srikanth Raju
  • Raghavan Rags Srinivas

4
The J2ME Platform, CLDC and MIDP Overview
5
Java 2 Platform
6
J2ME 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

7
CLDC (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

9
Example J2ME Platform-based Wireless Device Stack
10
CLDC 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("//")

11
Scope 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

12
MIDP Networking
  • MIDP devices must implement client portion of
    HTTP 1.1 protocol
  • May or may not use IP-based transport underneath

13
MIDP 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

14
MIDP 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

15
XML Overview
16
Java 2 Platform and the Web Services Model
17
SAX Simple API for XML
18
DOM Document Object Model
19
XML 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

20
XSLT Processor
21
Using XML in Enterprise Applications for the java
platform (Enterprise Java Application)
22
Using 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

23
Using 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

24
Using 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

25
The 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

26
Using 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

27
MIDlet 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

28
Compiling the Source
29
Preverifying the Class
30
Jar Up the Preverified Class
31
Create the MIDlet Descriptor File
32
Running the MIDlet
33
The 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

34
kToolBar (in the J2ME Wireless Toolkit, v.1.0.4)
35
Parsing XML in the JavaTM 2 Platform, Micro
Edition (J2METM) - XML in a MIDP Environment
  • Session 2716, JavaOne 2002
  • Jonathan Knudsen

36
Multi-tier System Architecture
37
3-tier System Architecture
38
Everything Is Small in MIDP
  • Network setup is slow
  • Data rates are slow
  • Processor is slow
  • Memory is scarce

39
MIDP 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

40
Three Tiers With MIDP
41
Parser Roundup
42
Don'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

43
Parser 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

44
The Small Parser Lineup
45
Links
46
Near Misses
  • NanoXML 2.2 Lite
  • 6 kB
  • http//nanoxml.sourceforge.net/
  • XMLtp 1.7
  • 25 kB
  • http//members.tripod.de/xmltp/

47
Porting Techniques
  • Remove features you dont need
  • Supply missing classes
  • java. naming is questionable
  • Dummy classes or real implementations
  • Rewrite unavailable functionality

48
Performance Consideration
49
Overview
  • 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

50
Document 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

51
Threading
  • 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

52
Code 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

53
What 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

54
Using 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

55
Some 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

56
DEMO
  • An Example Parsing RSS

57
An example of the output from Meerkat
58
RSSPaser.java and RSSListener.java
59
RSSMIDlet.java
60
DEMO
  • Sample XML Midlet Interaction with the
    Middle-tier

61
MIDP 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

62
ServletXML.java
63
ServletXML.java
64
ServletXML.java
65
HelloMIDlet.java
66
HelloMIDlet.java
67
HelloMIDlet.java
68
HelloMIDlet.java
69
HelloMIDlet.java
70
HelloMIDlet.java
71
Summary
  • 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

72
Resources
  • 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
?? ??
74
Questions
from Yongwoos Park ywoopark_at_penta.co.kr
Write a Comment
User Comments (0)
About PowerShow.com