KickJava   Java API By Example, From Geeks To Geeks.

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


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.OMConstants;
19 import org.apache.axis2.om.OMElement;
20 import org.apache.axis2.om.OMException;
21 import org.apache.axis2.om.OMXMLParserWrapper;
22 import org.apache.axis2.soap.SOAPBody;
23 import org.apache.axis2.soap.SOAPEnvelope;
24 import org.apache.axis2.soap.SOAPFault;
25 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
26 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
27
28 /**
29  * Class SOAPBodyImpl
30  */

31 public abstract class SOAPBodyImpl extends SOAPElement
32         implements SOAPBody, OMConstants {
33     /**
34      * Field hasSOAPFault
35      */

36     private boolean hasSOAPFault = false;
37
38     /**
39      * @param envelope
40      */

41     public SOAPBodyImpl(SOAPEnvelope envelope) throws SOAPProcessingException {
42         super(envelope, SOAPConstants.BODY_LOCAL_NAME, true);
43
44     }
45
46     /**
47      * Constructor SOAPBodyImpl
48      *
49      * @param envelope
50      * @param builder
51      */

52     public SOAPBodyImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {
53         super(envelope, SOAPConstants.BODY_LOCAL_NAME, builder);
54     }
55
56     /**
57      * Creates a new <code>SOAPFault</code> object and adds it to
58      * this <code>SOAPBody</code> object.
59      *
60      * @param e
61      * @return the new <code>SOAPFault</code> object
62      * @throws org.apache.axis2.om.OMException if there is a SOAP error
63      * @throws OMException
64      */

65     public abstract SOAPFault addFault(Exception JavaDoc e) throws OMException;
66
67     /**
68      * Indicates whether a <code>SOAPFault</code> object exists in
69      * this <code>SOAPBody</code> object.
70      *
71      * @return <code>true</code> if a <code>SOAPFault</code> object exists in
72      * this <code>SOAPBody</code> object; <code>false</code>
73      * otherwise
74      */

75     public boolean hasFault() {
76         if (hasSOAPFault) {
77             return true;
78         } else {
79             OMElement element = getFirstElement();
80             if (element != null
81                     && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())
82                     && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName())
83                         || SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()))) { //added this line
84
hasSOAPFault = true;
85                 return true;
86             } else {
87                 return false;
88             }
89         }
90     }
91
92     /**
93      * Returns the <code>SOAPFault</code> object in this <code>SOAPBody</code>
94      * object.
95      *
96      * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code>
97      * object
98      */

99     public SOAPFault getFault() {
100         OMElement element = getFirstElement();
101         if (hasSOAPFault) {
102             return (SOAPFault) element;
103         } else if (element != null
104                 && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())
105                 && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName())
106                     || SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(element.getNamespace().getName()))) { //added this line
107
hasSOAPFault = true;
108             return (SOAPFault) element;
109         } else {
110             return null;
111         }
112
113     }
114
115     /**
116      * @param soapFault
117      * @throws org.apache.axis2.om.OMException
118      * @throws OMException
119      */

120     public void addFault(SOAPFault soapFault) throws OMException {
121         if (hasSOAPFault) {
122             throw new OMException("SOAP Body already has a SOAP Fault and there can not be more than one SOAP fault");
123         }
124         addChild(soapFault);
125         hasSOAPFault = true;
126     }
127
128     protected void checkParent(OMElement parent) throws SOAPProcessingException {
129         if (!(parent instanceof SOAPEnvelopeImpl)) {
130             throw new SOAPProcessingException("Expecting an implementation of SOAP Envelope as the parent. But received some other implementation");
131         }
132     }
133 }
134
Popular Tags