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 javax.xml.soap.SOAPElement;
21  
22  import org.apache.axis.utils.XMLUtils;
23  import org.apache.axis.encoding.SimpleType;
24  
25  import org.apache.axis.message.addressing.util.TextExtractor;
26  
27  import org.w3c.dom.Attr;
28  import org.w3c.dom.Element;
29  
30  import javax.xml.namespace.QName;
31  
32  /***
33   * Java content class for ServiceNameType complex type.
34   * <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 67)
35   * <p>
36   * <pre>
37   * &lt;complexType name="ServiceNameType">
38   *   &lt;simpleContent>
39   *     &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>QName">
40   *       &lt;attribute name="PortName" type="{http://www.w3.org/2001/XMLSchema}NCName" />
41   *     &lt;/extension>
42   *   &lt;/simpleContent>
43   * &lt;/complexType>
44   * </pre>
45   * 
46   * @author Davanum Srinivas (dims@yahoo.com)
47   */
48  public class ServiceNameType extends AttributedQName 
49      implements SimpleType { // needed to serialize attributes
50      
51      /***
52       * Field port
53       */
54      private String port;
55      
56      public ServiceNameType(QName qname) {
57          super(qname);
58      }
59  
60      /***
61       * Constructor ServiceName
62       * 
63       * @param qname 
64       * @param port  
65       */
66      public ServiceNameType(QName qname, String port) {
67          super(qname);
68          this.port = port;
69      }
70  
71      /***
72       * Constructor ServiceName
73       * 
74       * @param namespace
75       * @param localName
76       */
77      public ServiceNameType(String namespace, 
78                             String localName) {
79          super(namespace, localName);
80      }
81      
82      /***
83       * Constructor ServiceName
84       * 
85       * @param serviceName
86       */
87      public ServiceNameType(ServiceNameType serviceName) {
88          super(serviceName);
89          this.port = serviceName.getPort();
90      }
91  
92      /***
93       * Method getPort
94       * 
95       * @return 
96       */
97      public String getPort() {
98          return port;
99      }
100 
101     /***
102      * Method setPort
103      * 
104      * @param port 
105      */
106     public void setPort(String port) {
107         this.port = port;
108     }
109 
110     /***
111      * append DOM node to parent
112      * 
113      * @param parent 
114      */
115     public void append(Element parent, String elementName) {
116         Element sn = parent.getOwnerDocument().createElementNS(
117                            Constants.NS_URI_ADDRESSING_DEFAULT,
118                            elementName);
119         String value = XMLUtils.getStringForQName(this, sn);
120         sn.appendChild(parent.getOwnerDocument().createTextNode(value));
121         if (getPort() != null) {
122             sn.setAttribute(Constants.PORT_NAME, getPort());
123         }
124         parent.appendChild(sn);
125     }
126 
127     public static ServiceNameType fromSOAPElement(SOAPElement element) 
128         throws Exception {
129         String value = TextExtractor.getText(element);
130         QName qname = TextExtractor.getQName(value, element);
131         String portName = element.getAttribute(Constants.PORT_NAME);
132         portName = (portName == null || portName.length() == 0) ? 
133             null : portName;
134         return new ServiceNameType(qname, portName);
135     }
136 
137     public static ServiceNameType fromElement(Element element) 
138         throws Exception {
139         String value = TextExtractor.getText(element);
140         QName qname = XMLUtils.getQNameFromString(value, element);
141         String portName = element.getAttribute(Constants.PORT_NAME);
142         portName = (portName == null || portName.length() == 0) ? 
143             null : portName;
144         return new ServiceNameType(qname, portName);
145     }
146 
147     // Axis bits to serialize/deserialize the fields correctly
148     
149     // Type metadata
150     private static org.apache.axis.description.TypeDesc typeDesc =
151         new org.apache.axis.description.TypeDesc(ServiceNameType.class, true);
152 
153     static {
154         typeDesc.setXmlType(new javax.xml.namespace.QName(Constants.NS_URI_ADDRESSING_DEFAULT, "ServiceNameType"));
155         org.apache.axis.description.AttributeDesc attrField = new org.apache.axis.description.AttributeDesc();
156         attrField.setFieldName("port");
157         attrField.setXmlName(new javax.xml.namespace.QName("", "PortName"));
158         attrField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
159         typeDesc.addFieldDesc(attrField);
160     }
161 
162     /***
163      * Return type metadata object
164      */
165     public static org.apache.axis.description.TypeDesc getTypeDesc() {
166         return typeDesc;
167     }
168 
169 
170     /***
171      * Get Custom Serializer
172      */
173     public static org.apache.axis.encoding.Serializer getSerializer(
174            java.lang.String mechType, 
175            java.lang.Class _javaType,  
176            javax.xml.namespace.QName _xmlType) {
177         return 
178           new  org.apache.axis.encoding.ser.SimpleSerializer(
179             _javaType, _xmlType, typeDesc);
180     }
181 
182     /***
183      * Get Custom Deserializer
184      */
185     public static org.apache.axis.encoding.Deserializer getDeserializer(
186            java.lang.String mechType, 
187            java.lang.Class _javaType,  
188            javax.xml.namespace.QName _xmlType) {
189         return 
190           new  org.apache.axis.encoding.ser.SimpleDeserializer(
191             _javaType, _xmlType, typeDesc);
192     }
193 
194 }
195 
196