# CustomerDB_XMLBeanClient.jws Sample

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

## Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/database/xmlBean/

## Sample Source Code

`001 package database.xmlBean; 002 003 import databaseCustomerDb.XCustomerDocument; 004 import databaseCustomerDb.XCustomerDocument.XCustomer; 005 import databaseCustomerDb.XCustomerDocument.XCustomer.XCustomerRow; 006 import java.io.File; 007 008 /** 009 * <p>This web service is a client to the database control CustomerDB_XMLBean.jcx. 010 * 011 * <p>The methods of this web service show how XMLBeans types can be passed to and received from the control. 012 */ 013 public class CustomerDB_XMLBeanClient implements com.bea.jws.WebService 014 { 015 static final long serialVersionUID = 1L; 016 017 /** 018 * @common:control 019 */ 020 public database.xmlBean.CustomerDB_XMLBean customerDB_XMLBean; 021 022 /** 023 * Returns an XML document containing all of the data in the CUSTOMER table. 024 * 025 * @common:operation 026 */ 027 public XCustomerDocument findAllCustomersDoc() 028 { 029 return customerDB_XMLBean.findAllCustomersDoc(); 030 } 031 032 /** 033 * Returns an XML document containing all of the names in the CUSTOMER table. 034 * 035 * @common:operation 036 */ 037 public XCustomerDocument getAllCustomerNames() 038 { 039 return customerDB_XMLBean.getAllCustomerNames(); 040 } 041 042 /** 043 * Returns an XML document containing one customer. 044 * 045 * @common:operation 046 */ 047 public XCustomerDocument getCustomerByID(int key) 048 { 049 return customerDB_XMLBean.getCustomerByID(key); 050 } 051 052 /** 053 * Returns an XML document containing the requested customer's city. 054 * 055 * @common:operation 056 */ 057 public XCustomerDocument getCustomerCityByID(int key) 058 { 059 return customerDB_XMLBean.getCustomerCityByID(key); 060 } 061 062 /** 063 * Shows how to contruct a XCustomerDocument instance and pass this to the database control. 064 * The control method parses the XCustomerDocument into a SQL INSERT statement and passes the statement 065 * on to the database. 066 * 067 * @common:operation 068 */ 069 public int insertCustomerBean (int custid, java.lang.String name, java.lang.String address, 070 java.lang.String city, java.lang.String state, java.lang.String zip, 071 java.lang.String area_code, java.lang.String phone) 072 { 073 XCustomerDocument custDoc = null; 074 XCustomer cust = null; 075 XCustomerRow custRow = null; 076 077 /* 078 * Create an instance XML document. XMLBean "Document" types represent an entire XML document 079 */ 080 custDoc = XCustomerDocument.Factory.newInstance(); 081 /* 082 * Add a <XCustomer> element to the document. 083 */ 084 cust = custDoc.addNewXCustomer(); 085 /* 086 * Add a <XCustomerRow> element to the document 087 */ 088 custRow = cust.addNewXCustomerRow(); 089 /* 090 * Add <CUSTID>, <NAME>, etc. elements to the document and set their values. 091 */ 092 custRow.setCUSTID(custid); 093 custRow.setNAME(name); 094 custRow.setADDRESS(address); 095 custRow.setCITY(city); 096 custRow.setSTATE(state); 097 custRow.setZIP(zip); 098 custRow.setAREACODE(area_code); 099 custRow.setPHONE(phone); 100 101 /* 102 * The entire document now looks like this: 103 * 104 * <!DOCTYPE XCustomer SYSTEM ""> 105 * <XCustomer xmlns="java:///database/customer_db" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 106 * <XCustomerRow> 107 * <CUSTID>1111</CUSTID> 108 * <NAME>Some Name</NAME> 109 * <ADDRESS>Some Address</ADDRESS> 110 * <CITY>Some City</CITY> 111 * <STATE>Some State</STATE> 112 * <ZIP>00000</ZIP> 113 * <AREA_CODE>111</AREA_CODE> 114 * <PHONE>123-4567</PHONE> 115 * </XCustomerRow> 116 * </XCustomer> 117 * 118 * But only the <XCustomerRow> element is sent to the database control method. 119 * 120 */ 121 return customerDB_XMLBean.insertCustomerBean(custDoc.getXCustomer().getXCustomerRowArray(0)); 122 } 123 }`