home
NEWS       BLOGS       FORUMS       NEWSLETTERS       RESEARCH       EVENTS       DIGITAL LIBRARY       CAREERS  
Network Computing Network Computing Powered by InformationWeek Business Technology Network

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers



Netdesign Manual

Part 4

Java XML Programmers Reference

Chapter 11: XML Tools for Information Appliances


October 15, 2001


Brought to you by:





Check It Out!

Writing the XML Document

The final step is to ask handle the yes/no button click. If yes is pressed, we must open the database and write the contact (received XML) as a new record. If no is pressed, we repaint the screen with the "Waiting for contact information…" message. As we've already seen, button clicks are handled by overriding the com.sun.kjava.Spotlet.penDown() event handler. If the exit button has been pressed, we register our "owner" — the ContactBook object — as the current Spotlet event listener (remember, there is only one Spotlet listening for events at a time), and tell ContactBook to paint itself. This effectively hands control back to the main menu. The owner is set in the ReceiveContact constructor:

import com.sun.kjava.*;
import nanoxml.kXMLElement;
import nanoxml.XMLParseException;
public class ReceiveContact extends Spotlet {
private Button exitBtn = new Button("Quit", 135, 140),
yesBtn, noBtn;
private Graphics g = Graphics.getGraphics();
private ContactBook owner;
private String contact;
public ReceiveContact(ContactBook owner) {
register(NO_EVENT_OPTIONS);
this.owner = owner;
paint(); //paint the "Waiting for..." message
}
public void penDown(int x, int y) {
//did the user press the exit btn?
if (exitBtn.pressed(x,y)) {
owner.register(NO_EVENT_OPTIONS);
owner.paint();
}
//did the user press the yes btn, telling us to
//write the received contact into the database?
else if (yesBtn.pressed(x,y)) {
Database db = new Database(ContactBook.dbType,
ContactBook.creatorId, Database.WRITEONLY);
if (!db.isOpen()){ 
//the database doesn't exist yet. create it.
Database.create(0, ContactBook.dbName,
ContactBook.creatorId, ContactBook.dbType, false);
db = new Database(ContactBook.dbType,
ContactBook.creatorId, Database.WRITEONLY);
}
db.addRecord(contact.getBytes());
db.close();
paint(); //repaint the "Waiting for..." message
}
else if (noBtn.pressed(x,y))
paint();
}
public void beamReceive(byte[] buf) {
//parse the received xml using NanoXML
contact = new String(buf);
kXMLElement elem = new kXMLElement();
try {
elem.parseString(contact);
}
catch (XMLParseException e) {
//can't parse received data--the sender probably
//wasn't BeamContact!! ignore it and return.
paint();
 
return;
}
String fname = elem.getProperty("fname"), 
lname = elem.getProperty("lname");
if (fname != null && lname != null) {
g.clearScreen();
g.drawString("Contact info was received for:", 0, 20);
g.drawString(fname + " " + lname, 0, 40);
g.drawString("Import into contact book?", 0, 60);
yesBtn = new Button("Yes", 40, 80);
noBtn = new Button("No", 60, 80);
yesBtn.paint();
noBtn.paint();
}
else
paint();
}
public void paint() {
g.clearScreen();
yesBtn = noBtn = null;
exitBtn.paint();
g.drawString("Waiting for contact information...", 10,
70);
}
}

Summary

In this chapter, we examined Java and XML on lightweight clients, also known as information appliances. We talked about where XML on lightweight clients stands today, and why we need XML on lightweights.

Then we discussed the architecture of Java 2 Micro Edition: the application layer, the device profile layer, the configuration layer, and finally the operating system layer. Focusing more on the Connected Limited Device Configuration, as it is more "lightweight" than the Connected Device Configuration, we discussed the Java Kilobyte Virtual Machine, kjava, and kAWT.

Next we reviewed parsers for lightweights. Pull parsers such as kXML and XPP hold a lot of potential for information appliances, but since there is no industry-accepted standard interface, we focused on DOM-style and SAX parsers. We covered two very different versions of NanoXML in-depth, as well as NanoXML's SAX interface. We also discussed MinML with its SAX interface.

XSLT Compiler, by Sun Microsystems, was covered in detail. We wrote an XSL stylesheet, compiled a translet, and executed a small TroubleTicket application that used the translet with an input XML document. XSLTC's speedy execution and small size make it ideal for performing XSL transformations on information appliances.

SOAP on information appliances is very appealing, but library support is limited currently. It might be best to write your own library if you can't wait until kSOAP or another small library matures.

Finally, we built a peer-to-peer contact book application for the Palm OS using NanoXML, Java KVM, the Palm OS Emulator, and some GUI classes made available by Sun. This infrared beaming application prompted the user with a list of contact book entries to beam, while a receiving application waited for an XML document to insert into its contact book database.


PAGE: 1 | 2 | 3 | 4 | 5 | 6 | 7 | FIRST PAGE
 





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



InformationWeek Business Technology Network
InformationWeekInformationWeek 500InformationWeek 500 ConferenceInformationWeek AnalyticsInformationWeek CIO
InformationWeek EventsInformationWeek ReportsInformationWeek MagazinebMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingNo JitterPlug Into The Cloud
space
Techweb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0 ConferenceMobile Business ExpoSoftware ConferenceCSI - Computer Security Institute
Black HatGTECEnergy CampMashup CampStartup Camp
space
Light Reading Communications Network
Light ReadingLight Reading EuropeUnstrungLight Reading's Cable Digital NewsConstantinopleInternet EvolutionPyramid Research
Heavy ReadingLight Reading Live!Light Reading InsiderEthernet ExpoOptical ExpoTeleco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems & TechnologyInsurance & TechnologyWall Street & TechnologyAccelerating Wall StreetBank Systems & Technology Executive SummitBuyside Trading SummitInsurance & Technology Executive Summit
space
Microsoft Technology Network
MSDN MagazineTechNetThe Architecture Journal
space


App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Technology Marketing Solutions  |  Advertising Contacts  |   Briefing Centers
Copyright © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights