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