⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
JavaBeans Components</h3><a name="wp65990"> </a><h4 class="pHeading3">RetailPriceList</h4><a name="wp70911"> </a><p class="pBody"><code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/RetailPriceList.java" target="_blank">RetailPriceList</a></code> is a list of retail price items. A retail price item contains a coffee name, a wholesale price per pound, a retail price per pound, and a distributor. This data is used for two purposes: it contains the price list presented to the end user and is used by <code class="cCode">CheckoutFormBean</code> when it constructs the suborders dispatched to coffee distributors. </p><a name="wp70907"> </a><p class="pBody">It first performs a JAXR lookup to determine the JAX-RPC service endpoints. It then queries each JAX-RPC service for a coffee price list. Finally it queries the SAAJ service for a price list. The two price lists are combined and a retail price per pound is determined by adding a markup of 35% to the wholesale prices.</p><a name="wp65993"> </a><h5 class="pHeading4">Discovering the JAX-RPC Service</h5><a name="wp65994"> </a><p class="pBody">Instantiated by <code class="cCode">RetailPriceList</code>, <code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/JAXRQueryByName.java" target="_blank">JAXRQueryByName</a></code> connects to the registry server and searches for coffee distributors registered with the name <code class="cCode">JAXRPCCoffeeDistributor</code> in the <code class="cCode">executeQuery</code> method. The method returns a collection of organizations which contain services. Each service is accessible via a service binding or URI. <code class="cCode">RetailPriceList</code> makes a JAX-RPC call to each URI.</p><a name="wp65995"> </a><h4 class="pHeading3">ShoppingCart</h4><a name="wp65996"> </a><p class="pBody"><code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/ShoppingCart.java" target="_blank">ShoppingCart</a></code> is a list of shopping cart items. A <code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/ShoppingCartItem.java" target="_blank">ShoppingCartItem</a></code> contains a retail price item, the number of pounds of that item, and the total price for that item.</p><a name="wp65997"> </a><h4 class="pHeading3">OrderConfirmations</h4><a name="wp65998"> </a><p class="pBody"><code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/OrderConfirmations.java" target="_blank">OrderConfirmations</a></code> is a list of order confirmation objects. An <code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/OrderConfirmation.java" target="_blank">OrderConfirmation</a></code> contains order and confirmation objects, already discussed in <a  href="CB3.html#wp64997">Service Interface</a>.</p><a name="wp66002"> </a><h4 class="pHeading3">CheckoutFormBean</h4><a name="wp66003"> </a><p class="pBody"><code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/CheckoutFormBean.java" target="_blank">CheckoutFormBean</a></code> checks the completeness of information entered into <code class="cCode">checkoutForm</code>. If the information is incomplete, the bean populates error messages, and <code class="cCode">Dispatcher</code> redisplays <code class="cCode">checkoutForm</code> with the error messages. If the information is complete, order requests are constructed from the shopping cart and the information supplied to <code class="cCode">checkoutForm</code> and are sent to each distributor. As each confirmation is received, an order confirmation is created and added to <code class="cCode">OrderConfirmations</code>.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">if (allOk) {&nbsp;&nbsp;String orderId = CCNumber;&nbsp;&nbsp;AddressBean address = &nbsp;&nbsp;&nbsp;&nbsp;new AddressBean(street, city, state, zip);&nbsp;&nbsp;CustomerBean customer = &nbsp;&nbsp;&nbsp;&nbsp;new CustomerBean(firstName, lastName,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;(&quot; + areaCode + &quot;) &quot; + phoneNumber, email);&nbsp;&nbsp;for (Iterator d = rpl.getDistributors().iterator();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d.hasNext(); ) {&nbsp;&nbsp;&nbsp;&nbsp;String distributor = (String)d.next();&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(distributor);&nbsp;&nbsp;&nbsp;&nbsp;ArrayList lis = new ArrayList();&nbsp;&nbsp;&nbsp;&nbsp;BigDecimal price = new BigDecimal(&quot;0.00&quot;);&nbsp;&nbsp;&nbsp;&nbsp;BigDecimal total = new BigDecimal(&quot;0.00&quot;);&nbsp;&nbsp;&nbsp;&nbsp;for (Iterator c = cart.getItems().iterator(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.hasNext(); ) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShoppingCartItem sci = (ShoppingCartItem) c.next();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((sci.getItem().getDistributor()).&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;equals(distributor) &amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sci.getPounds().floatValue() &gt; 0) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price = sci.getItem().getWholesalePricePerPound().&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;multiply(sci.getPounds());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total = total.add(price);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LineItemBean li = new LineItemBean(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sci.getItem().getCoffeeName(), sci.getPounds(), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sci.getItem().getWholesalePricePerPound());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lis.add(li);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;if (!lis.isEmpty()) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderBean order = new OrderBean(address, customer, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderId, lis, total);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String SAAJOrderURL = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URLHelper.getSaajURL() + &quot;/orderCoffee&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (distributor.equals(SAAJOrderURL)) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderRequest or = new OrderRequest(SAAJOrderURL);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;confirmation = or.placeOrder(order);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderCaller ocaller = new OrderCaller(distributor);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;confirmation = ocaller.placeOrder(order);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderConfirmation oc = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new OrderConfirmation(order, confirmation);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ocs.add(oc);&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;}}<a name="wp70976"> </a></pre></div><a name="wp70875"> </a><h3 class="pHeading2">RetailPriceListServlet</h3><a name="wp70877"> </a><p class="pBody">The <code class="cCode"><a  href="../examples/cb/server/src/com/sun/cb/RetailPriceListServlet.java" target="_blank">RetailPriceListServlet</a></code> responds to requests to reload the price list via the URL <code class="cCode">/loadPriceList</code>. It simply creates a new <code class="cCode">RetailPriceList</code> and a new <code class="cCode">ShoppingCart</code>. </p><a name="wp70878"> </a><p class="pBody">Since this servlet would be used by administrators of the Coffee Break Server, it is a protected Web resource. In order to load the price list, a user must authenticate (using basic authentication) and the authenticated user must be in the <code class="cCode">admin</code> role.</p>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="CB4.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="CB6.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -