1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.Constants; 19 import org.apache.axis.utils.Messages; 20 import org.apache.axis.wsdl.symbolTable.BindingEntry; 21 import org.apache.axis.wsdl.symbolTable.FaultInfo; 22 import org.apache.axis.wsdl.symbolTable.Parameter; 23 import org.apache.axis.wsdl.symbolTable.Parameters; 24 import org.apache.axis.wsdl.symbolTable.SymbolTable; 25 26 import javax.wsdl.Binding; 27 import javax.wsdl.BindingInput; 28 import javax.wsdl.BindingOperation; 29 import javax.wsdl.BindingOutput; 30 import javax.wsdl.Operation; 31 import javax.wsdl.OperationType; 32 import javax.wsdl.extensions.UnknownExtensibilityElement; 33 import javax.wsdl.extensions.soap.SOAPBody; 34 import javax.wsdl.extensions.soap.SOAPOperation; 35 import javax.xml.namespace.QName ; 36 import java.io.IOException ; 37 import java.io.PrintWriter ; 38 import java.util.ArrayList ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 42 46 public class JavaSkelWriter extends JavaClassWriter { 47 48 49 private BindingEntry bEntry; 50 51 52 private Binding binding; 53 54 55 private SymbolTable symbolTable; 56 57 64 protected JavaSkelWriter(Emitter emitter, BindingEntry bEntry, 65 SymbolTable symbolTable) { 66 67 super(emitter, bEntry.getName() + "Skeleton", "skeleton"); 68 69 this.bEntry = bEntry; 70 this.binding = bEntry.getBinding(); 71 this.symbolTable = symbolTable; 72 } 74 79 protected String getImplementsText() { 80 81 return "implements " 82 + bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME) 83 + ", org.apache.axis.wsdl.Skeleton "; 84 } 86 92 protected void writeFileBody(PrintWriter pw) throws IOException { 93 94 String portTypeName = 95 (String ) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME); 96 String implType = portTypeName + " impl"; 97 98 pw.println(" private " + implType + ";"); 100 pw.println( 101 " private static java.util.Map _myOperations = new java.util.Hashtable();"); 102 pw.println( 103 " private static java.util.Collection _myOperationsList = new java.util.ArrayList();"); 104 pw.println(); 105 pw.println(" /**"); 106 pw.println( 107 " * Returns List of OperationDesc objects with this name"); 108 pw.println(" */"); 109 pw.println( 110 " public static java.util.List getOperationDescByName(java.lang.String methodName) {"); 111 pw.println( 112 " return (java.util.List)_myOperations.get(methodName);"); 113 pw.println(" }"); 114 pw.println(); 115 pw.println(" /**"); 116 pw.println(" * Returns Collection of OperationDescs"); 117 pw.println(" */"); 118 pw.println( 119 " public static java.util.Collection getOperationDescs() {"); 120 pw.println(" return _myOperationsList;"); 121 pw.println(" }"); 122 pw.println(); 123 124 pw.println(" static {"); 126 pw.println(" org.apache.axis.description.OperationDesc _oper;"); 127 pw.println(" org.apache.axis.description.FaultDesc _fault;"); 128 pw.println( 129 " org.apache.axis.description.ParameterDesc [] _params;"); 130 131 List operations = binding.getBindingOperations(); 132 133 for (int i = 0; i < operations.size(); ++i) { 134 BindingOperation bindingOper = (BindingOperation) operations.get(i); 135 Operation operation = bindingOper.getOperation(); 136 OperationType type = operation.getStyle(); 137 138 if ((OperationType.NOTIFICATION.equals(type)) 141 || (OperationType.SOLICIT_RESPONSE.equals(type))) { 142 continue; 143 } 144 145 Parameters parameters = 146 bEntry.getParameters(bindingOper.getOperation()); 147 148 if (parameters != null) { 149 150 String opName = bindingOper.getOperation().getName(); 152 String javaOpName = Utils.xmlNameToJava(opName); 153 154 pw.println( 155 " _params = new org.apache.axis.description.ParameterDesc [] {"); 156 157 for (int j = 0; j < parameters.list.size(); j++) { 158 Parameter p = (Parameter) parameters.list.get(j); 159 String modeStr; 160 161 switch (p.getMode()) { 162 163 case Parameter.IN: 164 modeStr = 165 "org.apache.axis.description.ParameterDesc.IN"; 166 break; 167 168 case Parameter.OUT: 169 modeStr = 170 "org.apache.axis.description.ParameterDesc.OUT"; 171 break; 172 173 case Parameter.INOUT: 174 modeStr = 175 "org.apache.axis.description.ParameterDesc.INOUT"; 176 break; 177 178 default : 179 throw new IOException ( 180 Messages.getMessage( 181 "badParmMode00", 182 (new Byte (p.getMode())).toString())); 183 } 184 185 QName paramName = p.getQName(); 187 QName paramType = Utils.getXSIType(p); 188 189 String inHeader = p.isInHeader() 191 ? "true" 192 : "false"; 193 String outHeader = p.isOutHeader() 194 ? "true" 195 : "false"; 196 197 pw.println( 198 " " 199 + "new org.apache.axis.description.ParameterDesc(" 200 + Utils.getNewQNameWithLastLocalPart(paramName) + ", " + modeStr + ", " 201 + Utils.getNewQName(paramType) + ", " 202 + Utils.getParameterTypeName(p) + ".class" + ", " 203 + inHeader + ", " + outHeader + "), "); 204 } 205 206 pw.println(" };"); 207 208 QName retName = null; 210 QName retType = null; 211 212 if (parameters.returnParam != null) { 213 retName = parameters.returnParam.getQName(); 214 retType = Utils.getXSIType(parameters.returnParam); 215 } 216 217 String returnStr; 218 219 if (retName != null) { 220 returnStr = Utils.getNewQNameWithLastLocalPart(retName); 221 } else { 222 returnStr = "null"; 223 } 224 225 pw.println( 226 " _oper = new org.apache.axis.description.OperationDesc(\"" 227 + javaOpName + "\", _params, " + returnStr + ");"); 228 229 if (retType != null) { 230 pw.println(" _oper.setReturnType(" 231 + Utils.getNewQName(retType) + ");"); 232 233 if ((parameters.returnParam != null) 234 && parameters.returnParam.isOutHeader()) { 235 pw.println(" _oper.setReturnHeader(true);"); 236 } 237 } 238 239 QName elementQName = Utils.getOperationQName(bindingOper, 243 bEntry, symbolTable); 244 245 if (elementQName != null) { 246 pw.println(" _oper.setElementQName(" 247 + Utils.getNewQName(elementQName) + ");"); 248 } 249 250 String action = Utils.getOperationSOAPAction(bindingOper); 252 if (action != null) { 253 pw.println(" _oper.setSoapAction(\"" + action + "\");"); 254 } 255 256 pw.println(" _myOperationsList.add(_oper);"); 257 pw.println(" if (_myOperations.get(\"" + javaOpName 258 + "\") == null) {"); 259 pw.println(" _myOperations.put(\"" + javaOpName 260 + "\", new java.util.ArrayList());"); 261 pw.println(" }"); 262 pw.println(" ((java.util.List)_myOperations.get(\"" 263 + javaOpName + "\")).add(_oper);"); 264 } 265 266 if (bEntry.getFaults() != null) { 268 ArrayList faults = 269 (ArrayList ) bEntry.getFaults().get(bindingOper); 270 271 if (faults != null) { 272 273 if (parameters == null) { 275 String opName = 276 bindingOper.getOperation().getName(); 277 String javaOpName = Utils.xmlNameToJava(opName); 278 279 pw.println( 280 " _oper = " 281 + "new org.apache.axis.description.OperationDesc();"); 282 pw.println(" _oper.setName(\"" + javaOpName 283 + "\");"); 284 } 285 286 Iterator it = faults.iterator(); 288 289 while (it.hasNext()) { 290 FaultInfo faultInfo = (FaultInfo) it.next(); 291 QName faultQName = faultInfo.getQName(); 292 QName faultXMLType = faultInfo.getXMLType(); 293 String faultName = faultInfo.getName(); 294 String className = 295 Utils.getFullExceptionName(faultInfo.getMessage(), 296 symbolTable); 297 298 pw.println( 299 " _fault = " 300 + "new org.apache.axis.description.FaultDesc();"); 301 302 if (faultName != null) { 303 pw.println(" _fault.setName(\"" + faultName 304 + "\");"); 305 } 306 307 if (faultQName != null) { 308 pw.println(" _fault.setQName(" 309 + Utils.getNewQName(faultQName) + ");"); 310 } 311 312 if (className != null) { 313 pw.println(" _fault.setClassName(\"" 314 + className + "\");"); 315 } 316 317 if (faultXMLType != null) { 318 pw.println(" _fault.setXmlType(" 319 + Utils.getNewQName(faultXMLType) 320 + ");"); 321 } 322 323 pw.println(" _oper.addFault(_fault);"); 324 } 325 } 326 } 327 } 328 329 pw.println(" }"); 330 pw.println(); 331 332 pw.println(" public " + className + "() {"); 334 335 String implementationClassName = emitter.getImplementationClassName(); 337 if ( implementationClassName == null) 338 implementationClassName = bEntry.getName() + "Impl"; 339 pw.println(" this.impl = new " + implementationClassName + "();"); 340 pw.println(" }"); 341 342 pw.println(); 343 pw.println(" public " + className + "(" + implType + ") {"); 344 pw.println(" this.impl = impl;"); 345 pw.println(" }"); 346 347 for (int i = 0; i < operations.size(); ++i) { 349 BindingOperation operation = (BindingOperation) operations.get(i); 350 Parameters parameters = 351 bEntry.getParameters(operation.getOperation()); 352 353 String soapAction = ""; 355 Iterator operationExtensibilityIterator = 356 operation.getExtensibilityElements().iterator(); 357 358 for (; operationExtensibilityIterator.hasNext();) { 359 Object obj = operationExtensibilityIterator.next(); 360 361 if (obj instanceof SOAPOperation) { 362 soapAction = ((SOAPOperation) obj).getSoapActionURI(); 363 364 break; 365 } else if (obj instanceof UnknownExtensibilityElement) { 366 367 UnknownExtensibilityElement unkElement = 369 (UnknownExtensibilityElement) obj; 370 QName name = 371 unkElement.getElementType(); 372 373 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 374 && name.getLocalPart().equals("operation")) { 375 if (unkElement.getElement().getAttribute("soapAction") 376 != null) { 377 soapAction = unkElement.getElement().getAttribute( 378 "soapAction"); 379 } 380 } 381 } 382 } 383 384 String namespace = ""; 387 Iterator bindingMsgIterator = null; 388 BindingInput input = operation.getBindingInput(); 389 BindingOutput output; 390 391 if (input != null) { 392 bindingMsgIterator = 393 input.getExtensibilityElements().iterator(); 394 } else { 395 output = operation.getBindingOutput(); 396 397 if (output != null) { 398 bindingMsgIterator = 399 output.getExtensibilityElements().iterator(); 400 } 401 } 402 403 if (bindingMsgIterator != null) { 404 for (; bindingMsgIterator.hasNext();) { 405 Object obj = bindingMsgIterator.next(); 406 407 if (obj instanceof SOAPBody) { 408 namespace = ((SOAPBody) obj).getNamespaceURI(); 409 410 if (namespace == null) { 411 namespace = 412 symbolTable.getDefinition().getTargetNamespace(); 413 } 414 415 if (namespace == null) { 416 namespace = ""; 417 } 418 419 break; 420 } else if (obj instanceof UnknownExtensibilityElement) { 421 422 UnknownExtensibilityElement unkElement = 424 (UnknownExtensibilityElement) obj; 425 QName name = 426 unkElement.getElementType(); 427 428 if (name.getNamespaceURI().equals( 429 Constants.URI_WSDL12_SOAP) 430 && name.getLocalPart().equals("body")) { 431 namespace = unkElement.getElement().getAttribute( 432 "namespace"); 433 434 if (namespace == null) { 435 namespace = 436 symbolTable.getDefinition().getTargetNamespace(); 437 } 438 439 if (namespace == null) { 440 namespace = ""; 441 } 442 443 break; 444 } 445 } 446 } 447 } 448 449 Operation ptOperation = operation.getOperation(); 450 OperationType type = ptOperation.getStyle(); 451 452 if ((OperationType.NOTIFICATION.equals(type)) 455 || (OperationType.SOLICIT_RESPONSE.equals(type))) { 456 pw.println(parameters.signature); 457 pw.println(); 458 } else { 459 writeOperation(pw, operation, parameters, soapAction, 460 namespace); 461 } 462 } 463 } 465 474 protected void writeOperation(PrintWriter pw, BindingOperation operation, 475 Parameters parms, String soapAction, 476 String namespace) { 477 478 writeComment(pw, operation.getDocumentationElement(), true); 479 480 pw.println(parms.signature); 483 pw.println(" {"); 484 485 if (parms.returnParam == null) { 489 pw.print(" "); 490 } else { 491 pw.print(" " + Utils.getParameterTypeName(parms.returnParam) 492 + " ret = "); 493 } 494 495 String call = "impl." + Utils.xmlNameToJava(operation.getName()) 496 + "("; 497 boolean needComma = false; 498 499 for (int i = 0; i < parms.list.size(); ++i) { 500 if (needComma) { 501 call = call + ", "; 502 } else { 503 needComma = true; 504 } 505 506 Parameter p = (Parameter) parms.list.get(i); 507 508 call = call + Utils.xmlNameToJava(p.getName()); 509 } 510 511 call = call + ")"; 512 513 pw.println(call + ";"); 514 515 if (parms.returnParam != null) { 516 pw.println(" return ret;"); 517 } 518 519 pw.println(" }"); 520 pw.println(); 521 } } | Popular Tags |