1 16 package org.apache.axis2.saaj; 17 18 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder; 19 import org.apache.axis2.transport.http.HTTPConstants; 20 import org.apache.axis2.util.SessionUtils; 21 import org.w3c.dom.*; 22 23 import javax.xml.soap.MimeHeaders ; 24 import javax.xml.soap.SOAPEnvelope ; 25 import javax.xml.soap.SOAPException ; 26 import javax.xml.soap.SOAPPart ; 27 import javax.xml.stream.XMLInputFactory; 28 import javax.xml.transform.Source ; 29 import java.io.InputStream ; 30 import java.io.InputStreamReader ; 31 import java.util.Iterator ; 32 33 39 public class SOAPPartImpl extends SOAPPart { 40 41 private SOAPMessageImpl msgObject; 42 private MimeHeaders mimeHeaders = new MimeHeaders(); 43 private Object envelope; 44 47 private String currentEncoding = "UTF-8"; 48 49 public SOAPPartImpl(SOAPMessageImpl parent, Object initialContents, boolean isBodyStream) throws SOAPException { 50 51 setMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SessionUtils.generateSessionId()); 52 setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE , "text/xml"); 53 StAXSOAPModelBuilder stAXSOAPModelBuilder; 54 55 msgObject = parent; 56 try{ 57 if(initialContents instanceof SOAPEnvelope ){ 58 ((SOAPEnvelopeImpl)initialContents).setOwnerDocument(this); 59 envelope = initialContents; 60 } else if(initialContents instanceof InputStream ){ 61 InputStreamReader inr = new InputStreamReader ((InputStream )initialContents); 63 stAXSOAPModelBuilder = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(inr)); 64 org.apache.axis2.soap.SOAPEnvelope omEnv = stAXSOAPModelBuilder.getSOAPEnvelope(); 65 envelope = new SOAPEnvelopeImpl(omEnv); 66 ((SOAPEnvelopeImpl)envelope).setOwnerDocument(this); 67 } 68 69 }catch(Exception e){ 70 throw new SOAPException (e); 71 } 72 } 73 74 public SOAPMessageImpl getMessage(){ 75 return msgObject; 76 } 77 78 84 public void setMessage (SOAPMessageImpl msg) { 85 this.msgObject= msg; 86 } 87 88 91 public SOAPEnvelope getEnvelope() throws SOAPException { 92 return (SOAPEnvelope )envelope; 94 95 } 96 97 102 public void removeMimeHeader(String header) { 103 mimeHeaders.removeHeader(header); 104 } 105 106 110 public void removeAllMimeHeaders() { 111 mimeHeaders.removeAllHeaders(); 112 } 113 114 124 public String [] getMimeHeader(String name) { 125 return mimeHeaders.getHeader(name); 126 } 127 128 152 public void setMimeHeader(String name, String value) { 153 mimeHeaders.setHeader(name,value); 154 } 155 156 162 public void addMimeHeader (String header, String value) { 163 mimeHeaders.addHeader(header, value); 164 } 165 166 173 public Iterator getAllMimeHeaders() { 174 return mimeHeaders.getAllHeaders(); 175 } 176 177 183 public java.util.Iterator getMatchingMimeHeaders( final String [] match){ 184 return mimeHeaders.getMatchingHeaders(match); 185 } 186 187 194 public java.util.Iterator getNonMatchingMimeHeaders( final String [] match){ 195 return mimeHeaders.getNonMatchingHeaders(match); 196 } 197 198 201 public void setContent(Source source) throws SOAPException { 202 204 } 205 206 209 public Source getContent() throws SOAPException { 210 return null; 212 } 213 214 224 225 private Document document = new SOAPDocumentImpl(this); 226 229 public Document getSOAPDocument(){ 230 if(document == null){ 231 document = new SOAPDocumentImpl(this); 232 } 233 return document; 234 } 235 236 239 public DocumentType getDoctype(){ 240 return document.getDoctype(); 241 } 242 243 246 public DOMImplementation getImplementation(){ 247 return document.getImplementation(); 248 } 249 250 253 protected Document mDocument; 254 255 public Element getDocumentElement() 256 { 257 try{ 258 return getEnvelope(); 259 }catch(SOAPException se){ 260 return null; 261 } 262 } 263 264 270 public Element createElement(String tagName) throws DOMException { 271 return document.createElement(tagName); 272 } 273 274 public DocumentFragment createDocumentFragment() { 275 return document.createDocumentFragment(); 276 } 277 278 public Text createTextNode(String data) { 279 return document.createTextNode(data); 280 } 281 282 public Comment createComment(String data){ 283 return document.createComment(data); 284 } 285 286 public CDATASection createCDATASection(String data) throws DOMException { 287 return document.createCDATASection(data); 288 } 289 290 public ProcessingInstruction createProcessingInstruction(String target, String data) 291 throws DOMException { 292 return document.createProcessingInstruction(target,data); 293 } 294 295 public Attr createAttribute(String name)throws DOMException { 296 return document.createAttribute(name); 297 } 298 299 public EntityReference createEntityReference(String name) throws DOMException { 300 return document.createEntityReference(name); 301 } 302 303 public NodeList getElementsByTagName(String tagname) { 304 return document.getElementsByTagName(tagname); 305 } 306 307 public Node importNode(Node importedNode, boolean deep) 308 throws DOMException { 309 return document.importNode(importedNode, deep); 310 } 311 312 public Element createElementNS(String namespaceURI, String qualifiedName) 313 throws DOMException { 314 return document.createElementNS(namespaceURI, qualifiedName); 315 } 316 317 public Attr createAttributeNS(String namespaceURI, String qualifiedName) 318 throws DOMException { 319 return document.createAttributeNS(namespaceURI, qualifiedName); 320 } 321 322 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 323 return document.getElementsByTagNameNS(namespaceURI,localName); 324 } 325 326 public Element getElementById(String elementId){ 327 return document.getElementById(elementId); 328 } 329 330 332 public String getEncoding() 333 { 334 return currentEncoding; 335 } 336 337 public void setEncoding(String s) 338 { 339 currentEncoding = s; 340 } 341 342 public boolean getStandalone() 343 { 344 throw new UnsupportedOperationException ("Not yet implemented.71"); 345 } 346 347 348 public void setStandalone(boolean flag) 349 { 350 throw new UnsupportedOperationException ("Not yet implemented.72"); 351 } 352 353 public boolean getStrictErrorChecking() 354 { 355 throw new UnsupportedOperationException ("Not yet implemented.73"); 356 } 357 358 359 public void setStrictErrorChecking(boolean flag) 360 { 361 throw new UnsupportedOperationException ("Not yet implemented. 74"); 362 } 363 364 365 public String getVersion() 366 { 367 throw new UnsupportedOperationException ("Not yet implemented. 75"); 368 } 369 370 371 public void setVersion(String s) 372 { 373 throw new UnsupportedOperationException ("Not yet implemented.76"); 374 } 375 376 377 public Node adoptNode(Node node) 378 throws DOMException 379 { 380 throw new UnsupportedOperationException ("Not yet implemented.77"); 381 } 382 383 386 387 public String getNodeName(){ 388 return document.getNodeName(); 389 } 390 391 public String getNodeValue() throws DOMException { 392 return document.getNodeValue(); 393 } 394 395 public void setNodeValue(String nodeValue) throws DOMException{ 396 document.setNodeValue(nodeValue); 397 } 398 399 public short getNodeType() { 400 return document.getNodeType(); 401 } 402 403 public Node getParentNode(){ 404 return document.getParentNode(); 405 } 406 407 public NodeList getChildNodes() { 408 return document.getChildNodes(); 409 } 410 411 public Node getFirstChild() { 412 return document.getFirstChild(); 413 } 414 415 public Node getLastChild(){ 416 return document.getLastChild(); 417 } 418 419 public Node getPreviousSibling(){ 420 return document.getPreviousSibling(); 421 } 422 423 public Node getNextSibling(){ 424 return document.getNextSibling(); 425 } 426 427 public NamedNodeMap getAttributes(){ 428 return document.getAttributes(); 429 } 430 431 public Document getOwnerDocument(){ 432 return document.getOwnerDocument(); 433 } 434 435 public Node insertBefore(Node newChild, Node refChild) throws DOMException { 436 return document.insertBefore(newChild, refChild); 437 } 438 439 public Node replaceChild(Node newChild, Node oldChild) throws DOMException { 440 return document.replaceChild(newChild, oldChild); 441 } 442 443 public Node removeChild(Node oldChild) throws DOMException { 444 return document.removeChild(oldChild); 445 } 446 447 public Node appendChild(Node newChild) throws DOMException { 448 return document.appendChild(newChild); 449 } 450 451 public boolean hasChildNodes(){ 452 return document.hasChildNodes(); 453 } 454 public Node cloneNode(boolean deep) { 455 return document.cloneNode(deep); 456 } 457 458 public void normalize(){ 459 document.normalize(); 460 } 461 462 public boolean isSupported(String feature, String version){ 463 return document.isSupported(feature, version); 464 } 465 466 public String getNamespaceURI() { 467 return document.getNamespaceURI(); 468 } 469 470 public String getPrefix() { 471 return document.getPrefix(); 472 } 473 474 public void setPrefix(String prefix) throws DOMException { 475 document.setPrefix(prefix); 476 } 477 public String getLocalName() { 478 return document.getLocalName(); 479 } 480 481 public boolean hasAttributes(){ 482 return document.hasAttributes(); 483 } 484 485 } 486 | Popular Tags |