InputMapMultiple.jws Sample

This topic inludes the source code for the InputMapMultiple.jws Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/xqueryMap/

Sample Source Code


01 package xqueryMap;
02 
03 /**
04  * This web service illustrates how you can use an XQuery map on a method whose
05  * parameter values are arrays.
06  
07  * @common:xmlns namespace="http://openuri.org/bea/samples/workshop/xmlmap/inputMultiple" prefix="ns0"
08  * @common:target-namespace namespace="http://workshop.bea.com/InputMapMultiple"
09  */ 
10 public class InputMapMultiple implements com.bea.jws.WebService  
11 
12     /**
13      * This method accepts three arrays as parameters and returns a simple float. In order
14      * to map to the set of arrays, the XQuery map loops through the incoming XML message,
15      * extracting values and inserting them into the template represented by the map. <br/><br/>
16      
17      * To test this method, paste the contents of InputMapMultiple.xml into the Test XML
18      * window provided in Test View, then click getTotalPrice.<br/><br/>
19      
20      * In general, you may find that while the XQuery expression in the source code looks complex, 
21      * it resembles programming conventions with which you're already familiar, such as variables, 
22      * loops, and return values.<br/><br/>
23      
24      * Here are a few things to note about the XQuery in this map:<br/>
25      * - An XQuery let clause binds variables (represented by $i, $n, and so on) to the 
26      * XML resulting from a path to an item element.<br/> 
27      * - for clauses evaluate their expressions and iterate over the items in the resulting 
28      * sequence, binding a variable to each item in turn. The bound variables are then used
29      * to insert values into the template of the outgoing message.<br/>
30      * - return clauses return the result of the expressions that follow them.<br/><br/>
31      
32      * The return-xml XQuery map includes a simple path expression that finds the result of the
33      * method and inserts it into the template for the outgoing message.<br/><br/>
34      
35      * For the schema that defines the messages, see InputMapMultiple.xsd in the
36      * Schemas project of the SamplesApp application.
37      <br/>
38      
39      * @common:operation
40      * @jws:parameter-xml schema-element="ns0:order" xquery::
41      * declare namespace ns0="http://openuri.org/bea/samples/workshop/xmlmap/inputMultiple"
42      * declare namespace ns1="http://workshop.bea.com/InputMapMultiple"
43      
44      * let $i := $input/ns0:item 
45      *     return
46      *         <ns1:getTotalPrice>
47      *             <ns1:nameArr>
48      *                 {for $n in $i/ns0:name
49      *                     return
50      *                         <ns1:String>{data($n)}</ns1:String>}
51      *             </ns1:nameArr>
52      *             <ns1:amountArr>
53      *                 {for $a in $i/ns0:amount
54      *                     return
55      *                         <ns1:int>{data($a)}</ns1:int>}
56      *             </ns1:amountArr>
57      *             <ns1:priceArr>
58      *                 {for $p in $i/ns0:price
59      *                     return
60      *                         <ns1:float>{data($p)}</ns1:float>}
61      *              </ns1:priceArr>
62      *         </ns1:getTotalPrice>::
63      * @jws:return-xml schema-element="ns0:totalPrice" xquery::
64      * declare namespace ns0="http://workshop.bea.com/InputMapMultiple"
65      * declare namespace ns1="http://openuri.org/bea/samples/workshop/xmlmap/inputMultiple"
66      
67      <ns1:totalPrice>{data($input/ns0:getTotalPriceResult)}</ns1:totalPrice>
68      * ::
69      */
70     public float getTotalPrice(String [] nameArr, int [] amountArr, float [] priceArr)
71     {
72         float totalPrice = 0.0f;
73         
74         // make sure list of items isn't empty
75         ifnameArr != null )
76         {
77             // for each item, compute subtotal and add to total
78             for (int i = 0; i < nameArr.length; i++)
79             {
80                 totalPrice += amountArr[i* priceArr[i];
81             }
82         }
83         return totalPrice;
84     }
85