KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > 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.saaj;
17
18 import org.apache.axis2.om.OMAbstractFactory;
19 import org.apache.axis2.om.OMElement;
20 import org.apache.axis2.om.OMFactory;
21 import org.apache.axis2.soap.SOAPFactory;
22 import org.w3c.dom.Document JavaDoc;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import javax.xml.soap.*;
26 import java.util.Locale JavaDoc;
27
28 /**
29  * Class SOAPBodeImpl
30  *
31  * @author Jayachandra
32  * jayachandra@gmail.com
33  */

34 public class SOAPBodyImpl extends SOAPElementImpl implements SOAPBody {
35     /**
36      * Field omSOAPBody
37      * omSOAPBody is the OM's SOAPBody object that is used for delegation purpose
38      */

39     private org.apache.axis2.soap.SOAPBody omSOAPBody;
40
41     /**
42      * Constructor SOAPBodeImpl
43      * The constructor to facilitate conversion of SAAJ SOAPBody out of OM SOAPBody
44      * @param omSoapBody
45      */

46     public SOAPBodyImpl(org.apache.axis2.soap.SOAPBody omSoapBody)
47     {
48         super(omSoapBody);
49         this.omSOAPBody = omSoapBody;
50     }
51
52     /**
53      * Method addFault
54      * @see javax.xml.soap.SOAPBody#addFault()
55      * @return
56      * @throws SOAPException
57      */

58     public SOAPFault addFault() throws SOAPException {
59         try{
60             //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
61
SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
62             org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception JavaDoc("No explicit faultstring available"));
63             omSOAPBody.addFault(omSoapFault);
64             return (new SOAPFaultImpl(omSoapFault));
65         }catch(Exception JavaDoc e)
66         {
67             throw new SOAPException(e);
68         }
69     }
70
71     /**
72      * Method hasFault
73      * @see javax.xml.soap.SOAPBody#hasFault()
74      * @return
75      */

76     public boolean hasFault() {
77         return omSOAPBody.hasFault();
78     }
79
80     /**
81      * Method getFault
82      * @see javax.xml.soap.SOAPBody#getFault()
83      * @return
84      */

85     public SOAPFault getFault() {
86         return (new SOAPFaultImpl(omSOAPBody.getFault()));
87     }
88
89     /**
90      * Method addBodyElement
91      * @param name
92      * @return
93      * @throws SOAPException
94      * @see javax.xml.soap.SOAPBody#addBodyElement(javax.xml.soap.Name)
95      */

96     public SOAPBodyElement addBodyElement(Name JavaDoc name) throws SOAPException {
97
98         try {
99         OMFactory omFactory = OMAbstractFactory.getOMFactory();
100         QName JavaDoc qname = new QName JavaDoc(name.getURI(), name.getLocalName(), name.getPrefix());
101         OMElement bodyElement = omFactory.createOMElement(qname, omSOAPBody);
102         omSOAPBody.addChild(bodyElement);
103         return (new SOAPBodyElementImpl(bodyElement));
104         } catch (Exception JavaDoc e)
105         {
106             throw new SOAPException(e);
107         }
108     }
109
110     /**
111      * Method addFault
112      * @param faultCode
113      * @param faultString
114      * @param
115      * @throws SOAPException
116      * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String, java.util.Locale)
117      */

118     public SOAPFault addFault(Name JavaDoc faultCode, String JavaDoc faultString, Locale JavaDoc locale)
119             throws SOAPException {
120         try{
121             //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
122
//actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
123
//a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
124
//So am deferring it.
125
//even locale param is dropped, don't know how to handle it at the moment. so dropped it.
126
SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
127             org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception JavaDoc(faultString));
128             omSOAPBody.addFault(omSoapFault);
129             return (new SOAPFaultImpl(omSoapFault));
130         }catch(Exception JavaDoc e)
131         {
132             throw new SOAPException(e);
133         }
134     }
135
136     /**
137      * Method addFault
138      * @param faultCode
139      * @param faultString
140      * @return
141      * @throws SOAPException
142      * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String)
143      */

144     public SOAPFault addFault(Name JavaDoc faultCode, String JavaDoc faultString)
145             throws SOAPException {
146         try{
147             //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
148
//actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
149
//a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
150
//So am deferring it.
151
SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
152             org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception JavaDoc(faultString));
153             omSOAPBody.addFault(omSoapFault);
154             return (new SOAPFaultImpl(omSoapFault));
155         }catch(Exception JavaDoc e)
156         {
157             throw new SOAPException(e);
158         }
159     }
160
161     /**
162      * Method addDocument
163      * @param document
164      * @return
165      * @throws SOAPException
166      * @see javax.xml.soap.SOAPBody#addDocument(org.w3c.dom.Document)
167      */

168     public SOAPBodyElement addDocument(Document JavaDoc document) throws SOAPException {
169         /*
170          * Don't know how to resolve this as yet. So deferring it.
171          */

172         return null;
173     }
174
175 }
176
Popular Tags