KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > 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.saaj;
17
18 import org.apache.axis2.om.OMAbstractFactory;
19 import org.apache.axis2.soap.SOAPFactory;
20
21 import javax.xml.soap.*;
22
23
24 /**
25  * Class SOAPEnvelopeImpl
26  *
27  * @author Jayachandra
28  * jayachandra@gmail.com
29  */

30 public class SOAPEnvelopeImpl extends SOAPElementImpl implements SOAPEnvelope {
31
32     /**
33      * Field soSOAPEnvelope
34      * A data member of OM's SOAPEnvelopeImpl which would be used for delegation of any work to underlying OM.
35      */

36     private org.apache.axis2.soap.SOAPEnvelope omSOAPEnvelope;
37     
38     /**
39      * Constructor SOAPEnvelopeImpl
40      */

41     public SOAPEnvelopeImpl(){
42         //super(omEnv);
43
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
44         omNode = omElement =omSOAPEnvelope = fac.getDefaultEnvelope();
45     }
46     
47     public SOAPEnvelopeImpl(org.apache.axis2.soap.SOAPEnvelope omEnvelope){
48         super(omEnvelope);
49         this.omSOAPEnvelope = omEnvelope;
50     }
51     
52     /**
53      * method getOMEnvelope
54      * @return
55      */

56     public org.apache.axis2.soap.SOAPEnvelope getOMEnvelope(){
57         return omSOAPEnvelope;
58     }
59     
60
61     /**
62      * method createName
63      * @param localName
64      * @param prefix
65      * @param uri
66      * @return
67      * @throws SOAPException
68      * @see javax.xml.soap.SOAPEnvelope#createName(java.lang.String, java.lang.String, java.lang.String)
69      */

70     public Name createName(String JavaDoc localName, String JavaDoc prefix, String JavaDoc uri)
71             throws SOAPException {
72         try {
73             return new PrefixedQName(uri,localName, prefix);
74         }catch (Exception JavaDoc e)
75         {
76             throw new SOAPException(e);
77         }
78     }
79
80     /**
81      * method createName
82      *
83      * @param localName
84      * @return
85      * @throws SOAPException
86      * @see javax.xml.soap.SOAPEnvelope#createName(java.lang.String)
87      */

88     public Name createName(String JavaDoc localName) throws SOAPException {
89         try {
90             return new PrefixedQName(null, localName, null);
91         }catch (Exception JavaDoc e)
92         {
93             throw new SOAPException(e);
94         }
95     }
96
97     /**
98      * method getHeader
99      *
100      * @return
101      * @throws SOAPException
102      * @see javax.xml.soap.SOAPEnvelope#getHeader()
103      */

104     public SOAPHeader getHeader() throws SOAPException {
105
106         org.apache.axis2.soap.SOAPHeader omSOAPHeader;
107         try
108         {
109             omSOAPHeader = (org.apache.axis2.soap.SOAPHeader) omSOAPEnvelope.getHeader();
110         }catch (Exception JavaDoc e)
111         {
112             throw new SOAPException(e);
113         }
114         if(omSOAPHeader != null)
115             return new SOAPHeaderImpl(omSOAPHeader);
116         else
117             return null;
118     }
119
120     /**
121      * method getBody
122      *
123      * @return
124      * @throws SOAPException
125      * @see javax.xml.soap.SOAPEnvelope#getBody()
126      */

127     public SOAPBody getBody() throws SOAPException {
128
129         org.apache.axis2.soap.SOAPBody omSOAPBody = null;
130         try
131         {
132             omSOAPBody = omSOAPEnvelope.getBody();
133         } catch (Exception JavaDoc e)
134         {
135             //throw new SOAPException(e);
136
}
137         if(omSOAPBody != null)
138             return (new SOAPBodyImpl(omSOAPBody));
139         else
140             return null;
141     }
142
143     /**
144      * method addHeader
145      *
146      * @return
147      * @throws SOAPException
148      * @see javax.xml.soap.SOAPEnvelope#addHeader()
149      */

150     public SOAPHeader addHeader() throws SOAPException {
151         /*
152          * Our objective is to set the omSOAPHeader of the omSOAPEnvelope if not already present
153          */

154         try {
155             org.apache.axis2.soap.SOAPHeader header = omSOAPEnvelope.getHeader();
156             if (header == null) {
157                 SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
158                 header = soapFactory.createSOAPHeader(omSOAPEnvelope);
159                 omSOAPEnvelope.addChild(header);
160                 return (new SOAPHeaderImpl(header));
161             } else {
162                 throw new SOAPException("Header already present, can't set body again without deleting the existing header");
163             }
164         }catch (Exception JavaDoc e)
165         {
166             throw new SOAPException(e);
167         }
168     }
169
170     /**
171      * method addBody
172      *
173      * @return
174      * @throws SOAPException
175      * @see javax.xml.soap.SOAPEnvelope#addBody()
176      */

177     public SOAPBody addBody() throws SOAPException {
178         /*
179          * Our objective is to set the omSOAPBody of the omSOAPEnvelope if not already present
180          */

181         try {
182             org.apache.axis2.soap.SOAPBody body = omSOAPEnvelope.getBody();
183             if (body == null) {
184                 SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
185                 body = soapFactory.createSOAPBody(omSOAPEnvelope);
186                 omSOAPEnvelope.addChild(body);
187                 return (new SOAPBodyImpl(body));
188             } else {
189                 throw new SOAPException("Body already present, can't set body again without deleting the existing body");
190             }
191         }catch (Exception JavaDoc e)
192         {
193             throw new SOAPException(e);
194         }
195     }
196
197 }
198
Popular Tags