KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > docoriented > client > objectposervice > SchemaPOServiceBD


1 /* Copyright 2005 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
2
3  http://developer.sun.com/berkeley_license.html
4
5  $Id: SchemaPOServiceBD.java,v 1.17 2005/06/02 03:20:04 sean_brydon Exp $ */

6
7
8
9 package com.sun.j2ee.blueprints.docoriented.client.objectposervice;
10
11
12
13 import java.rmi.*;
14
15 import javax.naming.*;
16
17 import javax.xml.rpc.*;
18
19
20
21 import com.sun.j2ee.blueprints.docoriented.client.*;
22
23
24
25 /**
26
27  * Implements the Business Delegate pattern for Web services.
28
29  * Handles making the exchange of messages with the Web service endpoint
30
31  */

32
33 public class SchemaPOServiceBD {
34
35     
36
37     private ServiceLocator serviceLocator;
38
39      
40
41     public SchemaPOServiceBD(){
42
43         serviceLocator = new ServiceLocator();
44
45     }
46
47     
48
49     /**
50
51      * Accepts the PurchaseOrder built from client GUI inputs, and then
52
53      * creates a PurchaseOrder.java object that is generated from the
54
55      * service endpoint WSDL file.
56
57      */

58
59     public String JavaDoc submitPO(com.sun.j2ee.blueprints.docoriented.client.PurchaseOrder po) throws RequestHandlerException {
60
61         
62
63         try {
64
65             SchemaDefinedPurchaseOrderServiceSEI port = (SchemaDefinedPurchaseOrderServiceSEI)
66
67             serviceLocator.getServicePort(JNDINames.SCHEMA_SERVICE_REF, SchemaDefinedPurchaseOrderServiceSEI.class);
68
69                       
70
71             //create a Purchase Order object that is to be sent to the endpoint
72

73             Address shipTo = new Address();
74
75             shipTo.setStreet(po.getShipTo().getStreet());
76
77             shipTo.setCity(po.getShipTo().getCity());
78
79             shipTo.setState(po.getShipTo().getState());
80
81             shipTo.setPostalCode(po.getShipTo().getPostalCode());
82
83             
84
85             Address billTo = new Address();
86
87             billTo.setStreet(po.getBillTo().getStreet());
88
89             billTo.setCity(po.getBillTo().getCity());
90
91             billTo.setState(po.getBillTo().getState());
92
93             billTo.setPostalCode(po.getBillTo().getPostalCode());
94
95             
96
97             com.sun.j2ee.blueprints.docoriented.client.LineItem[] items = po.getItems();
98
99             LineItem item1 = new LineItem();
100
101             item1.setItemId(items[0].getItemId());
102
103             item1.setQuantity(items[0].getQuantity());
104
105             item1.setPrice(items[0].getPrice());
106
107             
108
109             LineItem item2 = new LineItem();
110
111             item2.setItemId(items[1].getItemId());
112
113             item2.setQuantity(items[1].getQuantity());
114
115             item2.setPrice(items[1].getPrice());
116
117                     
118
119             LineItem[] lineItems = new LineItem[2];
120
121             lineItems[0] = item1 ;
122
123             lineItems[1] = item2 ;
124
125             
126
127             PurchaseOrder order = new PurchaseOrder();
128
129             order.setPoId(po.getPoId());
130
131             order.setCreateDate(po.getCreateDate());
132
133             order.setShipTo(shipTo);
134
135             order.setBillTo(billTo);
136
137             order.setItems(lineItems);
138
139             
140
141             String JavaDoc ret = port.submitPO(order);
142
143             return ret;
144
145             
146
147         } catch(InvalidPOException ipoe){
148
149             ipoe.printStackTrace(System.err);
150
151             throw new RequestHandlerException("Request Handler Exception: Service Endpoint Application-Defined Exception "+ipoe.getMessage(), ipoe);
152
153         } catch(RemoteException re){
154
155             re.printStackTrace(System.err);
156
157             throw new RuntimeException JavaDoc("The web service you are trying to access is not available. A possible reason could be that the service has not been deployed yet. "+ re.getMessage(), re);
158
159         }
160
161     }
162
163 }
164
165
166
167
Popular Tags