1 4 5 package com.sun.j2ee.blueprints.anytypeposervice; 6 7 import java.io.*; 8 import java.util.Date ; 9 10 import javax.xml.soap.*; 11 import javax.xml.transform.*; 12 import javax.xml.parsers.*; 13 import javax.xml.transform.dom.*; 14 15 import org.w3c.dom.*; 16 import org.xml.sax.*; 17 18 public class POXMLUtil { 19 20 private DocumentBuilderFactory factory; 21 22 23 public POXMLUtil() { 24 factory = DocumentBuilderFactory.newInstance(); 25 factory.setValidating(false); 26 factory.setNamespaceAware(true); 27 } 28 29 35 36 public SOAPElement createSOAPMessage(String poID) throws Exception { 37 Document doc = createDOMFromString(poID); 38 if (doc == null) 39 throw new IOException("Problem reading cand creating DOM from file,readFileCreateDocument() returned null "); 40 41 SOAPElement parent = SOAPFactory.newInstance().createElement("dummy"); 42 TransformerFactory factory = TransformerFactory.newInstance(); 43 Transformer transformer = factory.newTransformer(); 44 transformer.transform(new DOMSource(doc), new DOMResult(parent)); 45 return (SOAPElement) parent.getChildElements().next(); 46 } 47 48 49 54 55 private Document createDOMFromString(String poID) throws Exception { 56 57 DocumentBuilder parser = factory.newDocumentBuilder(); 59 InputSource in = new InputSource(); 60 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 61 "<tns:BusinessDocumentReply xmlns:tns=\"urn:AnyTypePurchaseOrderService\">\n" + 62 "<tns:Status xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://com.sun.j2ee.blueprints.anytypeposervice/types PurchaseOrderStatus.xsd\">\n" + 63 " <orderid> "+ poID + " </orderid>\n" + 64 " <timestamp>"+ new Date ().toString()+"</timestamp>\n" + 65 "</tns:Status>\n" + 66 "</tns:BusinessDocumentReply>"; 67 in.setCharacterStream(new StringReader(xml)); 68 Document dom = parser.parse(in); 69 return dom; 70 } 71 } 72 | Popular Tags |