📄 package-summary.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Fri Dec 05 15:19:25 PST 2003 -->
<TITLE>
examples.xml.orderParser (WebLogic Server 8.1 Examples)
</TITLE>
<META NAME="keywords" CONTENT="examples.xml.orderParser package">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
</HEAD>
<SCRIPT>
function asd()
{
parent.document.title="examples.xml.orderParser (WebLogic Server 8.1 Examples)";
}
</SCRIPT>
<BODY BGCOLOR="white" onload="asd();">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</td><td valign=bottom align=right><b>WebLogic Server 8.1 Code Examples</b>, BEA Systems, Inc.</td></EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../examples/xml/package-summary.html"><B>PREV PACKAGE</B></A>
<A HREF="../../../examples/xml/sax/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A>
<SCRIPT>
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<H2>
Package examples.xml.orderParser
</H2>
This example illustrates how to use the WebLogic XML Streaming API to parse
an XML document and bind its elements to Java business objects.
<P>
<B>See:</B>
<BR>
<A HREF="#package_description"><B>Description</B></A>
<P>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Class Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="Client.html">Client</A></B></TD>
<TD>Initiates the parsing of an XML document into
business objects using the XMLInputStream API.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="CustomerBO.html">CustomerBO</A></B></TD>
<TD>Data representation of a customer.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ItemBO.html">ItemBO</A></B></TD>
<TD>Data representation of an item.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="OrderBO.html">OrderBO</A></B></TD>
<TD>Data representation of an order.
</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="OrderConstants.html">OrderConstants</A></B></TD>
<TD>Constants used while parsing an order XML document.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="StreamParser.html">StreamParser</A></B></TD>
<TD>Demonstrates the parsing of an XML document into
business objects using the XMLInputStream API.</TD>
</TR>
</TABLE>
<P>
<A NAME="package_description"><!-- --></A><H2>
Package examples.xml.orderParser Description
</H2>
<P>
<P>This example illustrates how to use the WebLogic XML Streaming API to parse
an XML document and bind its elements to Java business objects.
<p>
The client application that drives the example is called <tt>Client</tt>. This
simple Java application takes a single parameter: an XML file that describes an
order. In the example, this file is called <tt>order.xml</tt>. The
<tt>Client</tt> application then creates a <tt>StreamParser</tt> 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 <tt>Client</tt>
application prints out the resulting business object.
<p>
The <tt>StreamParser</tt> class contains the following methods, mostly called
in the order shown:
<ul>
<li><tt>getInputStream()</tt>: creates an XML input stream from the
<tt>order.xml</tt> file using the <tt>XMLInputStreamFactory.newInputStream()</tt>
method.
</li>
<p>
<li><tt>parse()</tt>: parses the XML document <tt>order.xml</tt>. This method first uses
the <tt>XMLInputStream.skip()</tt>, <tt>XMLInputStream.next()</tt>, and
<tt>XMLInputStream.getName().getLocalName()</tt> methods to ensure that the root
element of the order XML file is <tt><order></tt>. If
it is, then the <tt>parse()</tt> method creates a new <tt>OrderBO</tt> business
object that will contain the order. The <tt>OrderBO</tt> and other business objects
are described later in this section.
<p>The method then uses the <tt>XMLInputStream.skip()</tt>,
<tt>XMLInputStream.peek()</tt>, and <tt>XMLInputStream.getName().getLocalName()</tt>
methods to search the input stream for customer
and itemlist information, described by the <tt><customer></tt> and
<tt><itemlist></tt> elements respectively. Once it finds one of the
elements, it uses the <tt>XMLInputStream.getSubstream()</tt> method to get
the respective child element (either <tt><customer></tt> or
<tt><itemlist></tt>), then calls either the <tt>processCustomer()</tt> or
<tt>processItemList()</tt> methods to process the substream and create
<tt>CustomerBO</tt> or <tt>ItemBO</tt> business objects.
</li>
<p>
<li><tt>processCustomer()</tt>: this method first instantiates a <tt>CustomerBO</tt>
business object, then iterates through the <tt><customer></tt> substream
using the <tt>XMLInputStream.skip()</tt>, <tt>XMLInputSream.peek()</tt>, and
<tt>XMLInputStream.next()</tt> methods, searching for known customer element
names to populate the <tt>CustomerBO</tt> business object. The method uses the
<tt>CustomerBO.setXXX()</tt> methods to populate each field (<tt>firstName</tt>,
<tt>lastName</tt>, and so on) of the customer business object.
</li>
<p>
<li><tt>processItemList()</tt>: iterates over the <tt><itemlist></tt>
substream, looking for <tt><item></tt> elements. When it finds one, it
uses the <tt>XMLInputStream.getSubStream()</tt> method to get the
<tt><item></tt> substream and passes it to the <tt>processItem()</tt>
method for further processing.
</li>
<p>
<li><tt>processItem()</tt>: this method first instantiates a <tt>ItemBO</tt>
business object, then iterates through the <tt><item></tt> substream
using the <tt>XMLInputStream.skip()</tt> and <tt>XMLInputSream.peek()</tt>
methods, searching for known item elements to populate the <tt>ItemBO</tt> business object. The method uses the <tt>ItemBO.setXXX()</tt> methods to populate each
field (<tt>description</tt>, <tt>quantity</tt>, and so on) of the item business
object. Finally, once the item has been processed, the <tt>ItemBO</tt> business
object is added to the current <tt>Vector</tt> of items associated with the
current <tt>OrderBO</tt>.
</li>
<p>
<li><tt>getAttribute()</tt>: helper method that gets the value of a known
attribute of an element based on the attribute's name. The method first creates
an <tt>AttributeIterator</tt> object that contains all the attributes of a
given element, then iterates over the set of attributes using the
<tt>AttributeIterator.hasNext()</tt> and <tt>AttributeIterator.next()</tt>
methods, searching for a particular attribute based on the name passed to the
<tt>getAttribute()</tt> method.
</li>
<p>
<li><tt>getOrderBO()</tt>: prints out the <tt>OrderBO</tt> business object
after the <tt>order.xml</tt> file has been fully parsed and processed.
</li>
</ul>
<p>
The <tt>OrderBO</tt> business object describes an order. It contains the following
fields, along with respective getter and setter methods to get and set the values:
<ul>
<li><tt>number</tt> that contains the order number.</li>
<li><tt>customerBO</tt> that contains a <tt>CustomerBO</tt> object.</li>
<li><tt>items</tt> that contains a <tt>Vector</tt> of <tt>ItemBO</tt> objects.</li>
</ul>
The <tt>OrderBO</tt> business object also has a <tt>printOrder</tt> method to
print out the order once the order XML file has been fully processed.
The <tt>CustomerBO</tt> business object describes a customer. It contains
the following <tt>String</tt> fields, along with respective getter and setter
methods to get and set the values:
<ul>
<li><tt>firstName</tt></li>
<li><tt>lastName</tt></li>
<li><tt>street</tt></li>
<li><tt>city</tt></li>
<li><tt>state</tt></li>
<li><tt>zip</tt></li>
</ul>
The <tt>ItemBO</tt> 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:
<ul>
<li><tt>number</tt></li>
<li><tt>description</tt></li>
<li><tt>quantity</tt></li>
<li><tt>price</tt></li>
</ul>
Finally, the <tt>OrderConstants</tt> class contains the list of element
names that appear in the <tt>order.xml</tt> file, such as <tt><order></tt>,
<tt><customer></tt>, <tt><itemlist></tt>, and so on. This class
is used in the <tt>StreamParser</tt> class when iterating over the
<tt>order.xml</tt> file, looking for known elements.
<p>
<!-- this table matches the generated table of classes and methods -->
<!-- but is not generated -->
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Additional Resources for examples.xml.orderParser</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B>order.xml</B></TD>
<TD>XML document to be parsed containing a single order.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B>build.xml</B></TD>
<TD>The Java Ant build script compiles the example.</TD>
</TR>
</TABLE>
</b>
<p>
<P>The following sections describe how to build and run the example.
<P>
<ol>
<li><a href="#prereqs">Prerequisites</a>
<li><a href="#build">Build the Example</a>
<li><a href="#run">Run the Example</a>
<li><a href="#output">Check the Output</a>
</ol>
<p>
<h3><a name="prereqs">Prerequisites</a></h3>
<p>
Before you run this example, you need:
<ul>
<li> WebLogic Server Version 8.1
</ul>
<p>
<h3><a name="build">Build the Example</a></h3>
To build the example, follow these steps:
<ol>
<li> Set up your development shell as described in <a href=../../examples.html#quick>Quick Start</a>.
<p>
<li> Change to the <tt><i>SAMPLES_HOME</i>\server\examples\src\examples\xml\orderParser</tt> directory, where <i>SAMPLES_HOME</i> refers to the main WebLogic Server
examples directory, such as <tt>d:\beahome\weblogic81\samples</tt>.
<p>
<li>Assemble and compile the example by executing the <a href=../../examples.html#buildScripts>Java ant utility</a> at the command line:
<pre><font face="Courier New">prompt> <b>ant</b></font></pre>
<p>The <tt>ant</tt> utility uses the <tt>build.xml</tt> build script, which
compiles the <tt>OrderConstants</tt>, <tt>OrderBO</tt>, <tt>CustomerBO</tt>,
<tt>ItemBO</tt>, <tt>StreamParser</tt>, and <tt>Client</tt> Java source files.
</ol>
<p>
<H3><A name="run"></A>Run the Example</H3>
<ol>
<li><a href=../../examples.html#startServer>Start the examples WebLogic Server</a>.
<br><br>
<LI>In your development shell, run the <tt>Client</tt> Java application using the
following command:
<PRE><FONT face="Courier New">prompt><b> ant run </B></FONT></PRE>
</ol>
<p>
<h3><a name="output"></a>Check the Output</h3>
<p>You should see the following output if the example runs successfully:
<br>
<br>Printing contents of OrderBO...
<br>
<br>Order Number:
<br> 1234
<br>Customer Info:
<br> John Doe
<br> 2000 Pine St
<br> San Francisco, CA 94403
<br>Order Info:
<br> 4321 Stuffed Pastry 10x2.95
<br> 8765 Chocolate 5x9.5
<br> 9922 Cookie 30x0.85
<br>
<br>Successfully handled the document
<p>
<h2>See Also</h2>
Read more about:
<ul>
<li>XML in
<a href="http://e-docs.bea.com/wls/docs81/xml/index.html">Programming WebLogic XML</a>.
</ul>
<P>
<P>
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</td><td valign=bottom align=right>Documentation is available at<br> <a href=http://e-docs.bea.com/wls/docs81>http://e-docs.bea.com/wls/docs81</a></td></EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../examples/xml/package-summary.html"><B>PREV PACKAGE</B></A>
<A HREF="../../../examples/xml/sax/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A>
<SCRIPT>
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<a href=http://e-docs.bea.com/wls/docs81/copyright.html>Copyright</a> © 2003 BEA Systems, Inc. All Rights Reserved.
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -