1 16 package org.apache.axis2.saaj; 17 18 import org.apache.axis2.om.OMAbstractFactory; 19 import org.apache.axis2.soap.SOAPFactory; 20 21 import javax.xml.soap.*; 22 23 24 30 public class SOAPEnvelopeImpl extends SOAPElementImpl implements SOAPEnvelope { 31 32 36 private org.apache.axis2.soap.SOAPEnvelope omSOAPEnvelope; 37 38 41 public SOAPEnvelopeImpl(){ 42 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 44 omNode = omElement =omSOAPEnvelope = fac.getDefaultEnvelope(); 45 } 46 47 public SOAPEnvelopeImpl(org.apache.axis2.soap.SOAPEnvelope omEnvelope){ 48 super(omEnvelope); 49 this.omSOAPEnvelope = omEnvelope; 50 } 51 52 56 public org.apache.axis2.soap.SOAPEnvelope getOMEnvelope(){ 57 return omSOAPEnvelope; 58 } 59 60 61 70 public Name createName(String localName, String prefix, String uri) 71 throws SOAPException { 72 try { 73 return new PrefixedQName(uri,localName, prefix); 74 }catch (Exception e) 75 { 76 throw new SOAPException(e); 77 } 78 } 79 80 88 public Name createName(String localName) throws SOAPException { 89 try { 90 return new PrefixedQName(null, localName, null); 91 }catch (Exception e) 92 { 93 throw new SOAPException(e); 94 } 95 } 96 97 104 public SOAPHeader getHeader() throws SOAPException { 105 106 org.apache.axis2.soap.SOAPHeader omSOAPHeader; 107 try 108 { 109 omSOAPHeader = (org.apache.axis2.soap.SOAPHeader) omSOAPEnvelope.getHeader(); 110 }catch (Exception e) 111 { 112 throw new SOAPException(e); 113 } 114 if(omSOAPHeader != null) 115 return new SOAPHeaderImpl(omSOAPHeader); 116 else 117 return null; 118 } 119 120 127 public SOAPBody getBody() throws SOAPException { 128 129 org.apache.axis2.soap.SOAPBody omSOAPBody = null; 130 try 131 { 132 omSOAPBody = omSOAPEnvelope.getBody(); 133 } catch (Exception e) 134 { 135 } 137 if(omSOAPBody != null) 138 return (new SOAPBodyImpl(omSOAPBody)); 139 else 140 return null; 141 } 142 143 150 public SOAPHeader addHeader() throws SOAPException { 151 154 try { 155 org.apache.axis2.soap.SOAPHeader header = omSOAPEnvelope.getHeader(); 156 if (header == null) { 157 SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory(); 158 header = soapFactory.createSOAPHeader(omSOAPEnvelope); 159 omSOAPEnvelope.addChild(header); 160 return (new SOAPHeaderImpl(header)); 161 } else { 162 throw new SOAPException("Header already present, can't set body again without deleting the existing header"); 163 } 164 }catch (Exception e) 165 { 166 throw new SOAPException(e); 167 } 168 } 169 170 177 public SOAPBody addBody() throws SOAPException { 178 181 try { 182 org.apache.axis2.soap.SOAPBody body = omSOAPEnvelope.getBody(); 183 if (body == null) { 184 SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory(); 185 body = soapFactory.createSOAPBody(omSOAPEnvelope); 186 omSOAPEnvelope.addChild(body); 187 return (new SOAPBodyImpl(body)); 188 } else { 189 throw new SOAPException("Body already present, can't set body again without deleting the existing body"); 190 } 191 }catch (Exception e) 192 { 193 throw new SOAPException(e); 194 } 195 } 196 197 } 198 | Popular Tags |