KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.XMLUtils;
19 import org.w3c.dom.*;
20
21 import javax.xml.parsers.ParserConfigurationException JavaDoc;
22 import javax.xml.soap.SOAPException JavaDoc;
23
24 /**
25  * @author Ashutosh Shahi ashutosh.shahi@gmail.com
26  *
27  * TODO To change the template for this generated type comment go to
28  * Window - Preferences - Java - Code Style - Code Templates
29  */

30 public class SOAPDocumentImpl implements Document {
31
32     // Depending on the user's parser preference
33
protected Document delegate = null;
34     protected SOAPPartImpl soapPart = null;
35     
36     /**
37      * Construct the Document
38      *
39      * @param sp the soap part
40      */

41     public SOAPDocumentImpl(SOAPPartImpl sp) {
42         try {
43             delegate = XMLUtils.newDocument();
44         } catch (ParserConfigurationException JavaDoc e) {
45             // Do nothing
46
}
47         soapPart = sp;
48     }
49     
50     public DOMImplementation getImplementation() {
51         return delegate.getImplementation();
52     }
53
54     /**
55      *
56      * Creates an empty <code>DocumentFragment</code> object. @todo not
57      * implemented yet
58      *
59      * @return A new <code>DocumentFragment</code>.
60      */

61     public DocumentFragment createDocumentFragment() {
62         return delegate.createDocumentFragment();
63     }
64
65     /**
66      * @todo : link with SOAP
67      *
68      * @return
69      */

70     public DocumentType getDoctype() {
71         return delegate.getDoctype();
72     }
73
74     /**
75      * should not be called, the method will be handled in SOAPPart
76      *
77      * @return
78      */

79     public Element getDocumentElement() {
80         return soapPart.getDocumentElement();
81     }
82
83     /**
84      * @todo: How Axis will maintain the Attribute representation ?
85      */

86     public Attr createAttribute(String JavaDoc name) throws DOMException {
87         return delegate.createAttribute(name);
88     }
89
90     /* (non-Javadoc)
91      * @see org.w3c.dom.Document#createCDATASection(java.lang.String)
92      */

93     public CDATASection createCDATASection(String JavaDoc arg0) throws DOMException {
94         // Not implementing this one, as it may not be supported in om
95
return null;
96     }
97
98     /* (non-Javadoc)
99      * @see org.w3c.dom.Document#createComment(java.lang.String)
100      */

101     public Comment createComment(String JavaDoc arg0) {
102         //Not implementing this one, as it may not be supported in om
103
return null;
104     }
105
106     /* (non-Javadoc)
107      * @see org.w3c.dom.Document#createElement(java.lang.String)
108      */

109     public Element createElement(String JavaDoc arg0) throws DOMException {
110         // TODO Auto-generated method stub
111
return null;
112     }
113
114     public Element getElementById(String JavaDoc elementId) {
115         return delegate.getElementById(elementId);
116     }
117
118
119     /**
120      * @param name
121      * @return @throws
122      * DOMException
123      */

124     public EntityReference createEntityReference(String JavaDoc name)
125     throws DOMException {
126         throw new java.lang.UnsupportedOperationException JavaDoc(
127         "createEntityReference");
128     }
129
130     /* (non-Javadoc)
131      * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean)
132      */

133     public Node importNode(Node arg0, boolean arg1) throws DOMException {
134         // TODO Auto-generated method stub
135
return null;
136     }
137
138     /* (non-Javadoc)
139      * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String)
140      */

141     public NodeList getElementsByTagName(String JavaDoc localName) {
142         try{
143             NodeListImpl list = new NodeListImpl();
144             if (soapPart != null) {
145                 SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope();
146                 SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader();
147                 if (header != null) {
148                     list.addNodeList(header.getElementsByTagName(localName));
149                 }
150                 SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody();
151                 if (body != null) {
152                     list.addNodeList(body.getElementsByTagName(localName));
153                 }
154             }
155             return list;
156         }catch (SOAPException JavaDoc se) {
157             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
158         }
159     }
160
161     /* (non-Javadoc)
162      * @see org.w3c.dom.Document#createTextNode(java.lang.String)
163      */

164     public Text createTextNode(String JavaDoc data) {
165         TextImpl me = new TextImpl(delegate.createTextNode(data));
166         me.setOwnerDocument(soapPart);
167         return me;
168     }
169
170     /**
171      * Attribute is not particularly dealt with in SAAJ.
172      *
173      */

174     public Attr createAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName)
175     throws DOMException {
176         return delegate.createAttributeNS(namespaceURI, qualifiedName);
177     }
178
179     /* (non-Javadoc)
180      * @see org.w3c.dom.Document#createElementNS(java.lang.String, java.lang.String)
181      */

182     public Element createElementNS(String JavaDoc arg0, String JavaDoc arg1)
183             throws DOMException {
184         // TODO Auto-generated method stub
185
return null;
186     }
187
188     /* (non-Javadoc)
189      * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, java.lang.String)
190      */

