KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > SOAPMessageImpl


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.OMOutput;
19 import org.apache.axis2.transport.http.HTTPConstants;
20
21 import javax.xml.soap.*;
22 import javax.xml.stream.XMLOutputFactory;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 /**
28  * @author Ashutosh Shahi ashutosh.shahi@gmail.com
29  *
30  * TODO To change the template for this generated type comment go to
31  * Window - Preferences - Java - Code Style - Code Templates
32  */

33 public class SOAPMessageImpl extends SOAPMessage {
34     
35     private SOAPPartImpl mSOAPPart;
36     private java.util.Hashtable JavaDoc mProps = new java.util.Hashtable JavaDoc();
37     private MimeHeaders headers;
38
39     public SOAPMessageImpl(Object JavaDoc initialContents){
40         try{
41         setup(initialContents, false, null, null, null);
42         } catch(SOAPException e){
43             e.printStackTrace();
44         }
45     }
46     
47     public SOAPMessageImpl(Object JavaDoc initialContents, boolean bodyInStream, javax.xml.soap.MimeHeaders JavaDoc headers) {
48         try{
49         setup(initialContents, bodyInStream, null, null, (MimeHeaders)headers);
50         } catch(SOAPException e){
51             e.printStackTrace();
52         }
53     }
54     
55     private void setup(Object JavaDoc initialContents, boolean bodyInStream,
56             String JavaDoc contentType, String JavaDoc contentLocation,
57             MimeHeaders mimeHeaders)throws SOAPException{
58         if(null == mSOAPPart)
59             mSOAPPart = new SOAPPartImpl(this, initialContents, bodyInStream);
60         else
61             mSOAPPart.setMessage(this);
62         
63         headers = (mimeHeaders == null) ? new MimeHeaders() : new MimeHeaders(mimeHeaders);
64     }
65     
66     /**
67      * Retrieves a description of this <CODE>SOAPMessage</CODE>
68      * object's content.
69      * @return a <CODE>String</CODE> describing the content of this
70      * message or <CODE>null</CODE> if no description has been
71      * set
72      * @see #setContentDescription(java.lang.String) setContentDescription(java.lang.String)
73      */

74     public String JavaDoc getContentDescription() {
75         String JavaDoc values[] = headers.getHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION);
76         if(values != null && values.length > 0)
77             return values[0];
78         return null;
79     }
80
81     /**
82      * Sets the description of this <CODE>SOAPMessage</CODE>
83      * object's content with the given description.
84      * @param description a <CODE>String</CODE>
85      * describing the content of this message
86      * @see #getContentDescription() getContentDescription()
87      */

88     public void setContentDescription(String JavaDoc description) {
89         headers.setHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION, description);
90     }
91
92     /* (non-Javadoc)
93      * @see javax.xml.soap.SOAPMessage#getSOAPPart()
94      */

95     public SOAPPart getSOAPPart() {
96         return mSOAPPart;
97     }
98     
99     public SOAPBody getSOAPBody() throws SOAPException {
100         return mSOAPPart.getEnvelope().getBody();
101     }
102
103     public SOAPHeader getSOAPHeader() throws SOAPException {
104         return mSOAPPart.getEnvelope().getHeader();
105     }
106     
107     public void setProperty(String JavaDoc property, Object JavaDoc value) throws SOAPException {
108         mProps.put(property, value);
109     }
110
111     public Object JavaDoc getProperty(String JavaDoc property) throws SOAPException {
112         return mProps.get(property);
113     }
114
115     /* (non-Javadoc)
116      * @see javax.xml.soap.SOAPMessage#removeAllAttachments()
117      */

118     public void removeAllAttachments() {
119         // TODO Auto-generated method stub
120

121     }
122
123     /* (non-Javadoc)
124      * @see javax.xml.soap.SOAPMessage#countAttachments()
125      */

126     public int countAttachments() {
127         // TODO Auto-generated method stub
128
return 0;
129     }
130
131     /* (non-Javadoc)
132      * @see javax.xml.soap.SOAPMessage#getAttachments()
133      */

134     public Iterator JavaDoc getAttachments() {
135         // TODO Auto-generated method stub
136
return null;
137     }
138
139     /* (non-Javadoc)
140      * @see javax.xml.soap.SOAPMessage#getAttachments(javax.xml.soap.MimeHeaders)
141      */

142     public Iterator JavaDoc getAttachments(javax.xml.soap.MimeHeaders JavaDoc headers) {
143         // TODO Auto-generated method stub
144
return null;
145     }
146
147     /* (non-Javadoc)
148      * @see javax.xml.soap.SOAPMessage#addAttachmentPart(javax.xml.soap.AttachmentPart)
149      */

150     public void addAttachmentPart(AttachmentPart attachmentpart) {
151         // TODO Auto-generated method stub
152

153     }
154
155     /* (non-Javadoc)
156      * @see javax.xml.soap.SOAPMessage#createAttachmentPart()
157      */

158     public AttachmentPart createAttachmentPart() {
159         // TODO Auto-generated method stub
160
return null;
161     }
162
163     /* (non-Javadoc)
164      * @see javax.xml.soap.SOAPMessage#getMimeHeaders()
165      */

166     public javax.xml.soap.MimeHeaders JavaDoc getMimeHeaders() {
167         
168         return headers;
169     }
170
171     /* (non-Javadoc)
172      * @see javax.xml.soap.SOAPMessage#saveChanges()
173      */

174     public void saveChanges() throws SOAPException {
175         // TODO Auto-generated method stub
176

177     }
178
179     /* (non-Javadoc)
180      * @see javax.xml.soap.SOAPMessage#saveRequired()
181      */

182     public boolean saveRequired() {
183         // TODO Auto-generated method stub
184
return false;
185     }
186
187     /* (non-Javadoc)
188      * @see javax.xml.soap.SOAPMessage#writeTo(java.io.OutputStream)
189      */

190     public void writeTo(OutputStream JavaDoc out) throws SOAPException, IOException JavaDoc {
191         try{
192         OMOutput omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(out));
193         ((SOAPEnvelopeImpl)mSOAPPart.getEnvelope()).getOMEnvelope().serialize(omOutput);
194         omOutput.flush();
195         } catch(Exception JavaDoc e){
196             throw new SOAPException(e);
197         }
198     }
199
200 }
201
Popular Tags