KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > anyposervice > POXMLUtil


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: POXMLUtil.java,v 1.8 2005/12/01 20:53:16 yutayoshida Exp $ */

4
5 package com.sun.j2ee.blueprints.anyposervice;
6
7 import java.io.*;
8 import javax.xml.soap.*;
9 import javax.xml.transform.*;
10 import javax.xml.parsers.*;
11 import javax.xml.transform.dom.*;
12 import org.w3c.dom.*;
13
14 public class POXMLUtil {
15     
16     public POXMLUtil() {
17     }
18     
19     /**
20      * Method to create a SOAPElement
21      * @param poID the ID for the purchase order created
22      * @return SOAPElement
23      * @throws Exception
24      */

25     
26     public SOAPElement createSOAPMessage(String JavaDoc poID) throws Exception JavaDoc {
27         Document doc =createDocument(poID);
28         if (doc == null)
29             throw new IOException("Problem creating DOM ,createDocument() returned null ");
30         SOAPElement parent = SOAPFactory.newInstance().createElement("dummy");
31         TransformerFactory factory = TransformerFactory.newInstance();
32         Transformer transformer = factory.newTransformer();
33         transformer.transform(new DOMSource(doc), new DOMResult(parent));
34         return (SOAPElement) parent.getChildElements().next();
35     }
36     
37     /**
38      * Creates a DOM
39      * @param poID the ID for the purchase order created
40      * @return Document
41      */

42     
43     private Document createDocument(String JavaDoc poID) throws Exception JavaDoc {
44         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
45         docBuilderFactory.setValidating(false);
46         docBuilderFactory.setNamespaceAware(true);
47         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
48         Document doc = docBuilder.newDocument();
49         Element statusElem = doc.createElementNS("urn:AnyPurchaseOrderService","Status");
50         doc.appendChild(statusElem);
51         Element elem = doc.createElement("poID");
52         elem.appendChild(doc.createTextNode(poID));
53         statusElem.appendChild(elem);
54         return doc;
55     }
56 }
57
58
Popular Tags