Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Subscription to WebLogic Pro

XMLBeans Bind XML to the Future (Continued)

The methodology for updating an item in the inventory is mostly the same, except for the SQL expression. Retrieving the XML instance representation from the factory is a one-step operation. Retrieving the inventory is a little more complicated, but not by much. Our control returns an array of VehicleDocument.Vehicles. The Web service, on the other hand, will return a VehicleListDocument. Luckily, a VehicleListDocument is merely a factory class that represents an array of VehicleDocument.Vehicle objects. All we need to do is create a new VehicleListDocument, use it to create a new VehicleListDocument.VehicleList, and assign to it our retrieved VehicleDocument.Vehicle array:

public VehicleListDocument 
  findAllVehicles()
{
  VehicleDocument.Vehicle[] 
    vehicles = vehicleControl.
    getAllVehicles();
      VehicleListDocument 
        vehicleListDoc = 
        VehicleListDocument.
        Factory.newInstance();
      VehicleListDocument.
        VehicleList vehicleList = 
        vehicleListDoc.
        addNewVehicleList();
      vehicleList.setVehicleArray(
        vehicles);

      return vehicleListDoc;
}
ADVERTISEMENT

XMLBeans objects can be used to create new XML instances quickly and easily.

After the Web service has been created, we can generate the Web Services Description Language (WSDL) file and then use it to create a Web service client. When generating the client, Workshop recognizes automatically that our XMLBeans match the methods within the service (see Figure 2). This notification may seem like no great feat because we did develop the Web service to specify returning our XMLBeans, and at this point I'd have to agree. However, we'll soon discuss this same notification, but in a much greater circumstance.

The Web Service Client
Our PageFlow will rely on the service client to manage the vehicle inventory. The PageFlow should provide a user with the ability to view all items in the inventory and modify and create items. Also, to further demonstrate the power of XMLBeans, we will also allow the user to filter the results based on the status (new or used) of the vehicles. This filter, behind the scenes, will use XPath to select the appropriate vehicles. XPath is a syntax that is used to locate specific elements within XML documents based on a certain criterion. We will discuss the major pieces of functionality involved within the PageFlow shortly. (The entire source code is available online.)

First, let's examine displaying the inventory to the user. We know that our inventory service is returning a VehicleListDocument, and we also know that this object is basically a representation of a VehicleDocument.Vehicle array. That array would be the perfect object to use for our display. In the steps for retrieving the VehicleDocument.Vehicle array from our VehicleListDocument, the inventory variable is declared within PageFlow scope so that it will be accessible from within our JavaServer Pages (JSP):

vehicleListDoc = vehicleInventory.
  findAllVehicles();
inventory = vehicleListDoc.
  getVehicleList().
  getVehicleArray();



Back to top












Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTPOnline Home