1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.axis.message.addressing;
17
18 import javax.xml.namespace.QName;
19 import javax.xml.soap.SOAPElement;
20
21 import org.apache.axis.description.AttributeDesc;
22 import org.apache.axis.description.TypeDesc;
23 import org.apache.axis.encoding.Deserializer;
24 import org.apache.axis.encoding.Serializer;
25 import org.apache.axis.encoding.SimpleType;
26 import org.apache.axis.encoding.ser.SimpleDeserializer;
27 import org.apache.axis.encoding.ser.SimpleSerializer;
28 import org.apache.axis.message.addressing.util.TextExtractor;
29 import org.apache.axis.utils.XMLUtils;
30 import org.w3c.dom.Element;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class ServiceNameType extends AttributedQName implements SimpleType {
55
56
57
58
59 private static final long serialVersionUID = 4494158339591159503L;
60
61
62
63
64 private static final TypeDesc TYPE_DESC = new TypeDesc(ServiceNameType.class, true);
65
66 static {
67 String ns = Constants.NS_URI_ADDRESSING_DEFAULT;
68 TYPE_DESC.setXmlType(new QName(ns, "ServiceNameType"));
69 AttributeDesc attrField = new AttributeDesc();
70 attrField.setFieldName("port");
71 attrField.setXmlName(new QName("", "PortName"));
72 attrField.setXmlType(new QName("http://www.w3.org/2001/XMLSchema", "string"));
73 TYPE_DESC.addFieldDesc(attrField);
74 }
75
76
77
78
79
80
81
82 public static ServiceNameType fromElement(Element element) {
83 String value = TextExtractor.getText(element);
84 QName qname = XMLUtils.getQNameFromString(value, element);
85 String portName = element.getAttribute(Constants.PORT_NAME);
86 portName = portName == null || portName.length() == 0 ? null : portName;
87 return new ServiceNameType(qname, portName);
88 }
89
90
91
92
93
94
95
96 public static ServiceNameType fromSOAPElement(SOAPElement element) {
97 String value = TextExtractor.getText(element);
98 QName qname = TextExtractor.getQName(value, element);
99 String portName = element.getAttribute(Constants.PORT_NAME);
100 portName = portName == null || portName.length() == 0 ? null : portName;
101 return new ServiceNameType(qname, portName);
102 }
103
104
105
106
107
108
109
110
111
112 public static Deserializer getDeserializer(String mType, Class<?> jType, QName xType) {
113 return new SimpleDeserializer(jType, xType, TYPE_DESC);
114 }
115
116
117
118
119
120
121
122
123
124 public static Serializer getSerializer(String mType, Class<?> jType, QName xType) {
125 return new SimpleSerializer(jType, xType, TYPE_DESC);
126 }
127
128
129
130
131
132
133 public static TypeDesc getTypeDesc() {
134 return TYPE_DESC;
135 }
136
137
138
139
140 private String port;
141
142
143
144
145
146
147 public ServiceNameType(QName qname) {
148 super(qname);
149 }
150
151
152
153
154
155
156
157 public ServiceNameType(QName qname, String port) {
158 super(qname);
159 this.port = port;
160 }
161
162
163
164
165
166
167
168
169 public ServiceNameType(ServiceNameType serviceName) {
170 super(serviceName);
171 this.port = serviceName.getPort();
172 }
173
174
175
176
177
178
179
180 public ServiceNameType(String namespace, String localName) {
181 super(namespace, localName);
182 }
183
184
185
186
187 @Override
188 public void append(AddressingVersion version, Element parent, String elementName) {
189 Element sn = parent.getOwnerDocument().createElementNS(
190 version.getNamespace(), elementName);
191 String value = XMLUtils.getStringForQName(this, sn);
192 sn.appendChild(parent.getOwnerDocument().createTextNode(value));
193 if (this.getPort() != null) {
194 sn.setAttribute(Constants.PORT_NAME, this.getPort());
195 }
196 parent.appendChild(sn);
197 }
198
199
200
201
202 public void append(Element parent) {
203 append(parent, Constants.SERVICE_NAME);
204 }
205
206
207
208
209
210
211 public String getPort() {
212 return this.port;
213 }
214
215
216
217
218
219
220 public void setPort(String port) {
221 this.port = port;
222 }
223
224 }