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.SOAPHeaderElement;
21  import org.apache.axis.message.addressing.util.TextExtractor;
22  import org.apache.axis.message.addressing.util.AddressingUtils;
23  import org.apache.axis.types.URI;
24  
25  import javax.xml.namespace.QName;
26  import javax.xml.soap.Name;
27  import javax.xml.soap.SOAPElement;
28  import javax.xml.soap.SOAPEnvelope;
29  import javax.xml.soap.SOAPHeader;
30  
31  /***
32   * Java content class for RelatesTo element declaration.
33   * <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 77)
34   * <p>
35   * <pre>
36   * &lt;element name="RelatesTo" type="{http://schemas.xmlsoap.org/ws/2004/08/addressing}Relationship"/>
37   * </pre>
38   * 
39   * @author Davanum Srinivas (dims@yahoo.com)
40   */
41  public class RelatesTo extends Relationship {
42  
43      /***
44       * Constructor RelatesTo
45       * 
46       * @param uri  
47       * @param type 
48       * @throws URI.MalformedURIException 
49       */
50      public RelatesTo(String uri, String type) 
51          throws URI.MalformedURIException {
52          super(uri, type);
53      }
54  
55      /***
56       * Constructor RelatesTo
57       * 
58       * @param uri  
59       * @param type 
60       */
61      public RelatesTo(URI uri, QName type) {
62          super(uri, type);
63      }
64  
65      /***
66       * Constructor RelatesTo
67       * 
68       * @param uri  
69       * @param type 
70       */
71      public RelatesTo(String uri, QName type) 
72          throws URI.MalformedURIException {
73          super(new URI(uri), type);
74      }
75  
76      /***
77       * Constructor RelatesTo
78       * 
79       * @param el 
80       * @throws Exception
81       */
82      public RelatesTo(SOAPElement el) 
83          throws Exception {
84          super();
85          setURI(new URI(TextExtractor.getText(el)));
86          String value = el.getAttribute(Constants.RELATIONSHIP_TYPE);
87          if (value != null && value.length() > 0) {
88              int pos = value.indexOf(':');
89              if (pos == -1) {
90                  setType(new QName(value));
91              } else {
92                  String namespace =
93                      el.getNamespaceURI(value.substring(0, pos));
94                  setType(new QName(namespace, value.substring(pos+1)));
95              }
96          } else {
97              setType(Constants.QNAME_RESPONSE);
98          }
99  }
100 
101     protected SOAPHeaderElement toSOAPHeaderElement(SOAPEnvelope env,
102                                                     String actorURI)
103         throws Exception {
104         Name nm = env.createName(Constants.RELATES_TO,
105                                  Constants.NS_PREFIX_ADDRESSING,
106                                  Constants.NS_URI_ADDRESSING_DEFAULT);
107         SOAPHeader header = env.getHeader();
108         if (header == null) {
109             header = env.addHeader();
110         }
111 
112         SOAPHeaderElement headerElement = 
113             (SOAPHeaderElement)header.addHeaderElement(nm);
114         headerElement.setActor(actorURI);
115 
116         QName type = getType();
117 
118         if (type != null) {
119             headerElement.addAttribute("", Constants.RELATIONSHIP_TYPE, type);
120         }
121         
122         headerElement.addTextNode(getURI().toString());
123         
124         return headerElement;
125     }
126     
127 }