XsdConfig.jws Sample

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

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/xmlBeans/schema/

Sample Source Code


01 package xmlBeans.schema; 
02 
03 /**
04 
05 Package and type names as they would be generated without
06 using an XSDCONFIG file.
07 
08 import org.openuri.easypoLocal.PURCHORDERDocument;
09 import org.openuri.easypoLocal.PURCHORDERDocument.PURCHORDER;
10 import org.openuri.easypoLocal.PURCHORDERDocument.PURCHORDER.CUST;
11 import org.openuri.easypoLocal.PURCHORDERDocument.PURCHORDER.LINEITEM;
12 import org.openuri.easypoLocal.PURCHORDERDocument.PURCHORDER.SHIPPER;
13 import org.openuri.easypoLocal.NAMEDocument;
14 */
15 
16 import org.openuri.easypo.xsdconfig.PurchaseOrder;
17 import org.openuri.easypo.xsdconfig.PurchaseOrder.PurchaseOrder2;
18 import org.openuri.easypo.xsdconfig.PurchaseOrder.PurchaseOrder2.Customer;
19 import org.openuri.easypo.xsdconfig.PurchaseOrder.PurchaseOrder2.LineItem;
20 import org.openuri.easypo.xsdconfig.PurchaseOrder.PurchaseOrder2.Shipper;
21 import org.openuri.easypo.xsdconfig.Name;
22 
23 /**
24  * This web service illustrates how you can use an XSDCONFIG file
25  * to guide naming translation when the schema compiler generates
26  * an API corresponding to your schema. The schema for the XML
27  * created by this code is EasyPOLocal.xsd, in the Schemas project
28  * of the SamplesApp application. Without any configuration,
29  * compiling that schema would result in the package and type names
30  * shown in the commented import statements at the top of this
31  * web service. <br/><br/>
32  
33  * The EasyPOConfig.xsdconfig file included with the XSD file in 
34  * the Schemas project tells the schema compiler how to name and 
35  * package the types it generates. The XSDCONFIG file presents a 
36  * one-to-one mapping between schema element and proposed API name.
37  * It also gives the compiler a package name to use instead of 
38  * the namespace URI. A name such as "PurchaseOrder2" above is
39  * the schema compiler's effort to avoid a name conflict. Here, there
40  * would be a conflict between the purchase order "document" type
41  * that allows you to add a new PURCH_ORDER element to the document, and the 
42  * purchase order element that gives you access to its children. <br/><br/>
43  
44  * Note that guiding the compiler-generated naming does not affect 
45  * names and namespaces for the underlying XML. The createPO
46  * method of this web service returns the XML as it should be 
47  * shaped according to the original schema.
48  
49  * @common:target-namespace namespace="http://workshop.bea.com/XsdConfig"
50  */
51 public class XsdConfig implements com.bea.jws.WebService
52 
53     /**
54      * Creates purchase order XML from the information you enter
55      * in the parameter boxes. Note that the returned XML appears
56      * as defined by the schema even though the names for the API
57      * used to construct it have been defined in an XSDCONFIG file.
58      
59      * To test this method, enter values in the boxes and click
60      * createPO.
61      
62      * @common:operation
63      */
64     public PurchaseOrder createPO(String custName, String address, 
65         String description, int perUnitOunces, int quantity, double price)
66     {
67         PurchaseOrder poDoc = 
68             PurchaseOrder.Factory.newInstance();
69         PurchaseOrder2 po = poDoc.addNewPurchaseOrder();
70         
71         Customer cust = po.addNewCustomer();
72         cust.setName(custName);
73         cust.setAddress(address);
74         
75         LineItem item = po.addNewLineItem();
76         item.setDescription(description);
77         item.setPerUnitOunces(perUnitOunces);
78         item.setQuantity(quantity);
79         item.setPrice(price);
80 
81         return poDoc;
82     }
83