1 7 package org.jboss.webservice.deployment; 8 9 11 import org.jboss.logging.Logger; 12 13 import javax.xml.namespace.QName ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.io.PrintWriter ; 18 19 25 public class OperationDescription 26 { 27 private final Logger log = Logger.getLogger(OperationDescription.class); 29 30 private String name; 32 private QName qname; 33 private QName returnQName; 34 private QName returnType; 35 private boolean oneWay; 36 37 private ArrayList parameters = new ArrayList (); 38 private ArrayList faults = new ArrayList (); 39 40 public OperationDescription(String name, QName qname) 41 { 42 if (name == null) 43 throw new IllegalArgumentException ("Operation name cannot be null"); 44 45 if (qname == null) 46 qname = new QName (name); 47 48 this.name = name; 49 this.qname = qname; 50 } 51 52 public String getJavaName() 53 { 54 return name; 55 } 56 57 public String getWsdlName() 58 { 59 return getQName().getLocalPart(); 60 } 61 62 public QName getQName() 63 { 64 return qname; 65 } 66 67 public QName getReturnQName() 68 { 69 return returnQName; 70 } 71 72 public QName getReturnType() 73 { 74 return returnType; 75 } 76 77 public void setReturnQName(QName returnQName) 78 { 79 this.returnQName = returnQName; 80 } 81 82 public void setReturnType(QName returnType) 83 { 84 this.returnType = returnType; 85 } 86 87 public boolean isOneWay() 88 { 89 return oneWay; 90 } 91 92 public void setOneWay(boolean oneWay) 93 { 94 this.oneWay = oneWay; 95 } 96 97 public Iterator getParameters() 98 { 99 return parameters.iterator(); 100 } 101 102 public void setParameters(List newList) 103 { 104 List oldList = parameters; 105 parameters = new ArrayList (); 106 107 Iterator itNew = newList.iterator(); 108 while (itNew.hasNext()) 109 { 110 Parameter param = (Parameter)itNew.next(); 111 log.debug("Reordering: " + param.getName()); 112 parameters.add(param); 113 oldList.remove(param); 114 } 115 116 Iterator itOld = oldList.iterator(); 117 while (itOld.hasNext()) 118 { 119 Parameter param = (Parameter)itOld.next(); 120 if (param.inHeader || param.outHeader) 121 { 122 log.debug("Appending header: " + param.getName()); 123 parameters.add(param); 124 } 125 else 126 { 127 throw new IllegalStateException ("Incomplete reorder list: " + param.getName()); 128 } 129 } 130 } 131 132 public void addParameter(Parameter param) 133 { 134 parameters.add(param); 135 } 136 137 public void addFault(Fault fault) 138 { 139 faults.add(fault); 140 } 141 142 public Parameter getParameterForName(String partName) 143 { 144 Parameter param = null; 145 Iterator it = parameters.iterator(); 146 while (param == null && it.hasNext()) 147 { 148 Parameter pa = (Parameter)it.next(); 149 if (pa.getName().equals(partName)) 150 param = pa; 151 } 152 return param; 153 } 154 155 public Iterator getFaults() 156 { 157 return faults.iterator(); 158 } 159 160 public void writeWSDD(PrintWriter out) 161 { 162 String name = getJavaName(); 163 QName qname = getQName(); 164 QName returnQName = getReturnQName(); 165 QName returnType = getReturnType(); 166 167 log.trace("Operation: " + this); 168 169 String xmlns = ""; 170 String opPrefix = qname.getPrefix(); 171 if (opPrefix.length() > 0) 172 { 173 xmlns = "xmlns:" + opPrefix + "='" + qname.getNamespaceURI() + "' "; 174 } 175 176 String qnameAttr = WSDDGenerator.getQNameAttrValue(qname); 177 178 if (returnType != null) 179 { 180 String returnAttr = WSDDGenerator.getQNameAttrValue(returnQName); 181 String typeAttr = WSDDGenerator.getQNameAttrValue(returnType); 182 183 String typePrefix = returnType.getPrefix(); 184 if (typePrefix.startsWith("ns") && xmlns.startsWith("xmlns:" + typePrefix) == false) 185 { 186 xmlns += "xmlns:" + typePrefix + "='" + returnType.getNamespaceURI() + "' "; 187 } 188 189 out.println(" <operation name='" + name + "' qname='" + qnameAttr + "' returnQName='" + returnAttr + "' returnType='" + typeAttr + "' " + xmlns + ">"); 190 } 191 else 192 { 193 String onewayStr = (oneWay ? "oneway='true' " : ""); 194 out.println(" <operation name='" + name + "' qname='" + qnameAttr + "' " + onewayStr + xmlns + ">"); 195 } 196 197 Iterator itParam = getParameters(); 198 while (itParam.hasNext()) 199 { 200 OperationDescription.Parameter param = (OperationDescription.Parameter)itParam.next(); 201 String paramName = param.getName(); 202 QName paramQName = param.getQName(); 203 String mode = param.getMode(); 204 boolean inHeader = param.isInHeader(); 205 boolean outHeader = param.isOutHeader(); 206 207 log.trace("Parameter: " + param); 208 209 QName typeQName = param.getType(); 210 211 String headers = ""; 212 if (inHeader) headers += "inHeader='true' "; 213 if (outHeader) headers += "outHeader='true' "; 214 215 xmlns = ""; 216 217 if (typeQName != null) 218 { 219 String typeAttr = WSDDGenerator.getQNameAttrValue(typeQName); 220 String typePrefix = typeQName.getPrefix(); 221 if (typePrefix.startsWith("ns")) 222 { 223 xmlns += "xmlns:" + typePrefix + "='" + typeQName.getNamespaceURI() + "' "; 224 } 225 226 qnameAttr = WSDDGenerator.getQNameAttrValue(paramQName); 227 out.println(" <parameter name='" + paramName + "' qname='" + qnameAttr + "' mode='" + mode + "' type='" + typeAttr + "' " + headers + xmlns + "/>"); 228 } 229 else 230 { 231 out.println(" <parameter name='" + paramName + "' mode='" + mode + "' " + headers + xmlns + "/>"); 232 } 233 } 234 235 Iterator itFault = getFaults(); 236 while (itFault.hasNext()) 237 { 238 OperationDescription.Fault fault = (OperationDescription.Fault)itFault.next(); 239 String faultName = fault.getName(); 240 String javaType = fault.getJavaType(); 241 242 log.trace("Fault: " + fault); 243 244 QName typeQName = fault.getTypeQName(); 245 QName faultQName = fault.getQName(); 246 247 String typeAttr = WSDDGenerator.getQNameAttrValue(typeQName); 248 249 xmlns = ""; 250 String typePrefix = typeQName.getPrefix(); 251 if (typePrefix.startsWith("ns")) 252 { 253 xmlns += "xmlns:" + typePrefix + "='" + typeQName.getNamespaceURI() + "' "; 254 } 255 256 qnameAttr = WSDDGenerator.getQNameAttrValue(faultQName); 257 out.println(" <fault name='" + faultName + "' qname='" + qnameAttr + "' type='" + typeAttr + "' class='" + javaType + "' " + xmlns + "/>"); 258 } 259 260 out.println(" </operation>"); 261 } 262 263 public boolean equals(Object obj) 264 { 265 if (obj == null) return false; 266 return toString().equals(obj.toString()); 267 } 268 269 public int hashCode() 270 { 271 return toString().hashCode(); 272 } 273 274 public String toString() 275 { 276 return "[name=" + name + ",qname=" + qname + ",returnQName=" + returnQName + ",returnType=" + returnType + "]"; 277 } 278 279 public static class Parameter 281 { 282 private String name; 283 private QName qname; 284 private String mode; 285 private QName type; 286 private boolean inHeader; 287 private boolean outHeader; 288 289 public Parameter(String name, QName qname, String mode, QName type) 290 { 291 if (name == null) 292 throw new IllegalArgumentException ("Parameter name cannot be null"); 293 if (mode == null) 294 throw new IllegalArgumentException ("Parameter mode cannot be null"); 295 if (type == null) 296 throw new IllegalArgumentException ("Parameter type cannot be null"); 297 298 if (qname == null) 299 qname = new QName (name); 300 301 this.name = name; 302 this.qname = qname; 303 this.mode = mode; 304 this.type = type; 305 } 306 307 public String getName() 308 { 309 return name; 310 } 311 312 public QName getQName() 313 { 314 return qname; 315 } 316 317 public QName getType() 318 { 319 return type; 320 } 321 322 public String getMode() 323 { 324 return mode; 325 } 326 327 public void setMode(String mode) 328 { 329 this.mode = mode; 330 } 331 332 public boolean isInHeader() 333 { 334 return inHeader; 335 } 336 337 public void setInHeader(boolean inHeader) 338 { 339 this.inHeader = inHeader; 340 } 341 342 public boolean isOutHeader() 343 { 344 return outHeader; 345 } 346 347 public void setOutHeader(boolean outHeader) 348 { 349 this.outHeader = outHeader; 350 } 351 352 public boolean equals(Object obj) 353 { 354 if (obj == null) return false; 355 return toString().equals(obj.toString()); 356 } 357 358 public int hashCode() 359 { 360 return toString().hashCode(); 361 } 362 363 public String toString() 364 { 365 return "[name=" + name + "qname=" + qname + ",mode=" + mode + ",type=" + type + "]"; 366 } 367 } 368 369 public static class Fault 371 { 372 private String name; 373 private QName qname; 374 private QName typeQName; 375 private String javaType; 376 377 public Fault(String name, QName qname, String javaType, QName type) 378 { 379 if (name == null) 380 throw new IllegalArgumentException ("Fault name cannot be null"); 381 if (javaType == null) 382 throw new IllegalArgumentException ("Fault javaType cannot be null"); 383 if (type == null) 384 throw new IllegalArgumentException ("Fault type cannot be null"); 385 386 if (qname == null) 387 qname = new QName (name); 388 389 this.name = name; 390 this.qname = qname; 391 this.javaType = javaType; 392 this.typeQName = type; 393 } 394 395 public String getName() 396 { 397 return name; 398 } 399 400 public QName getQName() 401 { 402 return qname; 403 } 404 405 public QName getTypeQName() 406 { 407 return typeQName; 408 } 409 410 public String getJavaType() 411 { 412 return javaType; 413 } 414 415 public boolean equals(Object obj) 416 { 417 if (obj == null) return false; 418 return toString().equals(obj.toString()); 419 } 420 421 public int hashCode() 422 { 423 return toString().hashCode(); 424 } 425 426 public String toString() 427 { 428 return "[name=" + name + "qname=" + qname + ",type=" + typeQName + ",java=" + javaType + "]"; 429 } 430 } 431 } | Popular Tags |