WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.xml.orderParser

This example illustrates how to use the WebLogic XML Streaming API to parse an XML document and bind its elements to Java business objects.

See:
          Description

Class Summary
Client Initiates the parsing of an XML document into business objects using the XMLInputStream API.
CustomerBO Data representation of a customer.
ItemBO Data representation of an item.
OrderBO Data representation of an order.
OrderConstants Constants used while parsing an order XML document.
StreamParser Demonstrates the parsing of an XML document into business objects using the XMLInputStream API.
 

Package examples.xml.orderParser Description

This example illustrates how to use the WebLogic XML Streaming API to parse an XML document and bind its elements to Java business objects.

The client application that drives the example is called Client. This simple Java application takes a single parameter: an XML file that describes an order. In the example, this file is called order.xml. The Client application then creates a StreamParser object which does most of the work of the example, such as parsing the XML file and populating business objects. Once all the processing is complete, the Client application prints out the resulting business object.

The StreamParser class contains the following methods, mostly called in the order shown:

The OrderBO business object describes an order. It contains the following fields, along with respective getter and setter methods to get and set the values:

The OrderBO business object also has a printOrder method to print out the order once the order XML file has been fully processed. The CustomerBO business object describes a customer. It contains the following String fields, along with respective getter and setter methods to get and set the values: The ItemBO business object describes an item in an item list. It contains the following fields, along with the respective getter and setter methods get and set the values: Finally, the OrderConstants class contains the list of element names that appear in the order.xml file, such as <order>, <customer>, <itemlist>, and so on. This class is used in the StreamParser class when iterating over the order.xml file, looking for known elements.

 
Additional Resources for examples.xml.orderParser
order.xml XML document to be parsed containing a single order.
build.xml The Java Ant build script compiles the example.

 

The following sections describe how to build and run the example.

  1. Prerequisites
  2. Build the Example
  3. Run the Example
  4. Check the Output

 

Prerequisites

Before you run this example, you need:

 

Build the Example

To build the example, follow these steps:
  1. Set up your development shell as described in Quick Start.

  2. Change to the SAMPLES_HOME\server\src\examples\xml\orderParser directory, where SAMPLES_HOME refers to the examples WebLogic Server domain directory.

  3. Assemble and compile the example by executing the Java ant utility at the command line:
    prompt> ant

    The ant utility uses the build.xml build script, which compiles the OrderConstants, OrderBO, CustomerBO, ItemBO, StreamParser, and Client Java source files.

 

Run the Example

  1. Start the examples WebLogic Server.

  2. In your development shell, run the Client Java application using the following command:
    prompt> ant run 

 

Check the Output

You should see the following output if the example runs successfully:
 
Printing contents of OrderBO...
 
Order Number:
  1234
Customer Info:
  John Doe
  2000 Pine St
  San Francisco, CA 94403
Order Info:
  4321 Stuffed Pastry 10x2.95
  8765 Chocolate 5x9.5
  9922 Cookie 30x0.85
 
Successfully handled the document

 

See Also

Read more about:


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.