B2B with XML
HRS Module Uses XML to Exchange Data
August 2000 |
 |
Contents
|
The sample app's main module is a servlet
called the Hotel Reservation System (HRS). It uses two databases: one
stores information about domestic hotels, the other stores information
about international hotels (also called third-party hotels). The
HRS manages the domestic hotel database directly, but operates on a copy
of the third-party hotel database. A separate module, the Third
Party Hotel System (TPHS), manages the original third-party hotel
database and sends email to the HRS administrator whenever the third-party
hotel database changes.
|
The HRS provides interfaces for end-users (customers) and adminstrators:
- The user interface (HRS-U) enables customers to make
and cancel room reservations. Another module, the Travel
Discount Provider (TDP), provides an XML document containing discount
data for each reservation the customer makes.
- The admin interface (HRS-A) enables system administrators
to read email sent by the TPHS and it updates the third-party hotel tables
in its local schema. It also updates the currency exchange rates using data
provided by the Exchange Rate Provider (ERP) module.
End-User Interface (HRS-U)
The HRS-U interface displays HTML pages and processes user input. As a customer
makes room reservations, the HRS stores the data in a virtual shopping cart.
When the customer is finished, the HRS processes the items in the cart. The
class xmla2a.hrs.HRSServletHTML implements most of this functionality.
For example, the method generateMainPageHTML generates the HTML
for the main page when the servlet is invoked for the first time.
public static String generateMainPageHTML() { return "<HTML><HEAD><TITLE> E-Hotel </TITLE></HEAD>\n"+ "<FRAMESET ROWS=\"65%,35%\" noresize border=\"0\" >\n"+
"<FRAMESET COLS=\"30%,70%\" noresize >\n"+ "<FRAME SRC =\""+HRSServlet.s_servletPath+"?REQ_TYPE=PICTURE\" name=\"left1\">\n"+ "<FRAME SRC=\""+HRSServlet.s_servletPath+"?REQ_TYPE=ALL_HOTELS\" name=\"right1\"\n>"+ "</FRAMESET>\n"
"<FRAMESET COLS=\"30%,70%\" noresize >\n"+ "<FRAME SRC =\""+HRSServlet.s_servletPath+"?REQ_TYPE=ADMIN\" name=\"left2\">\n"+ "<FRAME SRC=\""+HRSServlet.s_servletPath+"?REQ_TYPE=BUTTON\" name=\"right2\">"+ "</FRAMESET>\n"+ "<FRAMESET COLS=\"30%,70%\" noresize >\n"+ "<FRAME SRC =\""+HRSServlet.s_servletPath+"?REQ_TYPE=ADMIN\" name=\"left2\">\n"+ "<FRAME SRC=\""+HRSServlet.s_servletPath+"?REQ_TYPE=BUTTON\" name=\"right2\">"+ "</FRAMESET>\n"+
"</FRAMESET><BODY></BODY></HTML>\n";
}
|
One phase of processing a reservation involves finding out whether the user
is eligible for a discounted room rate (for example, a hotel might offer Diner's
Club members a 15 percent discount). The HRS module contacts the Travel
Discount Provider (TDP) module to get this information.
Administrator Interface (HRS-A)
The HRS-A interface enables an administrator to manage various aspects of the
hotel reservation system, including:
- Maintaining a local copy of the Third-Party Hotel database. The original
Third-Party Hotel database is maintained by the adminstrator of the Third-Party
Hotel System (TPHS). When the original database changes, the TPHS admin
emails an XML document to the HRS admin. When the HRS admin reads the mail,
the system updates the local copy of the database.
- Updating a table of international currency exchange rates. Periodically,
the Exchange Rate Provider (ERP) module sends an
XML file via FTP to the HRS. The HRS-A interface provides an "Update
Exchange Rates" option that parses the file and updates the table.
Reading Email to Update the Database
The following code is from xmla2a.hrs.XmlTPUpdate.processMail.
It does the following:
- Identifies the message by the parameter
p_mailId.
- Reads the message and uses the DOM Parser provided by the Oracle
XML Parser for Java to process the XML data in the message body.
- Uses the parsed data to update the local copy of the database.
- Applies an XSL stylesheet to transform the XML to HTML.
- Displays the HTML to the HRS admin.
- Deletes the message.
void processMail(String p_mailId, HttpServletResponse p_response) throws Exception {
// Set parameters for the servlet response. p_response.setHeader("pragma","no-cache"); p_response.setContentType("text/html");
// Get the mail body content.
/* m_mailHandler is a utility for sending and receiving email.
* Implemented in xmla2a/utilities/MailHandler, it uses the
* Java Mail API (in javax.mail.* and javax.mail.internet.*).
* m_mailBody is a String.
*/ m_mailBody = m_mailHandler.readMail(Integer.parseInt(p_mailId)); ByteArrayInputStream l_bis = new ByteArrayInputStream( m_mailBody.getBytes());
// Parse the input stream. DOMParser l_parser = new DOMParser(); l_parser.parse(l_bis);
// Get the XMLDocument from the parser. XMLDocument l_xmlDoc = l_parser.getDocument();
Element l_childElement ; Node l_childNode ; NodeList l_childList ;
Element l_root = l_xmlDoc.getDocumentElement(); // Get the root element. l_childList = l_root.getChildNodes(); // Get the list of updates to process. int l_childCount = l_childList.getLength();
for(int i = 0; i < l_childCount; ++i){ l_childElement = (Element)l_childList.item(i); // Get the table name. if (l_childElement.getTagName().equalsIgnoreCase("change_room_availability")){ updateRoomAvailability(l_childElement); } else if (l_childElement.getTagName().equalsIgnoreCase("change_room_rate")){ updateRoomRate(l_childElement); } else if (l_childElement.getTagName().equalsIgnoreCase("change_room_facilities")){ updateRoomFacilities(l_childElement); } else if (l_childElement.getTagName().equalsIgnoreCase("add_room_type")){ addRoomType(l_childElement); }
} m_con.commit();
// Display status messages and delete the email.
String l_html = XMLHandler.TransformXMLToHTML(l_xmlDoc,
ConnectionParams.s_pathOfFile + "xslfiles/tpUpdate.xsl"); HTMLDisplay.displaySuccessMessage(p_response, p_mailId, l_html, m_mailBody); new MailHandler().deleteMail(Integer.parseInt(p_mailId));
}
|
The following code is from xmla2a.hrs.XmlTPUpdate.updateRoomAvailability.
It updates the number of rooms available for a hotel by:
- Extracting information from a parse tree passed in as a parameter.
- Updating the database.
void updateRoomAvailability( Element p_childElement ) throws SQLException{
Element l_grandChildElement; // A temporary variable
// Get the list of elements that are under p_childElement.
NodeList l_grandChildList = p_childElement.getChildNodes() ;
String l_hotelId = l_grandChildList.item(0).getFirstChild().getNodeValue();
String l_roomType = l_grandChildList.item(1).getFirstChild().getNodeValue();
String l_newValue = l_grandChildList.item(2).getFirstChild().getNodeValue();
PreparedStatement l_stmt = m_con.prepareStatement(
" UPDATE ROOM_AVAILABILITY "+ " SET TOTAL_"+l_roomType+" = ? WHERE HOT_ID = ? ");
l_stmt.setString( 1,l_newValue );
l_stmt.setInt( 2,Integer.parseInt(l_hotelId) );
l_stmt.execute();
l_stmt.close();
}
|
Questions or comments? Post a message in OTN's Sample Code discussion
forum or send email to the author.
B2B with XML: Hotel Reservation System
Author: Robert Hall, Oracle
Corporation
Date: August 2000
This document is provided for information purposes only and
the information herein is subject to change without notice. Please report any
errors herein to Oracle Corporation. Oracle Corporation does not provide any
warranties covering and specifically disclaims any liability in connection with
this document.
Oracle is a registered trademark and Enabling the Information
Age is a trademark or registered trademark of Oracle Corporation. All other
company and product names mentioned are used for identification purposes only
and may be trademarks of their respective owners.
Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.
Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation 2000
All Rights Reserved
|