KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > soap > impl > llom > SOAPEnvelopeImpl


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis2.soap.impl.llom;
17
18 import org.apache.axis2.om.*;
19 import org.apache.axis2.soap.SOAPBody;
20 import org.apache.axis2.soap.SOAPEnvelope;
21 import org.apache.axis2.soap.SOAPHeader;
22
23 import javax.xml.namespace.QName JavaDoc;
24
25 /**
26  * Class SOAPEnvelopeImpl
27  */

28 public class SOAPEnvelopeImpl extends SOAPElement
29         implements SOAPEnvelope, OMConstants {
30
31     /**
32      * @param builder
33      */

34     public SOAPEnvelopeImpl(OMXMLParserWrapper builder) {
35         super(null, SOAPConstants.SOAPENVELOPE_LOCAL_NAME, builder);
36     }
37
38     /**
39      * @param ns
40      */

41     public SOAPEnvelopeImpl(OMNamespace ns) {
42         super(SOAPConstants.SOAPENVELOPE_LOCAL_NAME, ns);
43     }
44
45     /**
46      * Returns the <CODE>SOAPHeader</CODE> object for this <CODE>
47      * SOAPEnvelope</CODE> object. <P> This SOAPHeader will just be a container
48      * for all the headers in the <CODE>OMMessage</CODE> </P>
49      *
50      * @return the <CODE>SOAPHeader</CODE> object or <CODE> null</CODE> if there
51      * is none
52      * @throws org.apache.axis2.om.OMException if there is a problem obtaining
53      * the <CODE>SOAPHeader</CODE>
54      * object
55      * @throws OMException
56      */

57     public SOAPHeader getHeader() throws OMException {
58         return (SOAPHeader) getFirstChildWithName(new QName JavaDoc(SOAPConstants.HEADER_LOCAL_NAME));
59     }
60
61     /**
62      * Returns the <CODE>SOAPBody</CODE> object associated with this
63      * <CODE>SOAPEnvelope</CODE> object. <P> This SOAPBody will just be a
64      * container for all the BodyElements in the <CODE>OMMessage</CODE> </P>
65      *
66      * @return the <CODE>SOAPBody</CODE> object for this <CODE>
67      * SOAPEnvelope</CODE> object or <CODE>null</CODE> if there is none
68      * @throws org.apache.axis2.om.OMException if there is a problem obtaining
69      * the <CODE>SOAPBody</CODE> object
70      * @throws OMException
71      */

72     public SOAPBody getBody() throws OMException {
73             //check for the first element
74
OMElement element = getFirstElement();
75             if (element != null) {
76                 if (SOAPConstants.BODY_LOCAL_NAME.equals(element.getLocalName())) {
77                     return (SOAPBody) element;
78                 } else { // if not second element SHOULD be the body
79
OMNode node = element.getNextSibling();
80                     while (node != null && node.getType() != OMNode.ELEMENT_NODE) {
81                         node = node.getNextSibling();
82                     }
83                     element = (OMElement) node;
84
85                     if (node != null && SOAPConstants.BODY_LOCAL_NAME.equals(element.getLocalName())) {
86                         return (SOAPBody) element;
87                     } else {
88                         throw new OMException("SOAPEnvelope must contain a body element which is either first or second child element of the SOAPEnvelope.");
89                     }
90                 }
91             }
92         return null;
93     }
94
95     /**
96      * Method detach
97      *
98      * @throws OMException
99      */

100     public OMNode detach() throws OMException {
101         throw new OMException("Root Element can not be detached");
102     }
103
104     protected void checkParent(OMElement parent) throws SOAPProcessingException {
105         // here do nothing as SOAPEnvelope doesn't have a parent !!!
106
}
107 }
108
Popular Tags