Home TOC |
![]() ![]() ![]() |
Sample Scenario
Overview
The following scenario is an example of how the Java APIs for XML might be used and how they work together. Part of the richness of the Java APIs for XML is that in many cases they offer alternate ways of doing something and thus let you tailor your code to meet individual needs. This section will point out some instances in which an alternate API could have been used and will also give the reasons why one API or the other might be a better choice.
Scenario
Suppose that the owner of a chain of coffee houses, called The Coffee Break, wants to expand the line of coffees that he sells. He instructs his business manager to find some new coffee suppliers and get their wholesale prices. The Coffee Break can analyze the prices and decide which new coffees it wants to carry and which companies it wants to buy them from. The business manager assigns the task to the company's software engineer, who decides that the best way to locate new coffee suppliers is to search a Universal Description, Discovery, and Integration (UDDI) registry, where The Coffee Break has already registered itself.
The engineer uses JAXR to send a query searching for wholesale coffee suppliers. JAXR sends messages using JAXM in the background, which ensures that the registry will be able to receive and understand it.
The UDDI registry will receive the query and apply the search criteria transmitted in the JAXR code to the information it has about the organizations registered with it. When the search is completed, the registry will send back information on how to contact the the wholesale coffee distributors that met the specified criteria.
The engineer's next step is to draft a request for price lists and send it to each of the coffee distributors using JAXM. She writes an application that gets a connection to the company's messaging service so that she can send the requests. She then creates a JAXM message, adds the request, and sends it.
Each coffee distributor receives the request, and before sending out current prices, checks with its stock quote service using JAX-RPC to get the latest quotes for the relevant coffee futures. Based on the figures they get back, the distributors send The Coffee Break their newly revised prices in an XML price sheet. The vendors use an agreed upon XML schema for their price sheets because that way they can use a format that is convenient for them and that their buyers can process easily.
Compare Prices and Order Coffees
The engineer decides to use JAXB to process the price lists. The information that the registry returned contained information for getting the DTDs that the distributors use for their price lists. Because they all use one standard DTD, the engineer can generate a set of classes from that DTD that applies to the price lists from all of the suppliers. (Otherwise, she would have used SAX or DOM to do the processing.) The engineer's application will work with each coffee as an object that has a price property and a name property. After instantiating the classes, the application gets the prices from the
Coffee
objects and compares the prices quoted by the different vendors.When the owner and business manager decide which suppliers to do business with, based on the engineer's price comparisons, they are ready to send an order. With JAXB, the engineer creates a new XML order form based on the classes generated from the price list DTD. This new order form, which contains only the coffees that the owner wants to buy, is then sent to the suppliers via JAXM. Each supplier will acknowledge receipt of the order via JAXM.
Selling Coffees on the Internet
Meanwhile, The Coffee Break has been preparing for its expanded coffee line. It will need to publish a new price list/order form in HTML for its web site. But before that can be done, the company needs to determine what prices it will charge. The engineer uses the same objects she created for comparing prices and composing the wholesale order form to access each price and multiply it by 125% to arrive at the price that The Coffee Break will charge. With a few modifications, the list of retail prices will become the online order form.
With the objects containing the new retail prices, the engineer can use JavaServer Pages
(JSP
) technology to create an HTML order form that customers can use to order coffee online. The engineer accesses the objects from the JSP page and inserts the name and the price of each Coffee object into an HTML table on the JSP page. The customer enters the quantity of each coffee he or she wants to order and clicks the Submit button to send the order.
Conclusion
Although this scenario is simplified for the sake of brevity, it illustrates how pervasive XML technologies are becoming in the world of web services. And now, with the Java APIs for XML and the J2EE platform, it keeps getting easier to implement web services and to write applications that are the consumers of web services.
Home TOC |
![]() ![]() ![]() |