001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.saaj;
020:
021: import org.apache.axiom.om.OMNamespace;
022: import org.apache.axiom.om.OMNode;
023: import org.apache.axiom.om.impl.dom.DocumentImpl;
024: import org.apache.axiom.om.impl.dom.ElementImpl;
025: import org.apache.axiom.om.impl.dom.NamespaceImpl;
026: import org.apache.axiom.om.impl.dom.NodeImpl;
027: import org.apache.axiom.soap.SOAPFactory;
028: import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
029: import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultImpl;
030: import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
031: import org.apache.axiom.soap.impl.dom.soap12.SOAP12FaultImpl;
032: import org.w3c.dom.Document;
033: import org.w3c.dom.Element;
034: import org.w3c.dom.NamedNodeMap;
035: import org.w3c.dom.NodeList;
036: import org.w3c.dom.Text;
037:
038: import javax.xml.namespace.QName;
039: import javax.xml.parsers.DocumentBuilder;
040: import javax.xml.parsers.DocumentBuilderFactory;
041: import javax.xml.parsers.ParserConfigurationException;
042: import javax.xml.soap.Name;
043: import javax.xml.soap.Node;
044: import javax.xml.soap.SOAPBody;
045: import javax.xml.soap.SOAPBodyElement;
046: import javax.xml.soap.SOAPElement;
047: import javax.xml.soap.SOAPException;
048: import javax.xml.soap.SOAPFault;
049: import java.util.ArrayList;
050: import java.util.Collection;
051: import java.util.Iterator;
052: import java.util.Locale;
053:
054: public class SOAPBodyImpl extends SOAPElementImpl implements SOAPBody {
055:
056: private org.apache.axiom.soap.SOAPBody omSOAPBody;
057: private boolean isBodyElementAdded;
058:
059: /** @param omSOAPBody */
060: public SOAPBodyImpl(org.apache.axiom.soap.SOAPBody omSOAPBody) {
061: super ((ElementImpl) omSOAPBody);
062: this .omSOAPBody = omSOAPBody;
063: }
064:
065: /* (non-Javadoc)
066: * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String)
067: */
068: public SOAPElement addChildElement(String localName)
069: throws SOAPException {
070: if (omSOAPBody.hasFault()) {
071: throw new SOAPException(
072: "A SOAPFault has been already added to this SOAPBody");
073: }
074: SOAPBodyElementImpl childEle = new SOAPBodyElementImpl(
075: (ElementImpl) getOwnerDocument().createElement(
076: localName));
077: childEle.element.setUserData(SAAJ_NODE, childEle, null);
078: element.appendChild(childEle.element);
079: ((NodeImpl) childEle.element.getParentNode()).setUserData(
080: SAAJ_NODE, this , null);
081: isBodyElementAdded = true;
082: return childEle;
083: }
084:
085: public SOAPElement addChildElement(String localName, String prefix)
086: throws SOAPException {
087: String namespaceURI = getNamespaceURI(prefix);
088:
089: if (namespaceURI == null) {
090: throw new SOAPException(
091: "Namespace not declared for the give prefix: "
092: + prefix);
093: }
094: SOAPBodyElementImpl childEle = new SOAPBodyElementImpl(
095: (ElementImpl) getOwnerDocument().createElementNS(
096: namespaceURI, localName));
097: childEle.element.setUserData(SAAJ_NODE, childEle, null);
098: childEle.element.setNamespace(childEle.element
099: .declareNamespace(namespaceURI, prefix));
100: element.appendChild(childEle.element);
101: ((NodeImpl) childEle.element.getParentNode()).setUserData(
102: SAAJ_NODE, this , null);
103: childEle.setParentElement(this );
104: return childEle;
105: }
106:
107: public SOAPElement addChildElement(SOAPElement soapElement)
108: throws SOAPException {
109: String namespaceURI = soapElement.getNamespaceURI();
110: String prefix = soapElement.getPrefix();
111: String localName = soapElement.getLocalName();
112: element.declareNamespace(namespaceURI, prefix);
113: SOAPBodyElementImpl childEle;
114:
115: if (localName == null) {
116: childEle = new SOAPBodyElementImpl(
117: (ElementImpl) getOwnerDocument().createElementNS(
118: namespaceURI, ""));
119: } else {
120: childEle = new SOAPBodyElementImpl(
121: (ElementImpl) getOwnerDocument().createElementNS(
122: namespaceURI, localName));
123: }
124: for (Iterator iter = soapElement.getAllAttributes(); iter
125: .hasNext();) {
126: Name name = (Name) iter.next();
127: childEle.addAttribute(name, soapElement
128: .getAttributeValue(name));
129: }
130:
131: for (Iterator iter = soapElement.getChildElements(); iter
132: .hasNext();) {
133: Object o = iter.next();
134: if (o instanceof Text) {
135: childEle.addTextNode(((Text) o).getData());
136: } else {
137: childEle.addChildElement((SOAPElement) o);
138: }
139: }
140:
141: childEle.element.setUserData(SAAJ_NODE, childEle, null);
142: childEle.element.setNamespace(childEle.element
143: .declareNamespace(namespaceURI, prefix));
144: element.appendChild(childEle.element);
145: ((NodeImpl) childEle.element.getParentNode()).setUserData(
146: SAAJ_NODE, this , null);
147: childEle.setParentElement(this );
148: return childEle;
149: }
150:
151: /* (non-Javadoc)
152: * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String, java.lang.String, java.lang.String)
153: */
154: public SOAPElement addChildElement(String localName, String prefix,
155: String uri) throws SOAPException {
156: if (omSOAPBody.hasFault()) {
157: throw new SOAPException(
158: "A SOAPFault has been already added to this SOAPBody");
159: }
160: SOAPBodyElementImpl childEle;
161: if (uri == null || "".equals(uri)) {
162: childEle = new SOAPBodyElementImpl(
163: (ElementImpl) getOwnerDocument().createElement(
164: localName));
165: } else if (prefix == null || "".equals(prefix)) {
166: childEle = new SOAPBodyElementImpl(
167: (ElementImpl) getOwnerDocument().createElementNS(
168: uri, localName));
169: } else {
170: childEle = new SOAPBodyElementImpl(
171: (ElementImpl) getOwnerDocument().createElementNS(
172: uri, prefix + ":" + localName));
173: }
174: childEle.element.setUserData(SAAJ_NODE, childEle, null);
175: childEle.element.setNamespace(childEle.element
176: .declareNamespace(uri, prefix));
177: element.appendChild(childEle.element);
178: ((NodeImpl) childEle.element.getParentNode()).setUserData(
179: SAAJ_NODE, this , null);
180: isBodyElementAdded = true;
181: childEle.setParentElement(this );
182: return childEle;
183: }
184:
185: /**
186: * Creates a new <code>SOAPFault</code> object and adds it to this <code>SOAPBody</code>
187: * object.
188: *
189: * @return the new <code>SOAPFault</code> object
190: * @throws SOAPException if there is a SOAP error
191: */
192: public SOAPFault addFault() throws SOAPException {
193: if (isBodyElementAdded) {
194: throw new SOAPException(
195: "A SOAPBodyElement has been already added to this SOAPBody");
196: }
197: SOAPFaultImpl saajSOAPFault = null;
198:
199: if (this .element.getOMFactory() instanceof SOAP11Factory) {
200: SOAP11FaultImpl fault = new SOAP11FaultImpl(omSOAPBody,
201: (SOAPFactory) this .element.getOMFactory());
202: saajSOAPFault = new SOAPFaultImpl(fault);
203: } else if (this .element.getOMFactory() instanceof SOAP12Factory) {
204: SOAP12FaultImpl fault = new SOAP12FaultImpl(omSOAPBody,
205: (SOAPFactory) this .element.getOMFactory());
206: saajSOAPFault = new SOAPFaultImpl(fault);
207: }
208: // set default fault code and string
209: saajSOAPFault.setDefaults();
210:
211: ((NodeImpl) omSOAPBody.getFault()).setUserData(SAAJ_NODE,
212: saajSOAPFault, null);
213: return saajSOAPFault;
214: }
215:
216: /**
217: * Indicates whether a <code>SOAPFault</code> object exists in this <code>SOAPBody</code>
218: * object.
219: *
220: * @return <code>true</code> if a <code>SOAPFault</code> object exists in this
221: * <code>SOAPBody</code> object; <code>false</code> otherwise
222: */
223: public boolean hasFault() {
224: return omSOAPBody.hasFault();
225: }
226:
227: /**
228: * Returns the <code>SOAPFault</code> object in this <code>SOAPBody</code> object.
229: *
230: * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code> object
231: */
232: public SOAPFault getFault() {
233: if (omSOAPBody.hasFault()) {
234: return (SOAPFault) toSAAJNode((org.w3c.dom.Node) omSOAPBody
235: .getFault());
236: }
237: return null;
238: }
239:
240: /**
241: * Creates a new <code>SOAPBodyElement</code> object with the specified name and adds it to this
242: * <code>SOAPBody</code> object.
243: *
244: * @param name a <code>Name</code> object with the name for the new <code>SOAPBodyElement</code>
245: * object
246: * @return the new <code>SOAPBodyElement</code> object
247: * @throws SOAPException if a SOAP error occurs
248: */
249: public SOAPBodyElement addBodyElement(Name name)
250: throws SOAPException {
251: return (SOAPBodyElement) addChildElement(name);
252: }
253:
254: /**
255: * Creates a new <code>SOAPFault</code> object and adds it to this <code>SOAPBody</code> object.
256: * The new <code>SOAPFault</code> will have a <code>faultcode</code> element that is set to the
257: * <code>faultCode</code> parameter and a <code>faultstring</code> set to
258: * <code>faultstring</code> and localized to <code>locale</code>.
259: *
260: * @param faultCode a <code>Name</code> object giving the fault code to be set; must be one of
261: * the fault codes defined in the SOAP 1.1 specification and of type QName
262: * @param faultString a <code>String</code> giving an explanation of the fault
263: * @param locale a <code>Locale</code> object indicating the native language of the
264: * <ocde>faultString</code>
265: * @return the new <code>SOAPFault</code> object
266: * @throws SOAPException if there is a SOAP error
267: */
268: public SOAPFault addFault(Name faultCode, String faultString,
269: Locale locale) throws SOAPException {
270: org.apache.axiom.soap.SOAPFault fault;
271: if (this .element.getOMFactory() instanceof SOAP11Factory) {
272: fault = new SOAP11FaultImpl(omSOAPBody, new Exception(
273: faultString), (SOAPFactory) this .element
274: .getOMFactory());
275: } else {
276: fault = new SOAP12FaultImpl(omSOAPBody, new Exception(
277: faultString), (SOAPFactory) this .element
278: .getOMFactory());
279: }
280: SOAPFaultImpl faultImpl = new SOAPFaultImpl(fault);
281: faultImpl.setFaultCode(faultCode);
282:
283: if (locale != null) {
284: faultImpl.setFaultString(faultString, locale);
285: } else {
286: faultImpl.setFaultString(faultString);
287: }
288:
289: return faultImpl;
290: }
291:
292: /**
293: * Creates a new <code>SOAPFault</code> object and adds it to this <code>SOAPBody</code> object.
294: * The new <code>SOAPFault</code> will have a <code>faultcode</code> element that is set to the
295: * <code>faultCode</code> parameter and a <code>faultstring</code> set to
296: * <code>faultstring</code>.
297: *
298: * @param faultCode a <code>Name</code> object giving the fault code to be set; must be one of
299: * the fault codes defined in the SOAP 1.1 specification and of type QName
300: * @param faultString a <code>String</code> giving an explanation of the fault
301: * @return the new <code>SOAPFault</code> object
302: * @throws SOAPException if there is a SOAP error
303: */
304: public SOAPFault addFault(Name faultCode, String faultString)
305: throws SOAPException {
306: return addFault(faultCode, faultString, null);
307: }
308:
309: /**
310: * Adds the root node of the DOM <code>Document</code> to this <code>SOAPBody</code> object.
311: * <p/>
312: * Calling this method invalidates the <code>document</code> parameter. The client application
313: * should discard all references to this <code>Document</code> and its contents upon calling
314: * <code>addDocument</code>. The behavior of an application that continues to use such
315: * references is undefined.
316: *
317: * @param document the <code>Document</code> object whose root node will be added to this
318: * <code>SOAPBody</code>
319: * @return the <code>SOAPBodyElement</code> that represents the root node that was added
320: * @throws SOAPException if the <code>Document</code> cannot be added
321: */
322: public SOAPBodyElement addDocument(Document document)
323: throws SOAPException {
324: Element docEle = document.getDocumentElement();
325:
326: SOAPElement saajSOAPEle = (SOAPElement) toSAAJNode(docEle, this );
327: SOAPBodyElementImpl bodyEle = new SOAPBodyElementImpl(
328: ((SOAPElementImpl) saajSOAPEle).element);
329: addChildElement(bodyEle);
330: return bodyEle;
331: }
332:
333: /**
334: * Creates a new <code>SOAPBodyElement</code> object with the specified name and adds it to this
335: * <code>SOAPBody</code> object.
336: *
337: * @param qname a <code>QName</code> object with the name for the new <code>SOAPBodyElement</code>
338: * object
339: * @return the new <code>SOAPBodyElement</code> object
340: * @throws SOAPException if a SOAP error occurs
341: */
342: public SOAPBodyElement addBodyElement(QName qname)
343: throws SOAPException {
344: return (SOAPBodyElement) addChildElement(qname);
345: }
346:
347: public SOAPFault addFault(QName faultcode, String faultString)
348: throws SOAPException {
349: return addFault(faultcode, faultString, null);
350: }
351:
352: /**
353: * Creates a new <code>SOAPFault</code> object and adds it to this <code>SOAPBody</code> object.
354: * The new <code>SOAPFault</code> will have a <code>faultcode</code> element that is set to the
355: * <code>faultCode</code> parameter and a <code>faultstring</code> set to
356: * <code>faultstring</code> and localized to <code>locale</code>.
357: *
358: * @param faultCode a <code>QName</code> object giving the fault code to be
359: * @param faultString a <code>String</code> giving an explanation of the fault
360: * @param locale a <code>Locale</code> object indicating the native language of the
361: * <ocde>faultString</code>
362: * @return the new <code>SOAPFault</code> object
363: * @throws SOAPException if there is a SOAP error
364: */
365: public SOAPFault addFault(QName faultCode, String faultString,
366: Locale locale) throws SOAPException {
367: SOAPFaultImpl faultImpl = null;
368:
369: if (this .element.getOMFactory() instanceof SOAP11Factory) {
370: SOAP11FaultImpl fault = new SOAP11FaultImpl(omSOAPBody,
371: new Exception(faultString),
372: (SOAPFactory) this .element.getOMFactory());
373: faultImpl = new SOAPFaultImpl(fault);
374: } else if (this .element.getOMFactory() instanceof SOAP12Factory) {
375: SOAP12FaultImpl fault = new SOAP12FaultImpl(omSOAPBody,
376: new Exception(faultString),
377: (SOAPFactory) this .element.getOMFactory());
378: faultImpl = new SOAPFaultImpl(fault);
379: }
380:
381: if (faultImpl != null) {
382: faultImpl.setFaultCode(faultCode);
383: if (locale != null) {
384: faultImpl.setFaultString(faultString, locale);
385: } else {
386: faultImpl.setFaultString(faultString);
387: }
388: }
389: return faultImpl;
390: }
391:
392: /**
393: * Creates a new DOM org.w3c.dom.Document and sets the first child of this SOAPBody as its
394: * document element. The child SOAPElement is removed as part of the process.
395: *
396: * @return The org.w3c.dom.Document representation of the SOAPBody content.
397: * @throws SOAPException - if there is not exactly one child SOAPElement of the SOAPBody.
398: */
399: public Document extractContentAsDocument() throws SOAPException {
400: Iterator childElements = this .getChildElements();
401: org.w3c.dom.Node domNode = null;
402: int childCount = 0;
403: while (childElements.hasNext()) {
404: domNode = (org.w3c.dom.Node) childElements.next();
405: childCount++;
406: if (childCount > 1) {
407: throw new SOAPException(
408: "SOAPBody contains more than one child element");
409: }
410: }
411: //The child SOAPElement is removed as part of the process
412: this .removeContents();
413:
414: Document document;
415: DocumentBuilderFactory factory = DocumentBuilderFactory
416: .newInstance();
417: factory.setNamespaceAware(true);
418:
419: try {
420: DocumentBuilder builder = factory.newDocumentBuilder();
421: document = builder.newDocument();
422: Element element = document.createElementNS(domNode
423: .getNamespaceURI(), domNode.getLocalName());
424: element.setNodeValue(domNode.getNodeValue());
425: document.appendChild(element);
426: } catch (ParserConfigurationException e) {
427: throw new SOAPException(e);
428: }
429: return document;
430: }
431:
432: private javax.xml.soap.Node toSAAJNode(org.w3c.dom.Node node,
433: SOAPElement parent) throws SOAPException {
434: if (node == null) {
435: return null;
436: }
437: if (node instanceof org.w3c.dom.Text) {
438: org.w3c.dom.Text domText = (org.w3c.dom.Text) node;
439: return new TextImplEx(domText.getData(), parent);
440: }
441: if (node instanceof org.w3c.dom.Comment) {
442: org.w3c.dom.Comment domText = (org.w3c.dom.Comment) node;
443: return new TextImplEx("<!--" + domText.getData() + "-->",
444: parent);
445: }
446: Element domEle = ((Element) node);
447: int indexOfColon = domEle.getTagName().indexOf(":");
448: NamespaceImpl ns;
449: String localName;
450: if (indexOfColon != -1) {
451: localName = domEle.getTagName().substring(indexOfColon + 1);
452: ns = new NamespaceImpl(domEle.getNamespaceURI(), domEle
453: .getTagName().substring(0, indexOfColon));
454: } else {
455: localName = domEle.getLocalName();
456: if (localName == null) { //it is possible that localname isn't set but name is set
457: localName = domEle.getTagName();
458: }
459: if (domEle.getNamespaceURI() != null) {
460: ns = new NamespaceImpl(domEle.getNamespaceURI(), domEle
461: .getPrefix());
462: } else {
463: if (domEle.getPrefix() != null) {
464: ns = new NamespaceImpl("", domEle.getPrefix());
465: } else {
466: ns = new NamespaceImpl("", "");
467:
468: }
469: }
470: }
471: ElementImpl eleImpl = new ElementImpl((DocumentImpl) this
472: .getOwnerDocument(), localName, ns, this .element
473: .getOMFactory());
474:
475: SOAPElementImpl saajEle = new SOAPElementImpl(eleImpl);
476:
477: saajEle.setParentElement(parent);
478: NamedNodeMap domAttrs = domEle.getAttributes();
479: for (int i = 0; i < domAttrs.getLength(); i++) {
480: org.w3c.dom.Node attrNode = domAttrs.item(i);
481: String attrLocalName = attrNode.getLocalName();
482: if (attrLocalName == null) {
483: attrLocalName = attrNode.getNodeName();
484: }
485: if (attrLocalName == null) {
486: //local part is required. "" is allowed to preserve compatibility with QName 1.0
487: attrLocalName = "";
488: }
489: saajEle.addAttribute(new PrefixedQName(attrNode
490: .getNamespaceURI(), attrLocalName, attrNode
491: .getPrefix()), attrNode.getNodeValue());
492: }
493:
494: NodeList childNodes = node.getChildNodes();
495: for (int i = 0; i < childNodes.getLength(); i++) {
496: Node childSAAJNode = toSAAJNode(childNodes.item(i), saajEle);
497: if (childSAAJNode instanceof javax.xml.soap.Text) {
498: saajEle.addTextNode(childSAAJNode.getValue());
499: } else {
500: saajEle
501: .addChildElement((javax.xml.soap.SOAPElement) childSAAJNode);
502: }
503: }
504: return saajEle;
505: }
506:
507: public void detachNode() {
508: this .detach();
509: }
510:
511: public OMNode detach() {
512: this .parentElement = null;
513: return this .element.detach();
514: }
515:
516: public Iterator getChildElements(Name name) {
517: QName qName = new QName(name.getURI(), name.getLocalName());
518: return getChildren(element.getChildrenWithName(qName));
519: }
520:
521: public SOAPElement addAttribute(QName qname, String value)
522: throws SOAPException {
523: OMNamespace omNamespace = null;
524: SOAPFactory soapFactory;
525: if (this .element.getOMFactory() instanceof SOAP11Factory) {
526: soapFactory = new SOAP11Factory();
527: omNamespace = soapFactory.createOMNamespace(qname
528: .getNamespaceURI(), qname.getPrefix());
529: } else if (this .element.getOMFactory() instanceof SOAP12Factory) {
530: soapFactory = new SOAP12Factory();
531: omNamespace = soapFactory.createOMNamespace(qname
532: .getNamespaceURI(), qname.getPrefix());
533: }
534: this .element.addAttribute(qname.getLocalPart(), value,
535: omNamespace);
536: return this ;
537: }
538:
539: public SOAPElement addChildElement(QName qname)
540: throws SOAPException {
541: if (omSOAPBody.hasFault()) {
542: throw new SOAPException(
543: "A SOAPFault has been already added to this SOAPBody");
544: }
545: SOAPBodyElementImpl childEle;
546: if (qname.getNamespaceURI() == null
547: || "".equals(qname.getNamespaceURI())) {
548: childEle = new SOAPBodyElementImpl(
549: (ElementImpl) getOwnerDocument().createElement(
550: qname.getLocalPart()));
551: } else if (null == qname.getPrefix()
552: || "".equals(qname.getPrefix().trim())) {
553: childEle = new SOAPBodyElementImpl(
554: (ElementImpl) getOwnerDocument().createElementNS(
555: qname.getNamespaceURI(),
556: qname.getLocalPart()));
557: } else {
558: childEle = new SOAPBodyElementImpl(
559: (ElementImpl) getOwnerDocument().createElementNS(
560: qname.getNamespaceURI(),
561: qname.getPrefix() + ":"
562: + qname.getLocalPart()));
563: }
564: childEle.element.setUserData(SAAJ_NODE, childEle, null);
565: childEle.element.setNamespace(childEle.element
566: .declareNamespace(qname.getNamespaceURI(), qname
567: .getPrefix()));
568:
569: element.appendChild(childEle.element);
570: ((NodeImpl) childEle.element.getParentNode()).setUserData(
571: SAAJ_NODE, this , null);
572: isBodyElementAdded = true;
573: childEle.setParentElement(this );
574: return childEle;
575: }
576:
577: public QName createQName(String localName, String prefix)
578: throws SOAPException {
579: if (this .element.getOMFactory() instanceof SOAP11Factory) {
580: return super .createQName(localName, prefix);
581: } else if (this .element.getOMFactory() instanceof SOAP12Factory) {
582: if (this .element.findNamespaceURI(prefix) == null) {
583: throw new SOAPException(
584: "Only Namespace Qualified elements are allowed");
585: } else {
586: return super .createQName(localName, prefix);
587: }
588: } else {
589: throw new UnsupportedOperationException();
590: }
591: }
592:
593: public Iterator getAllAttributesAsQNames() {
594: return super .getAllAttributesAsQNames();
595: }
596:
597: public String getAttributeValue(QName qname) {
598: return super .getAttributeValue(qname);
599: }
600:
601: public Iterator getChildElements(QName qname) {
602: return super .getChildElements(qname);
603: }
604:
605: public QName getElementQName() {
606: return super .getElementQName();
607: }
608:
609: public boolean removeAttribute(QName qname) {
610: return super .removeAttribute(qname);
611: }
612:
613: public SOAPElement setElementQName(QName qname)
614: throws SOAPException {
615: return super .setElementQName(qname);
616: }
617:
618: public Iterator getChildElements() {
619: return getChildren(element.getChildren());
620: }
621:
622: public SOAPElement addTextNode(String text) throws SOAPException {
623: return super .addTextNode(text);
624: }
625:
626: private Iterator getChildren(Iterator childIter) {
627: Collection childElements = new ArrayList();
628: while (childIter.hasNext()) {
629: org.w3c.dom.Node domNode = (org.w3c.dom.Node) childIter
630: .next();
631: Node saajNode = toSAAJNode(domNode);
632: if (saajNode instanceof javax.xml.soap.Text) {
633: childElements.add(saajNode);
634: } else if (!(saajNode instanceof SOAPBodyElement)) {
635: // silently replace node, as per saaj 1.2 spec
636: if (domNode instanceof ElementImpl) {
637: if (omSOAPBody.hasFault()) {
638:
639: SOAPFactory omFactory = (SOAPFactory) this .element
640: .getOMFactory();
641: org.apache.axiom.soap.SOAPFault fault;
642: if (omFactory instanceof SOAP11Factory) {
643: fault = new SOAP11FaultImpl(omSOAPBody,
644: omFactory);
645: } else {
646: fault = new SOAP12FaultImpl(omSOAPBody,
647: omFactory);
648: }
649: SOAPFaultImpl saajSOAPFault = new SOAPFaultImpl(
650: fault);
651: ((NodeImpl) omSOAPBody.getFault()).setUserData(
652: SAAJ_NODE, saajSOAPFault, null);
653: childElements.add(saajSOAPFault);
654: } else {
655: SOAPBodyElement saajBodyEle = new SOAPBodyElementImpl(
656: (ElementImpl) domNode);
657: ((NodeImpl) domNode).setUserData(SAAJ_NODE,
658: saajBodyEle, null);
659: childElements.add(saajBodyEle);
660: }
661: }
662: } else {
663: childElements.add(saajNode);
664: }
665: }
666: return childElements.iterator();
667: }
668: }
|