KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > message > SOAPElementImpl


1 /*
2  * Copyright 2001-2004 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.jboss.axis.message;
17
18 // $Id: SOAPElementImpl.java,v 1.1.2.2 2005/04/21 22:35:19 tdiesler Exp $
19

20 import org.jboss.axis.NotImplementedException;
21 import org.jboss.axis.utils.DOM2Utils;
22 import org.jboss.logging.Logger;
23 import org.w3c.dom.Attr JavaDoc;
24 import org.w3c.dom.DOMException JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26 import org.w3c.dom.NamedNodeMap JavaDoc;
27 import org.w3c.dom.NodeList JavaDoc;
28 import org.w3c.dom.TypeInfo JavaDoc;
29
30 import javax.xml.soap.Name JavaDoc;
31 import javax.xml.soap.SOAPElement JavaDoc;
32 import javax.xml.soap.SOAPException JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Iterator JavaDoc;
35
36 /**
37  * An implemenation of the abstract SOAPElement.
38  * <p/>
39  * This class should not expose functionality that is not part of
40  * {@link SOAPElement}. Client code should use <code>SOAPElement</code> whenever possible.
41  *
42  * @author Thomas Diesler (thomas.diesler@jboss.org)
43  */

44 public class SOAPElementImpl extends NodeImpl implements SOAPElement JavaDoc
45 {
46
47    // provide logging
48
private static Logger log = Logger.getLogger(SOAPElement JavaDoc.class.getName());
49
50    // The element
51
private Element JavaDoc element;
52
53    /**
54     * Constructor used by the <code>SOAPElementFactory</code>
55     */

56    public SOAPElementImpl(String JavaDoc localPart)
57    {
58       super(DOM2Utils.createElement(null, localPart));
59       element = (Element JavaDoc)domNode;
60    }
61
62    /**
63     * Constructor used by the <code>SOAPElementFactory</code>
64     */

65    public SOAPElementImpl(String JavaDoc localPart, String JavaDoc prefix, String JavaDoc namespace)
66    {
67       super(DOM2Utils.createElement(null, namespace, prefix, localPart));
68       element = (Element JavaDoc)domNode;
69    }
70
71    /**
72     * Constructor used by the <code>SOAPElementFactory</code>
73     */

74    public SOAPElementImpl(Name JavaDoc name)
75    {
76       super(DOM2Utils.createElement(null, name));
77       element = (Element JavaDoc)domNode;
78    }
79
80    // package protected contructors
81

82    SOAPElementImpl(Element JavaDoc element)
83    {
84       super(element);
85       this.element = element;
86    }
87
88    // javax.xml.soap.SOAPElement *************************************************************************************
89

90    /**
91     * Adds an attribute with the specified name and value to this SOAPElement object.
92     *
93     * @param name a Name object with the name of the attribute
94     * @param value a String giving the value of the attribute
95     * @return the SOAPElement object into which the attribute was inserted
96     * @throws javax.xml.soap.SOAPException if there is an error in creating the Attribute
97     */

98    public SOAPElement JavaDoc addAttribute(Name JavaDoc name, String JavaDoc value) throws SOAPException JavaDoc
99    {
100       setAttributeNS(name.getURI(), name.getQualifiedName(), value);
101       return this;
102    }
103
104    /**
105     * Creates a new SOAPElement object initialized with the specified local name and adds the new element to this SOAPElement object.
106     *
107     * @param name a String giving the local name for the element
108     * @return the new SOAPElement object that was created
109     * @throws javax.xml.soap.SOAPException if there is an error in creating the SOAPElement object
110     */

111    public SOAPElement JavaDoc addChildElement(String JavaDoc name) throws SOAPException JavaDoc
112    {
113       SOAPElement JavaDoc soapElement = new SOAPElementImpl(name);
114       addChildElement(soapElement);
115       return soapElement;
116    }
117
118    /**
119     * Creates a new SOAPElement object initialized with the specified local name and prefix and adds the new element to this SOAPElement object.
120     *
121     * @param localName a String giving the local name for the new element
122     * @param prefix a String giving the namespace prefix for the new element
123     * @return the new SOAPElement object that was created
124     * @throws javax.xml.soap.SOAPException if there is an error in creating the SOAPElement object
125     */

126    public SOAPElement JavaDoc addChildElement(String JavaDoc localName, String JavaDoc prefix) throws SOAPException JavaDoc
127    {
128       SOAPElement JavaDoc soapElement = new SOAPElementImpl(localName, prefix, null);
129       addChildElement(soapElement);
130       return soapElement;
131    }
132
133    /**
134     * Creates a new SOAPElement object initialized with the specified local name, prefix, and URI and adds the new element to this SOAPElement object.
135     *
136     * @param localName a String giving the local name for the new element
137     * @param prefix a String giving the namespace prefix for the new element
138     * @param uri a String giving the URI of the namespace to which the new element belongs
139     * @return the new SOAPElement object that was created
140     * @throws javax.xml.soap.SOAPException if there is an error in creating the SOAPElement object
141     */

142    public SOAPElement JavaDoc addChildElement(String JavaDoc localName, String JavaDoc prefix, String JavaDoc uri) throws SOAPException JavaDoc
143    {
144       SOAPElement JavaDoc soapElement = new SOAPElementImpl(localName, prefix, uri);
145       addChildElement(soapElement);
146       return soapElement;
147    }
148
149    /**
150     * Creates a new SOAPElement object initialized with the given Name object and adds the new element to this SOAPElement object.
151     *
152     * @param name a Name object with the XML name for the new element
153     * @return the new SOAPElement object that was created
154     * @throws javax.xml.soap.SOAPException if there is an error in creating the SOAPElement object
155     */

156    public SOAPElement JavaDoc addChildElement(Name JavaDoc name) throws SOAPException JavaDoc
157    {
158       SOAPElement JavaDoc soapElement = new SOAPElementImpl(name);
159       addChildElement(soapElement);
160       return soapElement;
161    }
162
163    /**
164     * Add a SOAPElement as a child of this SOAPElement instance. The SOAPElement is expected to be created by a SOAPElementFactory.
165     * <p/>
166     * Callers should not rely on the element instance being added as is into the XML tree.
167     * Implementations could end up copying the content of the SOAPElement passed into an instance of a different SOAPElement
168     * implementation. For instance if addChildElement() is called on a SOAPHeader, element will be copied into an instance of a SOAPHeaderElement.
169     * <p/>
170     * The fragment rooted in element is either added as a whole or not at all, if there was an error.
171     * <p/>
172     * The fragment rooted in element cannot contain elements named "Envelope", "Header" or "Body" and in the SOAP namespace.
173     * Any namespace prefixes present in the fragment should be fully resolved using appropriate namespace declarations within the fragment itself.
174     *
175     * @param child the SOAPElement to be added as a new child
176     * @return an instance representing the new SOAP element that was actually added to the tree.
177     * @throws javax.xml.soap.SOAPException if there was an error in adding this element as a child
178     */

179    public SOAPElement JavaDoc addChildElement(SOAPElement JavaDoc child) throws SOAPException JavaDoc
180    {
181       element.appendChild(child);
182       return new SOAPElementAxisImpl(child);
183    }
184
185    /**
186     * Adds a namespace declaration with the specified prefix and URI to this SOAPElement object.
187     *
188     * @param prefix a String giving the prefix of the namespace
189     * @param uri a String giving the uri of the namespace
190     * @return the SOAPElement object into which this namespace declaration was inserted.
191     * @throws javax.xml.soap.SOAPException if there is an error in creating the namespace
192     */

193    public SOAPElement JavaDoc addNamespaceDeclaration(String JavaDoc prefix, String JavaDoc uri) throws SOAPException JavaDoc
194    {
195       element.setAttribute("xmlns:" + prefix, uri);
196       return this;
197    }
198
199    /**
200     * Creates a new Text object initialized with the given String and adds it to this SOAPElement object.
201     *
202     * @param value a String object with the textual content to be added
203     * @return the SOAPElement object into which the new Text object was inserted
204     * @throws SOAPException if there is an error in creating the new Text object
205     */

206    public SOAPElement JavaDoc addTextNode(String JavaDoc value) throws SOAPException JavaDoc
207    {
208       org.w3c.dom.Text JavaDoc domText = element.getOwnerDocument().createTextNode(value);
209       javax.xml.soap.Text JavaDoc soapText = new TextImpl(domText);
210       appendChild(soapText);
211       return this;
212    }
213
214    /**
215     * Returns an Iterator over all of the attribute Name objects in this SOAPElement object.
216     * <p/>
217     * The iterator can be used to get the attribute names, which can then be passed to the method getAttributeValue to
218     * retrieve the value of each attribute.
219     *
220     * @return an iterator over the names of the attributes
221     */

222    public Iterator JavaDoc getAllAttributes()
223    {
224       ArrayList JavaDoc list = new ArrayList JavaDoc();
225       NamedNodeMap JavaDoc nnm = getAttributes();
226       for (int i = 0; i < nnm.getLength(); i++)
227       {
228          org.w3c.dom.Node JavaDoc node = (org.w3c.dom.Node JavaDoc)nnm.item(i);
229          String JavaDoc local = node.getLocalName();
230          String JavaDoc prefix = node.getPrefix();
231          String JavaDoc uri = node.getNamespaceURI();
232          list.add(new NameImpl(local, prefix, uri));
233       }
234       return list.iterator();
235    }
236
237    /**
238     * Returns the value of the attribute with the specified name.
239     *
240     * @param name a Name object with the name of the attribute
241     * @return a String giving the value of the specified attribute
242     */

243    public String JavaDoc getAttributeValue(Name JavaDoc name)
244    {
245       throw new NotImplementedException();
246    }
247
248    /**
249     * Returns an Iterator over all the immediate child Nodes of this element.
250     * <p/>
251     * This includes javax.xml.soap.Text objects as well as SOAPElement objects.
252     * Calling this method may cause child Element, SOAPElement and org.w3c.dom.Text nodes to be replaced by SOAPElement,
253     * SOAPHeaderElement, SOAPBodyElement or javax.xml.soap.Text nodes as appropriate for the type of this parent node.
254     * As a result the calling application must treat any existing references to these child nodes that have been obtained
255     * through DOM APIs as invalid and either discard them or refresh them with the values returned by this Iterator.
256     * This behavior can be avoided by calling the equivalent DOM APIs. See javax.xml.soap for more details.
257     *
258     * @return an iterator with the content of this SOAPElement object
259     */

260    public Iterator JavaDoc getChildElements()
261    {
262       throw new NotImplementedException();
263    }
264
265    /**
266     * Returns an Iterator over all the immediate child Nodes of this element with the specified name.
267     * <p/>
268     * All of these children will be SOAPElement nodes.
269     * Calling this method may cause child Element, SOAPElement and org.w3c.dom.Text nodes to be replaced by SOAPElement,
270     * SOAPHeaderElement, SOAPBodyElement or javax.xml.soap.Text nodes as appropriate for the type of this parent node.
271     * As a result the calling application must treat any existing references to these child nodes that have been obtained
272     * through DOM APIs as invalid and either discard them or refresh them with the values returned by this Iterator.
273     * This behavior can be avoided by calling the equivalent DOM APIs. See javax.xml.soap for more details.
274     *
275     * @param name a Name object with the name of the child elements to be returned
276     * @return an Iterator object over all the elements in this SOAPElement object with the specified name
277     */

278    public Iterator JavaDoc getChildElements(Name JavaDoc name)
279    {
280       throw new NotImplementedException();
281    }
282
283    /**
284     * Returns the name of this SOAPElement object.
285     *
286     * @return a Name object with the name of this SOAPElement object
287     */

288    public Name JavaDoc getElementName()
289    {
290       throw new NotImplementedException();
291    }
292
293    /**
294     * Returns the encoding style for this SOAPElement object.
295     *
296     * @return a String giving the encoding style
297     */

298    public String JavaDoc getEncodingStyle()
299    {
300       throw new NotImplementedException();
301    }
302
303    /**
304     * Returns an Iterator over the namespace prefix Strings declared by this element.
305     * <p/>
306     * The prefixes returned by this iterator can be passed to the method getNamespaceURI to retrieve the URI of each namespace.
307     *
308     * @return an iterator over the namespace prefixes in this SOAPElement object
309     */

310    public Iterator JavaDoc getNamespacePrefixes()
311    {
312       throw new NotImplementedException();
313    }
314
315    /**
316     * Returns the URI of the namespace that has the given prefix.
317     *
318     * @param prefix a String giving the prefix of the namespace for which to search
319     * @return a String with the uri of the namespace that has the given prefix
320     */

321    public String JavaDoc getNamespaceURI(String JavaDoc prefix)
322    {
323       throw new NotImplementedException();
324    }
325
326    /**
327     * Returns an Iterator over the namespace prefix Strings visible to this element.
328     * <p/>
329     * The prefixes returned by this iterator can be passed to the method getNamespaceURI to retrieve the URI of each namespace.
330     *
331     * @return an iterator over the namespace prefixes are within scope of this SOAPElement object
332     */

333    public Iterator JavaDoc getVisibleNamespacePrefixes()
334    {
335       throw new NotImplementedException();
336    }
337
338    /**
339     * Removes the attribute with the specified name.
340     *
341     * @param name the Name object with the name of the attribute to be removed
342     * @return true if the attribute was removed successfully; false if it was not
343     */

344    public boolean removeAttribute(Name JavaDoc name)
345    {
346       throw new NotImplementedException();
347    }
348
349    /**
350     * Detaches all children of this SOAPElement.
351     * <p/>
352     * This method is useful for rolling back the construction of partially completed SOAPHeaders and SOAPBodys in
353     * preparation for sending a fault when an error condition is detected.
354     * It is also useful for recycling portions of a document within a SOAP message.
355     */

356    public void removeContents()
357    {
358       throw new NotImplementedException();
359    }
360
361    /**
362     * Removes the namespace declaration corresponding to the given prefix.
363     *
364     * @param prefix a String giving the prefix for which to search
365     * @return true if the namespace declaration was removed successfully; false if it was not
366     */

367    public boolean removeNamespaceDeclaration(String JavaDoc prefix)
368    {
369       throw new NotImplementedException();
370    }
371
372    /**
373     * Sets the encoding style for this SOAPElement object to one specified.
374     *
375     * @param encodingStyle a String giving the encoding style
376     * @throws javax.xml.soap.SOAPException if there was a problem in the encoding style being set.
377     */

378    public void setEncodingStyle(String JavaDoc encodingStyle) throws SOAPException JavaDoc
379    {
380       throw new NotImplementedException();
381    }
382
383    // org.w3c.Element ***********************************************************************************************
384

385    public String JavaDoc getTagName()
386    {
387       return element.getTagName();
388    }
389
390    public void removeAttribute(String JavaDoc name) throws DOMException JavaDoc
391    {
392       element.removeAttribute(name);
393    }
394
395    public boolean hasAttribute(String JavaDoc name)
396    {
397       return element.hasAttribute(name);
398    }
399
400    public String JavaDoc getAttribute(String JavaDoc name)
401    {
402       return element.getAttribute(name);
403    }
404
405    public void removeAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName) throws DOMException JavaDoc
406    {
407       element.removeAttributeNS(namespaceURI, localName);
408    }
409
410    public void setAttribute(String JavaDoc name, String JavaDoc value) throws DOMException JavaDoc
411    {
412       element.setAttribute(name, value);
413    }
414
415    public boolean hasAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName)
416    {
417       return element.hasAttributeNS(namespaceURI, localName);
418    }
419
420    public Attr JavaDoc getAttributeNode(String JavaDoc name)
421    {
422       return element.getAttributeNode(name);
423    }
424
425    public Attr JavaDoc removeAttributeNode(Attr JavaDoc oldAttr) throws DOMException JavaDoc
426    {
427       return element.removeAttributeNode(oldAttr);
428    }
429
430    public Attr JavaDoc setAttributeNode(Attr JavaDoc newAttr) throws DOMException JavaDoc
431    {
432       return element.setAttributeNode(newAttr);
433    }
434
435    public Attr JavaDoc setAttributeNodeNS(Attr JavaDoc newAttr) throws DOMException JavaDoc
436    {
437       return element.setAttributeNodeNS(newAttr);
438    }
439
440    public NodeList JavaDoc getElementsByTagName(String JavaDoc name)
441    {
442       return element.getElementsByTagName(name);
443    }
444
445    public String JavaDoc getAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName)
446    {
447       return element.getAttributeNS(namespaceURI, localName);
448    }
449
450    public void setAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName, String JavaDoc value) throws DOMException JavaDoc
451    {
452       element.setAttributeNS(namespaceURI, qualifiedName, value);
453    }
454
455    public Attr JavaDoc getAttributeNodeNS(String JavaDoc namespaceURI, String JavaDoc localName)
456    {
457       return element.getAttributeNodeNS(namespaceURI, localName);
458    }
459
460    public NodeList JavaDoc getElementsByTagNameNS(String JavaDoc namespaceURI, String JavaDoc localName)
461    {
462       return element.getElementsByTagNameNS(namespaceURI, localName);
463    }
464
465    // DOM3-API start ***************************************************************************************************
466
public TypeInfo JavaDoc getSchemaTypeInfo()
467    {
468       return null;
469    }
470
471    public void setIdAttribute(String JavaDoc name, boolean isId) throws DOMException JavaDoc
472    {
473
474    }
475
476    public void setIdAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName, boolean isId) throws DOMException JavaDoc
477    {
478
479    }
480
481    public void setIdAttributeNode(Attr JavaDoc idAttr, boolean isId) throws DOMException JavaDoc
482    {
483       
484    }
485    // DOM3-API end *****************************************************************************************************
486
}
487
Popular Tags