191     public NodeList getElementsByTagNameNS(String JavaDoc namespaceURI, String JavaDoc localName) {
192         try{
193             NodeListImpl list = new NodeListImpl();
194             if (soapPart != null) {
195                 SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope();
196                 SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader();
197                 if (header != null) {
198                     list.addNodeList(header.getElementsByTagNameNS(namespaceURI, localName));
199                 }
200                 SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody();
201                 if (body != null) {
202                     list.addNodeList(body.getElementsByTagNameNS(namespaceURI, localName));
203                 }
204             }
205             return list;
206         }catch (SOAPException JavaDoc se) {
207             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
208         }
209     }
210
211
212     public ProcessingInstruction createProcessingInstruction(
213             String JavaDoc target,
214             String JavaDoc data)
215     throws DOMException {
216         throw new java.lang.UnsupportedOperationException JavaDoc(
217         "createProcessingInstruction");
218     }
219
220
221     /**
222      * override it in sub-classes
223      *
224      * @return
225      */

226     public short getNodeType() {
227         return Node.DOCUMENT_NODE;
228     }
229
230
231     public void normalize() {
232         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
233     }
234
235
236     public boolean hasAttributes() {
237         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
238     }
239
240     public boolean hasChildNodes() {
241         try {
242             if (soapPart != null) {
243                 if (soapPart.getEnvelope() != null) {
244                     return true;
245                 }
246             }
247             return false;
248         } catch (SOAPException JavaDoc se) {
249             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
250         }
251     }
252
253     public String JavaDoc getLocalName() {
254         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
255     }
256
257     public String JavaDoc getNamespaceURI() {
258         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
259     }
260
261     
262     public String JavaDoc getNodeName() {
263         return null;
264     }
265
266     public String JavaDoc getNodeValue() throws DOMException {
267         throw new DOMException(
268                 DOMException.NO_DATA_ALLOWED_ERR,
269                 "Cannot use TextNode.get in " + this);
270     }
271
272     public String JavaDoc getPrefix() {
273         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
274     }
275
276     public void setNodeValue(String JavaDoc nodeValue) throws DOMException {
277         throw new DOMException(
278                 DOMException.NO_DATA_ALLOWED_ERR,
279                 "Cannot use TextNode.set in " + this);
280     }
281
282
283     public void setPrefix(String JavaDoc prefix) {
284         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
285     }
286
287     /**
288      *
289      * we have to have a link to them...
290      */

291     public Document getOwnerDocument() {
292         return null;
293     }
294
295     public NamedNodeMap getAttributes() {
296         return null;
297     }
298
299     public Node getFirstChild() {
300         try {
301             if (soapPart != null)
302                 return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart
303                 .getEnvelope();
304             else
305                 return null;
306         } catch (SOAPException JavaDoc se) {
307             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
308         }
309     }
310
311     public Node getLastChild() {
312         try {
313             if (soapPart != null)
314                 return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart
315                 .getEnvelope();
316             else
317                 return null;
318         } catch (SOAPException JavaDoc se) {
319             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
320         }
321     }
322
323     public Node getNextSibling() {
324
325         return null;
326     }
327
328     public Node getParentNode() {
329         return null;
330     }
331
332     public Node getPreviousSibling() {
333         return null;
334     }
335
336     public Node cloneNode(boolean deep) {
337         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
338     }
339
340     
341     public NodeList getChildNodes() {
342         try {
343             if (soapPart != null) {
344                 NodeListImpl children = new NodeListImpl();
345                 children.addNode(soapPart.getEnvelope());
346                 return children;
347             } else {
348                 return NodeListImpl.EMPTY_NODELIST;
349             }
350         } catch (SOAPException JavaDoc se) {
351             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
352         }
353
354     }
355
356     // fill appropriate features
357
private String JavaDoc[] features = { "foo", "bar" };
358     private String JavaDoc version = "version 2.0";
359
360     public boolean isSupported(String JavaDoc feature, String JavaDoc version) {
361         if (!version.equalsIgnoreCase(version))
362             return false;
363         else
364             return true;
365     }
366
367     public Node appendChild(Node newChild) throws DOMException {
368         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
369     }
370
371     public Node removeChild(Node oldChild) throws DOMException {
372         try {
373             Node envNode;
374             if (soapPart != null) {
375                 envNode = soapPart.getEnvelope();
376                 if (envNode.equals(oldChild)) {
377                     return envNode;
378                 }
379             }
380             throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
381         } catch (SOAPException JavaDoc se) {
382             throw new DOMException(DOMException.INVALID_STATE_ERR, "");
383         }
384     }
385
386     public Node insertBefore(Node newChild, Node refChild)
387     throws DOMException {
388         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
389     }
390
391     public Node replaceChild(Node newChild, Node oldChild)
392     throws DOMException {
393         throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
394     }
395
396
397 }
398
Popular Tags