View Javadoc

1   /*
2    * Copyright  1999-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   */
17  
18  package org.apache.axis.message.addressing;
19  
20  import org.apache.axis.message.addressing.util.TextExtractor;
21  
22  import org.apache.axis.types.URI;
23  
24  import javax.xml.soap.SOAPEnvelope;
25  import javax.xml.soap.SOAPHeader;
26  import javax.xml.soap.SOAPElement;
27  import javax.xml.soap.SOAPHeaderElement;
28  import javax.xml.soap.Name;
29  import javax.xml.namespace.QName;
30  
31  import java.util.Iterator;
32  import java.util.List;
33  import java.util.ArrayList;
34  
35  import org.w3c.dom.Element;
36  import org.w3c.dom.Document;
37  
38  /***
39   * Java content class for AttributedURI complex type.
40   * <p>The following schema fragment specifies the expected content contained within this java content object. (defined at http://schemas.xmlsoap.org/ws/2004/08/addressing line 105)
41   * <p>
42   * <pre>
43   * &lt;complexType name="AttributedURI">
44   *   &lt;simpleContent>
45   *     &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>anyURI">
46   *     &lt;/extension>
47   *   &lt;/simpleContent>
48   * &lt;/complexType>
49   * </pre>
50   * 
51   * @author Davanum Srinivas (dims@yahoo.com)
52   */
53  public class AttributedURI extends URI {
54  
55      /***
56       * Constructor AttributedURI
57       * 
58       * @param uri 
59       */
60      public AttributedURI(URI uri) {
61          super(uri);
62      }
63  
64      /***
65       * Constructor Address
66       * 
67       * @param uri 
68       * @throws MalformedURIException 
69       */
70      public AttributedURI(String uri) throws MalformedURIException {
71          this(new URI(uri));
72      }
73  
74      /***
75       * Constructor AttributedURI
76       */
77      public AttributedURI() {
78      }
79  
80      /***
81       * Constructor AttributedURI
82       * 
83       * @param el 
84       * @throws Exception 
85       */
86      public AttributedURI(SOAPHeaderElement el) 
87          throws Exception {
88          super(new URI(TextExtractor.getText(el)));
89      }
90  
91      /***
92       * append DOM node to parent
93       * 
94       * @param parent 
95       */
96      public void append(Element parent, String elementName) {
97          Document doc = parent.getOwnerDocument();
98          Element child = doc.createElementNS(Constants.NS_URI_ADDRESSING_DEFAULT, elementName);
99          child.appendChild(doc.createTextNode(toString()));
100         parent.appendChild(child);
101     }
102 
103     protected SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env,
104                                                     String actorURI,
105                                                     String name)
106         throws Exception {
107         if (name == null) {
108             throw new IllegalArgumentException("A null value for the name parameter is not allowed.");
109         }
110         Name nm = env.createName(name, 
111                                  Constants.NS_PREFIX_ADDRESSING,
112                                  Constants.NS_URI_ADDRESSING_DEFAULT);
113         SOAPHeader header = env.getHeader();
114         if (header == null) {
115             header = env.addHeader();
116         }
117 
118         // add the new header element
119         SOAPHeaderElement headerElement = header.addHeaderElement(nm);
120         headerElement.setActor(actorURI);
121         headerElement.addTextNode(toString());
122         return headerElement;
123     }
124     
125 }
126 
127