KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > docoriented > client > anyposervice > AnyPOServiceBD


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  http://developer.sun.com/berkeley_license.html
3  $Id: AnyPOServiceBD.java,v 1.15 2005/08/16 06:35:54 smitha Exp $ */

4
5 package com.sun.j2ee.blueprints.docoriented.client.anyposervice;
6
7 import java.rmi.*;
8
9 import javax.xml.soap.*;
10
11 import org.w3c.dom.*;
12 import org.w3c.dom.Node JavaDoc;
13
14 import com.sun.j2ee.blueprints.docoriented.client.*;
15
16 /**
17  * Implements the Business Delegate pattern for Web services.
18  * Handles making the exchange of messages with the Web service endpoint
19  */

20 public class AnyPOServiceBD {
21     
22     private ServiceLocator serviceLocator;
23     
24     
25     public AnyPOServiceBD(){
26         serviceLocator = new ServiceLocator();
27     }
28     
29     public String JavaDoc submitPO(PurchaseOrder po) throws RequestHandlerException {
30         try {
31             //this flag is set not to generate a wrapper element
32
//like when using xsd:anyType
33
boolean wrapper = false;
34             AnyPurchaseOrderServiceSEI port = (AnyPurchaseOrderServiceSEI)
35             serviceLocator.getServicePort(JNDINames.ANY_SERVICE_REF, AnyPurchaseOrderServiceSEI.class);
36             SOAPElement requestSOAPElem = po.toXMLSOAPElement(wrapper);
37             SubmitPO req = new SubmitPO();
38             req.set_any(requestSOAPElem);
39             SubmitPOResponse response = port.submitPO(req);
40             SOAPElement responseSOAPElem = response.get_any();
41             NodeList list = ((Element)responseSOAPElem).getElementsByTagNameNS("urn:AnyPurchaseOrderService","poID");
42             String JavaDoc ret = null;
43             for (int loop = 0; loop < list.getLength(); loop++) {
44                 Node JavaDoc node = list.item(loop);
45                 if (node != null) {
46                     Node JavaDoc child = node.getFirstChild();
47                     if ((child != null) && child.getNodeValue() != null){
48                         ret = child.getNodeValue();
49                     }
50                 }
51             }
52             return ret;
53         } catch(InvalidPOException ipoe){
54             ipoe.printStackTrace(System.err);
55             throw new RequestHandlerException("Request Handler Exception: Service Endpoint Application-Defined Exception "+ipoe.getMessage(), ipoe);
56         } catch(RemoteException re){
57             re.printStackTrace(System.err);
58             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);
59         }
60     }
61 }
62
63
Popular Tags