📄 cb5.html
字号:
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) { String orderId = CCNumber; AddressBean address = new AddressBean(street, city, state, zip); CustomerBean customer = new CustomerBean(firstName, lastName, "(" + areaCode + ") " + phoneNumber, email); for (Iterator d = rpl.getDistributors().iterator(); d.hasNext(); ) { String distributor = (String)d.next(); System.out.println(distributor); ArrayList lis = new ArrayList(); BigDecimal price = new BigDecimal("0.00"); BigDecimal total = new BigDecimal("0.00"); for (Iterator c = cart.getItems().iterator(); c.hasNext(); ) { ShoppingCartItem sci = (ShoppingCartItem) c.next(); if ((sci.getItem().getDistributor()). equals(distributor) && sci.getPounds().floatValue() > 0) { price = sci.getItem().getWholesalePricePerPound(). multiply(sci.getPounds()); total = total.add(price); LineItemBean li = new LineItemBean( sci.getItem().getCoffeeName(), sci.getPounds(), sci.getItem().getWholesalePricePerPound()); lis.add(li); } } if (!lis.isEmpty()) { OrderBean order = new OrderBean(address, customer, orderId, lis, total); String SAAJOrderURL = URLHelper.getSaajURL() + "/orderCoffee"; if (distributor.equals(SAAJOrderURL)) { OrderRequest or = new OrderRequest(SAAJOrderURL); confirmation = or.placeOrder(order); } else { OrderCaller ocaller = new OrderCaller(distributor); confirmation = ocaller.placeOrder(order); } OrderConfirmation oc = new OrderConfirmation(order, confirmation); ocs.add(oc); } }}<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 + -