1 55 package org.jboss.axis.wsdl.toJava; 56 57 import org.jboss.axis.Constants; 58 import org.jboss.axis.deployment.wsdd.WSDDConstants; 59 import org.jboss.axis.enums.Scope; 60 import org.jboss.axis.enums.Style; 61 import org.jboss.axis.enums.Use; 62 import org.jboss.axis.utils.JavaUtils; 63 import org.jboss.axis.utils.Messages; 64 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 65 import org.jboss.axis.wsdl.symbolTable.CollectionTE; 66 import org.jboss.axis.wsdl.symbolTable.Element; 67 import org.jboss.axis.wsdl.symbolTable.FaultInfo; 68 import org.jboss.axis.wsdl.symbolTable.Parameter; 69 import org.jboss.axis.wsdl.symbolTable.Parameters; 70 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 71 import org.jboss.axis.wsdl.symbolTable.TypeEntry; 72 73 import javax.wsdl.Binding; 74 import javax.wsdl.BindingOperation; 75 import javax.wsdl.Definition; 76 import javax.wsdl.Operation; 77 import javax.wsdl.OperationType; 78 import javax.wsdl.Port; 79 import javax.wsdl.Service; 80 import javax.wsdl.extensions.UnknownExtensibilityElement; 81 import javax.wsdl.extensions.soap.SOAPBinding; 82 import javax.xml.namespace.QName ; 83 import java.io.File ; 84 import java.io.FileOutputStream ; 85 import java.io.IOException ; 86 import java.io.OutputStreamWriter ; 87 import java.io.PrintWriter ; 88 import java.util.ArrayList ; 89 import java.util.HashSet ; 90 import java.util.Iterator ; 91 import java.util.Map ; 92 import java.util.Vector ; 93 94 97 public class JavaDeployWriter extends JavaWriter 98 { 99 protected Definition definition; 100 protected SymbolTable symbolTable; 101 102 105 public JavaDeployWriter(Emitter emitter, 106 Definition definition, 107 SymbolTable symbolTable) 108 { 109 super(emitter, "deploy"); 110 this.definition = definition; 111 this.symbolTable = symbolTable; 112 } 114 118 public void generate() throws IOException 119 { 120 if (emitter.isServerSide()) 121 { 122 super.generate(); 123 } 124 } 126 130 protected String getFileName() 131 { 132 String dir = emitter.getNamespaces().getAsDir(definition.getTargetNamespace()); 133 return dir + "deploy.wsdd"; 134 } 136 139 protected void writeFileHeader(PrintWriter pw) throws IOException 140 { 141 pw.println(Messages.getMessage("deploy00")); 142 pw.println(Messages.getMessage("deploy02")); 143 pw.println(Messages.getMessage("deploy03")); 144 pw.println(Messages.getMessage("deploy05")); 145 pw.println(Messages.getMessage("deploy06")); 146 pw.println(Messages.getMessage("deploy07")); 147 pw.println(Messages.getMessage("deploy09")); 148 pw.println(); 149 pw.println("<deployment"); 150 pw.println(" xmlns=\"" + WSDDConstants.URI_WSDD + "\""); 151 pw.println(" xmlns:" + WSDDConstants.NS_PREFIX_WSDD_JAVA + "=\"" + 152 WSDDConstants.URI_WSDD_JAVA + "\">"); 153 } 155 158 protected void writeFileBody(PrintWriter pw) throws IOException 159 { 160 writeDeployServices(pw); 161 pw.println("</deployment>"); 162 } 164 167 protected void writeDeployServices(PrintWriter pw) throws IOException 168 { 169 Map serviceMap = definition.getServices(); 171 for (Iterator mapIterator = serviceMap.values().iterator(); 172 mapIterator.hasNext();) 173 { 174 Service myService = (Service)mapIterator.next(); 175 176 pw.println(); 177 pw.println(" <!-- " + Messages.getMessage("wsdlService00", myService.getQName().getLocalPart()) 178 + " -->"); 179 pw.println(); 180 181 for (Iterator portIterator = myService.getPorts().values().iterator(); 182 portIterator.hasNext();) 183 { 184 Port myPort = (Port)portIterator.next(); 185 BindingEntry bEntry = 186 symbolTable.getBindingEntry(myPort.getBinding().getQName()); 187 188 if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) 190 { 191 continue; 192 } 193 writeDeployPort(pw, myPort, myService, bEntry); 194 } 195 } 196 } 198 201 protected void writeDeployTypes(PrintWriter pw, 202 Binding binding, 203 boolean hasLiteral, 204 boolean hasMIME, 205 Use use) throws IOException 206 { 207 Vector types = symbolTable.getTypes(); 208 209 pw.println(); 210 211 if (hasMIME) 212 { 213 QName bQName = binding.getQName(); 214 writeTypeMapping(pw, bQName.getNamespaceURI(), "DataHandler", 215 "javax.activation.DataHandler", 216 "org.jboss.axis.encoding.ser.JAFDataHandlerSerializerFactory", 217 "org.jboss.axis.encoding.ser.JAFDataHandlerDeserializerFactory", 218 use.getEncoding()); 219 } 220 221 for (int i = 0; i < types.size(); ++i) 222 { 223 TypeEntry type = (TypeEntry)types.elementAt(i); 224 225 boolean process = true; 227 228 if ((type.getBaseType() != null && type.getRefType() == null) || 236 type instanceof CollectionTE || 237 type instanceof Element || 238 !type.isReferenced() || 239 type.isOnlyLiteralReferenced()) 240 { 241 process = false; 242 } 243 244 if (process) 245 { 246 String namespaceURI = type.getQName().getNamespaceURI(); 247 String localPart = type.getQName().getLocalPart(); 248 String javaType = type.getName(); 249 String serializerFactory; 250 String deserializerFactory; 251 String encodingStyle = ""; 252 if (!hasLiteral) 253 { 254 encodingStyle = use.getEncoding(); 255 } 256 257 if (javaType.endsWith("[]")) 258 { 259 serializerFactory = "org.jboss.axis.encoding.ser.ArraySerializerFactory"; 260 deserializerFactory = "org.jboss.axis.encoding.ser.ArrayDeserializerFactory"; 261 } 262 else if (type.getNode() != null && 263 Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null) 264 { 265 serializerFactory = "org.jboss.axis.encoding.ser.EnumSerializerFactory"; 266 deserializerFactory = "org.jboss.axis.encoding.ser.EnumDeserializerFactory"; 267 } 268 else if (type.isSimpleType()) 269 { 270 serializerFactory = "org.jboss.axis.encoding.ser.SimpleSerializerFactory"; 271 deserializerFactory = "org.jboss.axis.encoding.ser.SimpleDeserializerFactory"; 272 } 273 else if (type.getBaseType() != null) 274 { 275 serializerFactory = "org.jboss.axis.encoding.ser.SimpleSerializerFactory"; 276 deserializerFactory = "org.jboss.axis.encoding.ser.SimpleDeserializerFactory"; 277 } 278 else 279 { 280 serializerFactory = "org.jboss.axis.encoding.ser.BeanSerializerFactory"; 281 deserializerFactory = "org.jboss.axis.encoding.ser.BeanDeserializerFactory"; 282 } 283 writeTypeMapping(pw, namespaceURI, localPart, javaType, serializerFactory, 284 deserializerFactory, encodingStyle); 285 } 286 } 287 } 289 292 protected void writeTypeMapping(PrintWriter pw, String namespaceURI, String localPart, String javaType, 293 String serializerFactory, String deserializerFactory, 294 String encodingStyle) throws IOException 295 { 296 pw.println(" <typeMapping"); 297 pw.println(" xmlns:ns=\"" + namespaceURI + "\""); 298 pw.println(" qname=\"ns:" + localPart + '"'); 299 pw.println(" type=\"java:" + javaType + '"'); 300 pw.println(" serializer=\"" + serializerFactory + "\""); 301 pw.println(" deserializer=\"" + deserializerFactory + "\""); 302 pw.println(" encodingStyle=\"" + encodingStyle + "\""); 303 pw.println(" />"); 304 } 305 306 309 protected void writeDeployPort(PrintWriter pw, 310 Port port, 311 Service service, 312 BindingEntry bEntry) throws IOException 313 { 314 String serviceName = port.getName(); 315 316 boolean hasLiteral = bEntry.hasLiteral(); 317 boolean hasMIME = Utils.hasMIME(bEntry); 318 319 String prefix = WSDDConstants.NS_PREFIX_WSDD_JAVA; 320 String styleStr = ""; 321 Use use = Use.DEFAULT; 322 323 324 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator(); 325 while (iterator.hasNext()) 326 { 327 Object obj = iterator.next(); 328 if (obj instanceof SOAPBinding) 329 { 330 use = Use.ENCODED; 331 } 332 else if (obj instanceof UnknownExtensibilityElement) 333 { 334 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)obj; 336 QName name = unkElement.getElementType(); 337 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 338 name.getLocalPart().equals("binding")) 339 { 340 use = Use.ENCODED; 341 } 342 } 343 } 344 345 if (symbolTable.isWrapped()) 346 { 347 styleStr = " style=\"" + Style.WRAPPED + "\""; 348 use = Use.LITERAL; 349 } 350 else 351 { 352 styleStr = " style=\"" + 353 bEntry.getBindingStyle().getName() + "\""; 354 if (hasLiteral) 355 { 356 use = Use.LITERAL; 357 } 358 } 359 360 String useStr = " use=\"" + use + "\""; 361 362 pw.println(" <service name=\"" + serviceName 363 + "\" provider=\"" + prefix + ":RPC" 364 + "\"" + styleStr + useStr + ">"); 365 366 pw.println(" <parameter name=\"wsdlTargetNamespace\" value=\"" 367 + service.getQName().getNamespaceURI() + "\"/>"); 368 pw.println(" <parameter name=\"wsdlServiceElement\" value=\"" 369 + service.getQName().getLocalPart() + "\"/>"); 370 pw.println(" <parameter name=\"wsdlServicePort\" value=\"" 371 + serviceName + "\"/>"); 372 373 if (hasMIME) 375 { 376 pw.println(" <parameter name=\"sendMultiRefs\" value=\"false\"/>"); 377 } 378 379 writeDeployBinding(pw, bEntry); 380 writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use); 381 382 pw.println(" </service>"); 383 } 385 388 protected void writeDeployBinding(PrintWriter pw, 389 BindingEntry bEntry) throws IOException 390 { 391 Binding binding = bEntry.getBinding(); 392 String className = bEntry.getName(); 393 if (emitter.isSkeletonWanted()) 394 className += "Skeleton"; 395 else 396 className += "Impl"; 397 398 pw.println(" <parameter name=\"className\" value=\"" 399 + className + "\"/>"); 400 401 pw.println(" <parameter name=\"wsdlPortType\" value=\"" 402 + binding.getPortType().getQName().getLocalPart() + "\"/>"); 403 404 405 HashSet allowedMethods = new HashSet (); 406 if (!emitter.isSkeletonWanted()) 407 { 408 Iterator operationsIterator = binding.getBindingOperations().iterator(); 409 for (; operationsIterator.hasNext();) 410 { 411 BindingOperation bindingOper = (BindingOperation)operationsIterator.next(); 412 Operation operation = bindingOper.getOperation(); 413 OperationType type = operation.getStyle(); 414 String javaOperName = JavaUtils.xmlNameToJava(operation.getName()); 415 416 if (type == OperationType.NOTIFICATION 419 || type == OperationType.SOLICIT_RESPONSE) 420 { 421 continue; 422 } 423 424 allowedMethods.add(javaOperName); 425 426 Parameters params = 429 symbolTable.getOperationParameters(operation, "", bEntry); 430 if (params != null) 431 { 432 433 QName elementQName = 435 Utils.getOperationQName(bindingOper, bEntry, symbolTable); 436 437 QName returnQName = null; 439 QName returnType = null; 440 if (params.returnParam != null) 441 { 442 returnQName = params.returnParam.getQName(); 443 returnType = Utils.getXSIType(params.returnParam); 444 } 445 446 Map faultMap = bEntry.getFaults(); 448 ArrayList faults = null; 449 if (faultMap != null) 450 { 451 faults = (ArrayList )faultMap.get(bindingOper); 452 } 453 writeOperation(pw, javaOperName, elementQName, 455 returnQName, returnType, 456 params, binding.getQName(), faults); 457 } 458 } 459 } 460 461 pw.print(" <parameter name=\"allowedMethods\" value=\""); 462 if (allowedMethods.isEmpty()) 463 { 464 pw.println("*\"/>"); 465 } 466 else 467 { 468 boolean first = true; 469 for (Iterator i = allowedMethods.iterator(); i.hasNext();) 470 { 471 String method = (String )i.next(); 472 if (first) 473 { 474 pw.print(method); 475 first = false; 476 } 477 else 478 { 479 pw.print(" " + method); 480 } 481 } 482 pw.println("\"/>"); 483 } 484 485 Scope scope = emitter.getScope(); 486 if (scope != null) 487 pw.println(" <parameter name=\"scope\" value=\"" + scope.getName() + "\"/>"); 488 } 490 493 protected void writeOperation(PrintWriter pw, 494 String javaOperName, 495 QName elementQName, 496 QName returnQName, 497 QName returnType, 498 Parameters params, 499 QName bindingQName, 500 ArrayList faults) 501 { 502 pw.print(" <operation name=\"" + javaOperName + "\""); 503 if (elementQName != null) 504 { 505 pw.print(" qname=\"" + 506 Utils.genQNameAttributeString(elementQName, "operNS") + 507 "\""); 508 } 509 if (returnQName != null) 510 { 511 pw.print(" returnQName=\"" + 512 Utils.genQNameAttributeString(returnQName, "retNS") + 513 "\""); 514 } 515 if (returnType != null) 516 { 517 pw.print(" returnType=\"" + 518 Utils.genQNameAttributeString(returnType, "rtns") + 519 "\""); 520 } 521 if (params.returnParam != null && params.returnParam.isOutHeader()) 522 { 523 pw.print(" returnHeader=\"true\""); 524 } 525 pw.println(" >"); 526 527 Vector paramList = params.list; 528 for (int i = 0; i < paramList.size(); i++) 529 { 530 Parameter param = (Parameter)paramList.elementAt(i); 531 532 QName paramQName = param.getQName(); 534 QName paramType = Utils.getXSIType(param); 535 536 pw.print(" <parameter"); 537 if (paramQName == null || "".equals(paramQName.getNamespaceURI())) 538 { 539 pw.print(" name=\"" + param.getName() + "\""); 540 } 541 else 542 { 543 pw.print(" qname=\"" + 544 Utils.genQNameAttributeString(paramQName, 545 "pns") + "\""); 546 } 547 548 pw.print(" type=\"" + 549 Utils.genQNameAttributeString(paramType, 550 "tns") + "\""); 551 if (param.getMode() != Parameter.IN) 553 { 554 pw.print(" mode=\"" + getModeString(param.getMode()) + "\""); 555 } 556 557 if (param.isInHeader()) 559 { 560 pw.print(" inHeader=\"true\""); 561 } 562 if (param.isOutHeader()) 563 { 564 pw.print(" outHeader=\"true\""); 565 } 566 567 pw.println("/>"); 568 } 569 if (faults != null) 570 { 571 for (Iterator iterator = faults.iterator(); iterator.hasNext();) 572 { 573 FaultInfo faultInfo = (FaultInfo)iterator.next(); 574 QName faultQName = faultInfo.getQName(); 575 if (faultQName != null) 576 { 577 String className = Utils.getFullExceptionName(faultInfo.getMessage(), symbolTable); 578 pw.print(" <fault"); 579 pw.print(" name=\"" + faultInfo.getName() + "\""); 580 pw.print(" qname=\"" + 581 Utils.genQNameAttributeString(faultQName, "fns") + "\""); 582 pw.print(" class=\"" + className + "\""); 583 pw.print(" type=\"" + 584 Utils.genQNameAttributeString(faultInfo.getXMLType(), "tns") + "\""); 585 pw.println("/>"); 586 } 587 } 588 } 589 590 pw.println(" </operation>"); 591 } 592 593 public String getModeString(byte mode) 594 { 595 if (mode == Parameter.IN) 596 { 597 return "IN"; 598 } 599 else if (mode == Parameter.INOUT) 600 { 601 return "INOUT"; 602 } 603 else 604 { 605 return "OUT"; 606 } 607 } 608 609 protected PrintWriter getPrintWriter(String filename) throws IOException 610 { 611 File file = new File (filename); 612 File parent = new File (file.getParent()); 613 parent.mkdirs(); 614 FileOutputStream out = new FileOutputStream (file); 615 OutputStreamWriter writer = new OutputStreamWriter (out, "UTF-8"); 616 return new PrintWriter (writer); 617 } 618 } | Popular Tags |