1 package org.codehaus.xfire.handler.dom; 2 3 import org.dom4j.Document; 4 import org.dom4j.DocumentHelper; 5 import org.dom4j.Element; 6 import org.dom4j.Namespace; 7 import org.dom4j.QName; 8 9 /*** 10 * Holds a SOAP message as a DOM4J document. There are also 11 * helper methods to grab the SOAP Body and/or Header. 12 * 13 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 14 * @since Feb 13, 2004 15 */ 16 public class Message 17 { 18 private Document message; 19 20 private Element body; 21 22 private Element header; 23 24 private String soapVersion; 25 26 public Message( Document message ) 27 { 28 this.message = message; 29 30 soapVersion = message.getRootElement().getNamespaceURI(); 31 } 32 33 /*** 34 * Creates a SOAP Envelope, Body and Header for the appropriate SOAP version. 35 */ 36 public Message( String soapVersion ) 37 { 38 message = DocumentHelper.createDocument(); 39 40 Namespace soapNamespace = Namespace.get( "soap", soapVersion ); 41 42 this.soapVersion = soapVersion; 43 44 Element envelope = message.addElement( new QName("Envelope", soapNamespace) ); 45 header = envelope.addElement( new QName("Header", soapNamespace) ); 46 47 body = envelope.addElement( new QName("Body", soapNamespace) ); 48 } 49 50 /*** 51 * @return Returns the body. 52 */ 53 public Element getBody() 54 { 55 if ( body == null ) 56 { 57 body = message.getRootElement().element( "Body" ); 58 } 59 return body; 60 } 61 62 /*** 63 * @return Returns the header. If it doesn't exist, it is created. 64 */ 65 public Element getHeader() 66 { 67 if ( header == null ) 68 { 69 header = message.getRootElement().element( "Header" ); 70 } 71 return header; 72 } 73 74 /*** 75 * @return Returns the message. 76 */ 77 public Document getMessage() 78 { 79 return message; 80 } 81 82 /*** 83 * @return Returns the soapVersion. 84 */ 85 public String getSoapVersion() 86 { 87 return soapVersion; 88 } 89 }