1 55 package org.jboss.axis.message; 56 57 import org.jboss.axis.AxisFault; 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.Message; 60 import org.jboss.axis.MessageContext; 61 import org.jboss.axis.client.AxisClient; 62 import org.jboss.axis.configuration.NullProvider; 63 import org.jboss.axis.encoding.DeserializationContext; 64 import org.jboss.axis.encoding.DeserializationContextImpl; 65 import org.jboss.axis.encoding.SerializationContext; 66 import org.jboss.axis.schema.SchemaVersion; 67 import org.jboss.axis.soap.SOAPConstants; 68 import org.jboss.axis.utils.Mapping; 69 import org.jboss.axis.utils.Messages; 70 import org.jboss.logging.Logger; 71 import org.w3c.dom.DOMException ; 72 import org.w3c.dom.Node ; 73 import org.xml.sax.InputSource ; 74 import org.xml.sax.SAXException ; 75 76 import javax.xml.namespace.QName ; 77 import javax.xml.soap.SOAPException ; 78 import java.io.InputStream ; 79 import java.util.ArrayList ; 80 import java.util.Enumeration ; 81 import java.util.Iterator ; 82 import java.util.Vector ; 83 84 87 public class SOAPEnvelopeAxisImpl extends SOAPEnvelopeImpl 88 { 89 90 private static Logger log = Logger.getLogger(SOAPEnvelopeAxisImpl.class.getName()); 91 92 private SOAPHeaderAxisImpl header; 93 private SOAPBodyAxisImpl body; 94 95 public Vector trailers = new Vector (); 96 private SOAPConstants soapConstants; 97 private SchemaVersion schemaVersion = SchemaVersion.SCHEMA_2001; 98 99 public String messageType; 106 107 private boolean modified; 109 110 private boolean processingRPCInvocation; 114 115 public SOAPEnvelopeAxisImpl() 116 { 117 this(true, SOAPConstants.SOAP11_CONSTANTS); 118 } 119 120 public SOAPEnvelopeAxisImpl(SOAPConstants soapConstants) 121 { 122 this(true, soapConstants); 123 } 124 125 public SOAPEnvelopeAxisImpl(SOAPConstants soapConstants, 126 SchemaVersion schemaVersion) 127 { 128 this(true, soapConstants, schemaVersion); 129 } 130 131 public SOAPEnvelopeAxisImpl(boolean registerPrefixes, SOAPConstants soapConstants) 132 { 133 this(registerPrefixes, soapConstants, SchemaVersion.SCHEMA_2001); 134 } 135 136 public SOAPEnvelopeAxisImpl(boolean registerPrefixes, SOAPConstants soapConstants, SchemaVersion schemaVersion) 137 { 138 139 super(Constants.ELEM_ENVELOPE, Constants.NS_PREFIX_SOAP_ENV, 141 (soapConstants != null) ? soapConstants.getEnvelopeURI() : Constants.DEFAULT_SOAP_VERSION.getEnvelopeURI()); 142 143 if (soapConstants == null) 144 soapConstants = Constants.DEFAULT_SOAP_VERSION; 145 146 148 this.soapConstants = soapConstants; 149 this.schemaVersion = schemaVersion; 150 151 setHeader(new SOAPHeaderAxisImpl(this, soapConstants)); 152 setBody(new SOAPBodyAxisImpl(this, soapConstants)); 153 154 if (registerPrefixes) 155 { 156 if (namespaces == null) 157 namespaces = new ArrayList (); 158 159 namespaces.add(new Mapping(soapConstants.getEnvelopeURI(), 160 Constants.NS_PREFIX_SOAP_ENV)); 161 namespaces.add(new Mapping(schemaVersion.getXsdURI(), 162 Constants.NS_PREFIX_SCHEMA_XSD)); 163 namespaces.add(new Mapping(schemaVersion.getXsiURI(), 164 Constants.NS_PREFIX_SCHEMA_XSI)); 165 } 166 167 setDirty(true); 168 } 169 170 public static SOAPEnvelopeAxisImpl newSOAPEnvelope(InputStream input) throws SAXException 171 { 172 173 SOAPEnvelopeAxisImpl env = new SOAPEnvelopeAxisImpl(); 174 175 InputSource is = new InputSource (input); 176 177 AxisClient tmpEngine = new AxisClient(new NullProvider()); 179 MessageContext msgContext = new MessageContext(tmpEngine); 180 DeserializationContext dser = new DeserializationContextImpl(is, msgContext, Message.REQUEST, env); 181 dser.parse(); 182 183 return env; 184 } 185 186 191 public String getMessageType() 192 { 193 return messageType; 194 } 195 196 201 public void setMessageType(String messageType) 202 { 203 this.messageType = messageType; 204 } 205 206 212 public Vector getBodyElements() throws AxisFault 213 { 214 if (body != null) 215 { 216 return new Vector (body.getBodyElements()); 217 } 218 else 219 { 220 return new Vector (); 221 } 222 } 223 224 229 public Vector getTrailers() 230 { 231 return trailers; 232 } 233 234 240 public SOAPBodyElementAxisImpl getFirstBody() throws AxisFault 241 { 242 return (body != null ? body.getFirstBody() : null); 243 } 244 245 public boolean isModified() 246 { 247 return modified; 248 } 249 250 public void setModified(boolean modified) 251 { 252 this.modified = modified; 253 log.debug("setModifiedAfterSerialization: " + modified); 254 } 255 256 public boolean isProcessingRPCInvocation() 257 { 258 return processingRPCInvocation; 259 } 260 261 public void setProcessingRPCInvocation(boolean flag) 262 { 263 log.debug("setProcessingRPCInvocation: " + flag); 264 this.processingRPCInvocation = flag; 265 } 266 267 273 public Vector getHeaders() throws AxisFault 274 { 275 if (header != null) 276 { 277 return new Vector (header.getChildren()); 278 } 279 else 280 { 281 return new Vector (); 282 } 283 } 284 285 290 public void addHeader(SOAPHeaderElementAxisImpl hdr) 291 { 292 if (header == null) 293 { 294 header = new SOAPHeaderAxisImpl(this, soapConstants); 295 } 296 hdr.setEnvelope(this); 297 header.addHeader(hdr); 298 setDirty(true); 299 } 300 301 306 public void addBodyElement(SOAPBodyElementAxisImpl element) 307 { 308 element.setEnvelope(this); 309 body.addBodyElement(element); 310 setDirty(true); 311 } 312 313 316 public void removeHeaders() 317 { 318 header = null; 319 } 320 321 324 public void setHeader(SOAPHeaderAxisImpl header) 325 { 326 try 327 { 328 if (this.header != null) 329 removeChild(this.header); 330 331 header.setParentElement(this); 333 this.header = header; 334 } 335 catch (SOAPException ex) 336 { 337 log.fatal(Messages.getMessage("exception00"), ex); 339 } 340 } 341 342 347 public void removeHeader(SOAPHeaderElementAxisImpl hdr) 348 { 349 if (header != null) 350 { 351 header.removeHeader(hdr); 352 setDirty(true); 353 } 354 } 355 356 public Node removeChild(Node oldChild) throws DOMException 357 { 358 super.removeChild(oldChild); 359 360 if (oldChild instanceof SOAPHeaderAxisImpl) 361 removeHeaders(); 362 363 else if (oldChild instanceof SOAPBodyAxisImpl) 364 removeBody(); 365 366 return oldChild; 367 } 368 369 372 public void removeBody() 373 { 374 body = null; 375 } 376 377 382 public void setBody(SOAPBodyAxisImpl newBody) 383 { 384 385 if (body != null) 386 { 387 removeChild(body); 388 } 389 390 try 391 { 392 newBody.setParentElement(this); 393 body = newBody; 394 } 395 catch (SOAPException ex) 396 { 397 log.fatal(Messages.getMessage("exception00"), ex); 399 } 400 } 401 402 407 public void removeBodyElement(SOAPBodyElementAxisImpl element) 408 { 409 if (body != null) 410 { 411 body.removeBodyElement(element); 412 setDirty(true); 413 } 414 } 415 416 421 public void removeTrailer(SOAPElementAxisImpl element) 422 { 423 if (log.isDebugEnabled()) 424 log.debug(Messages.getMessage("removeTrailer00")); 425 trailers.removeElement(element); 426 setDirty(true); 427 } 428 429 432 public void clearBody() 433 { 434 if (body != null) 435 { 436 body.clearBody(); 437 setDirty(true); 438 } 439 } 440 441 446 public void addTrailer(SOAPElementAxisImpl element) 447 { 448 if (log.isDebugEnabled()) 449 log.debug(Messages.getMessage("removeTrailer00")); 450 element.setEnvelope(this); 451 trailers.addElement(element); 452 setDirty(true); 453 } 454 455 459 public SOAPHeaderElementAxisImpl getHeaderByName(String namespace, 460 String localPart) 461 throws AxisFault 462 { 463 return getHeaderByName(namespace, localPart, false); 464 } 465 466 470 public SOAPHeaderElementAxisImpl getHeaderByName(String namespace, 471 String localPart, 472 boolean accessAllHeaders) 473 throws AxisFault 474 { 475 if (header != null) 476 { 477 return header.getHeaderByName(namespace, 478 localPart, 479 accessAllHeaders); 480 } 481 else 482 { 483 return null; 484 } 485 } 486 487 495 public SOAPBodyElementAxisImpl getBodyByName(String namespace, String localPart) throws AxisFault 496 { 497 return (body != null ? body.getBodyByName(namespace, localPart) : null); 498 } 499 500 508 public Enumeration getHeadersByName(String namespace, String localPart) 509 throws AxisFault 510 { 511 return getHeadersByName(namespace, localPart, false); 512 } 513 514 524 public Enumeration getHeadersByName(String namespace, String localPart, 525 boolean accessAllHeaders) 526 throws AxisFault 527 { 528 if (header != null) 529 { 530 return header.getHeadersByName(namespace, 531 localPart, 532 accessAllHeaders); 533 } 534 else 535 { 536 return new Vector ().elements(); 537 } 538 } 539 540 543 public void outputImpl(SerializationContext context) throws Exception 544 { 545 546 boolean oldPretty = context.getPretty(); 547 context.setPretty(true); 548 549 if (namespaces != null) 551 { 552 for (Iterator i = namespaces.iterator(); i.hasNext();) 553 { 554 Mapping mapping = (Mapping)i.next(); 555 context.registerPrefixForURI(mapping.getPrefix(), 556 mapping.getNamespaceURI()); 557 } 558 } 559 560 Enumeration en; 561 562 context.startElement(new QName (soapConstants.getEnvelopeURI(), 564 Constants.ELEM_ENVELOPE), attributes); 565 566 for (Iterator it = getChildElements(); it.hasNext();) 568 { 569 Node childNode = (Node )it.next(); 570 if (childNode instanceof SOAPHeaderAxisImpl || childNode instanceof SOAPBodyAxisImpl) 571 continue; 572 573 if (childNode instanceof SOAPElementAxisImpl) 574 ((SOAPElementAxisImpl)childNode).output(context); 575 else if (childNode instanceof TextImpl) 576 context.writeString(childNode.getNodeValue()); 577 } 578 579 if (header != null) 581 { 582 header.outputImpl(context); 583 } 584 585 if (body != null) 587 { 588 body.outputImpl(context); 589 } 590 591 en = trailers.elements(); 593 while (en.hasMoreElements()) 594 { 595 SOAPElementAxisImpl element = (SOAPElementAxisImpl)en.nextElement(); 596 element.output(context); 597 } 599 600 context.endElement(); 602 603 context.setPretty(oldPretty); 604 605 setModified(false); 606 } 607 608 613 public SOAPConstants getSOAPConstants() 614 { 615 return soapConstants; 616 } 617 618 623 public void setSoapConstants(SOAPConstants soapConstants) 624 { 625 this.soapConstants = soapConstants; 626 } 627 628 633 public SchemaVersion getSchemaVersion() 634 { 635 return schemaVersion; 636 } 637 638 643 public void setSchemaVersion(SchemaVersion schemaVersion) 644 { 645 this.schemaVersion = schemaVersion; 646 } 647 648 654 public javax.xml.soap.SOAPBody addBody() throws SOAPException 655 { 656 if (body == null) 657 { 658 setBody(new SOAPBodyAxisImpl(this, soapConstants)); 659 return body; 660 } 661 else 662 { 663 throw new SOAPException (Messages.getMessage("bodyPresent")); 664 } 665 } 666 667 673 public javax.xml.soap.SOAPHeader addHeader() throws SOAPException 674 { 675 if (header == null) 676 { 677 header = new SOAPHeaderAxisImpl(this, soapConstants); 678 return header; 679 } 680 else 681 { 682 throw new SOAPException (Messages.getMessage("headerPresent")); 683 } 684 } 685 686 693 public javax.xml.soap.Name createName(String localName) 694 throws SOAPException 695 { 696 return new NameImpl(localName); 697 } 698 699 708 public javax.xml.soap.Name createName(String localName, 709 String prefix, 710 String uri) 711 throws SOAPException 712 { 713 return new NameImpl(localName, prefix, uri); 714 } 715 716 719 public javax.xml.soap.SOAPBody getBody() 720 { 721 return body; 722 } 723 724 729 public javax.xml.soap.SOAPHeader getHeader() 730 { 731 return header; 732 } 733 734 public void setSAAJEncodingCompliance(boolean comply) 735 { 736 this.body.setSAAJEncodingCompliance(comply); 737 } 738 } 739 | Popular Tags |