CustomerDataImpl.jcs Sample

This topic inludes the source code for the CustomerDataImpl.jcs Sample.

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlFeatures/propEditor/

Sample Source Code


01 package propEditor; 
02 
03 import com.bea.control.*;
04 import java.util.HashMap;
05 import java.util.ArrayList;
06 import java.sql.ResultSet;
07 import java.sql.SQLException;
08 
09 /**
10  * The CustomerData control illustrates how to connect a custom attribute
11  * editing/validation dialog. The dialog ensures that the customer-id
12  * attribute is a six-digit number.
13  
14  * After specifying a value for the customer-id attribute, you can use 
15  * the control's method's to get information about the customer.
16  
17  * @jcs:control-tags file="CustomerData-tags.xml"
18  * @jcs:jc-jar label="CustomerData" 
19  *      version="0.8" 
20  *      icon-16="/images/hello_16.gif" 
21  *      icon-32="/images/hello_32.gif"
22  *      palette-priority="6" 
23  *      group-name="Feature Sample Controls"
24  *      description="Illustrates custom property editor"
25  *      @editor-info:code-gen control-interface="true"
26  */
27 public class CustomerDataImpl implements CustomerData, com.bea.control.ControlSource
28 
29     /**
30      * @common:control
31      */
32     private propEditor.CustomerDBControl customerDB;
33     
34     private String m_custIDProp;
35     private int m_custIDInt;
36 
37     /**
38      * @common:context
39      */
40     com.bea.control.ControlContext context;
41 
42     /*
43      * Use the onCreate callback handler to retrieve the attribute value set
44      * by the control's user. With the customer-id attribute stored internally,
45      * it can be used by other control methods. Remember that the onCreate callback
46      * is received when the control is created, before any control methods are called.
47      */
48     public void context_onCreate() {
49         m_custIDProp = context.getControlAttribute("jc:customer-db""customer-id");
50         m_custIDInt = new Integer(m_custIDProp).intValue();
51     }
52 
53     /**
54      * Returns the customer's company name using the nested Database control.
55      
56      * @common:operation
57      */
58     public String getCustomerName()
59     {
60         String custIDProp = context.getControlAttribute("jc:customer-db""customer-id");
61         int custIDInt = new Integer(custIDProp).intValue();
62         String customerName = customerDB.selectCustomerName(custIDInt);
63         return customerName;
64     }
65 
66     /**
67      * Returns a list of items the customer has ordered. The database includes
68      * tables for customers, items, items by order, and customers by order.
69      * This is method nests queries against these tables to produce joined
70      * results.
71      
72      * @common:operation
73      */
74     public ArrayList getItemsOrdered()
75     {
76         ArrayList itemNamesArray = new ArrayList();
77         ResultSet orderIDs = customerDB.selectOrdersByCustomer(m_custIDInt);
78         try{
79             while (orderIDs.next()){
80                 int orderID = orderIDs.getInt("orderid");
81                 ResultSet itemNumbers = customerDB.selectItemNumbersByOrder(orderID);
82                 while (itemNumbers.next()){
83                     int itemNumber = itemNumbers.getInt("itemnumber");
84                     ResultSet itemNames = customerDB.selectItemNameByItemNumber(itemNumber);
85                     while (itemNames.next()){
86                         itemNamesArray.add(itemNames.getString("itemname"));
87                     }
88                 }
89             }
90             return itemNamesArray;
91         catch(SQLException se){
92             throw new ControlException("Error while getting items ordered.", se);
93         }
94     }
95