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
020 package javax.xml.soap;
021
022 import org.w3c.dom.NodeList;
023
024 import javax.xml.transform.dom.DOMResult;
025
026 public class SAAJResult extends DOMResult {
027
028 public SAAJResult()
029 throws SOAPException {
030 this(MessageFactory.newInstance().createMessage());
031 org.w3c.dom.Node node = this.getNode();
032 NodeList nodeList = node.getChildNodes();
033 if (nodeList != null) {
034 int size = nodeList.getLength();
035 for (int a = 0; a < size; a++) {
036 node.removeChild(nodeList.item(a));
037 }
038 }
039 this.setNode(null);
040 }
041
042 public SAAJResult(String s)
043 throws SOAPException {
044 this(MessageFactory.newInstance(s).createMessage());
045 }
046
047 public SAAJResult(SOAPMessage soapmessage) {
048 super(soapmessage.getSOAPPart());
049 }
050
051 public SAAJResult(SOAPElement soapelement) {
052 super(soapelement);
053 }
054
055 public javax.xml.soap.Node getResult() {
056 org.w3c.dom.Node node = super.getNode();
057 //When using SAAJResult saajResult = new SAAJResult();
058 if (node == null) {
059 return null;
060 }
061 if (node instanceof SOAPPart) {
062 try {
063 return ((SOAPPart)node).getEnvelope();
064 } catch (SOAPException e) {
065 throw new RuntimeException(e);
066 }
067 }
068 return (javax.xml.soap.Node)node.getFirstChild();
069 }
070 }