1 55 package org.jboss.axis.wsdl; 56 57 import org.jboss.axis.encoding.DefaultSOAPEncodingTypeMappingImpl; 58 import org.jboss.axis.encoding.DefaultTypeMappingImpl; 59 import org.jboss.axis.utils.CLArgsParser; 60 import org.jboss.axis.utils.CLOption; 61 import org.jboss.axis.utils.CLOptionDescriptor; 62 import org.jboss.axis.utils.CLUtil; 63 import org.jboss.axis.utils.Messages; 64 import org.jboss.axis.wsdl.fromJava.Emitter; 65 66 import java.util.HashMap ; 67 import java.util.List ; 68 69 75 76 public class Java2WSDL 77 { 78 protected static final int INHERITED_CLASS_OPT = 'a'; 80 protected static final int SOAPACTION_OPT = 'A'; 81 protected static final int BINDING_NAME_OPT = 'b'; 82 protected static final int STOP_CLASSES_OPT = 'c'; 83 protected static final int IMPORT_SCHEMA_OPT = 'C'; 84 protected static final int EXTRA_CLASSES_OPT = 'e'; 85 protected static final int HELP_OPT = 'h'; 86 protected static final int IMPL_CLASS_OPT = 'i'; 87 protected static final int INPUT_OPT = 'I'; 88 protected static final int LOCATION_OPT = 'l'; 89 protected static final int LOCATION_IMPORT_OPT = 'L'; 90 protected static final int METHODS_ALLOWED_OPT = 'm'; 91 protected static final int NAMESPACE_OPT = 'n'; 92 protected static final int NAMESPACE_IMPL_OPT = 'N'; 93 protected static final int OUTPUT_OPT = 'o'; 94 protected static final int OUTPUT_IMPL_OPT = 'O'; 95 protected static final int PACKAGE_OPT = 'p'; 96 protected static final int PORTTYPE_NAME_OPT = 'P'; 97 protected static final int SERVICE_PORT_NAME_OPT = 's'; 98 protected static final int SERVICE_ELEMENT_NAME_OPT = 'S'; 99 protected static final int TYPEMAPPING_OPT = 'T'; 100 protected static final int USE_OPT = 'u'; 101 protected static final int OUTPUT_WSDL_MODE_OPT = 'w'; 102 protected static final int METHODS_NOTALLOWED_OPT = 'x'; 103 protected static final int STYLE_OPT = 'y'; 104 105 114 protected CLOptionDescriptor[] options = new CLOptionDescriptor[]{ 115 new CLOptionDescriptor("help", 116 CLOptionDescriptor.ARGUMENT_DISALLOWED, 117 HELP_OPT, 118 Messages.getMessage("j2wopthelp00")), 119 new CLOptionDescriptor("input", 120 CLOptionDescriptor.ARGUMENT_REQUIRED, 121 INPUT_OPT, 122 Messages.getMessage("j2woptinput00")), 123 new CLOptionDescriptor("output", 124 CLOptionDescriptor.ARGUMENT_REQUIRED, 125 OUTPUT_OPT, 126 Messages.getMessage("j2woptoutput00")), 127 new CLOptionDescriptor("location", 128 CLOptionDescriptor.ARGUMENT_REQUIRED, 129 LOCATION_OPT, 130 Messages.getMessage("j2woptlocation00")), 131 new CLOptionDescriptor("portTypeName", 132 CLOptionDescriptor.ARGUMENT_REQUIRED, 133 PORTTYPE_NAME_OPT, 134 Messages.getMessage("j2woptportTypeName00")), 135 new CLOptionDescriptor("bindingName", 136 CLOptionDescriptor.ARGUMENT_REQUIRED, 137 BINDING_NAME_OPT, 138 Messages.getMessage("j2woptbindingName00")), 139 new CLOptionDescriptor("serviceElementName", 140 CLOptionDescriptor.ARGUMENT_REQUIRED, 141 SERVICE_ELEMENT_NAME_OPT, 142 Messages.getMessage("j2woptserviceElementName00")), 143 new CLOptionDescriptor("servicePortName", 144 CLOptionDescriptor.ARGUMENT_REQUIRED, 145 SERVICE_PORT_NAME_OPT, 146 Messages.getMessage("j2woptservicePortName00")), 147 new CLOptionDescriptor("namespace", 148 CLOptionDescriptor.ARGUMENT_REQUIRED, 149 NAMESPACE_OPT, 150 Messages.getMessage("j2woptnamespace00")), 151 new CLOptionDescriptor("PkgtoNS", 152 CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENTS_REQUIRED_2, 153 PACKAGE_OPT, 154 Messages.getMessage("j2woptPkgtoNS00")), 155 new CLOptionDescriptor("methods", 156 CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENT_REQUIRED, 157 METHODS_ALLOWED_OPT, 158 Messages.getMessage("j2woptmethods00")), 159 new CLOptionDescriptor("all", 160 CLOptionDescriptor.ARGUMENT_DISALLOWED, 161 INHERITED_CLASS_OPT, 162 Messages.getMessage("j2woptall00")), 163 new CLOptionDescriptor("outputWsdlMode", 164 CLOptionDescriptor.ARGUMENT_REQUIRED, 165 OUTPUT_WSDL_MODE_OPT, 166 Messages.getMessage("j2woptoutputWsdlMode00")), 167 new CLOptionDescriptor("locationImport", 168 CLOptionDescriptor.ARGUMENT_REQUIRED, 169 LOCATION_IMPORT_OPT, 170 Messages.getMessage("j2woptlocationImport00")), 171 new CLOptionDescriptor("namespaceImpl", 172 CLOptionDescriptor.ARGUMENT_REQUIRED, 173 NAMESPACE_IMPL_OPT, 174 Messages.getMessage("j2woptnamespaceImpl00")), 175 new CLOptionDescriptor("outputImpl", 176 CLOptionDescriptor.ARGUMENT_REQUIRED, 177 OUTPUT_IMPL_OPT, 178 Messages.getMessage("j2woptoutputImpl00")), 179 new CLOptionDescriptor("implClass", 180 CLOptionDescriptor.ARGUMENT_REQUIRED, 181 IMPL_CLASS_OPT, 182 Messages.getMessage("j2woptimplClass00")), 183 new CLOptionDescriptor("exclude", 184 CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENT_REQUIRED, 185 METHODS_NOTALLOWED_OPT, 186 Messages.getMessage("j2woptexclude00")), 187 new CLOptionDescriptor("stopClasses", 188 CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENT_REQUIRED, 189 STOP_CLASSES_OPT, 190 Messages.getMessage("j2woptstopClass00")), 191 new CLOptionDescriptor("typeMappingVersion", 192 CLOptionDescriptor.ARGUMENT_REQUIRED, 193 TYPEMAPPING_OPT, 194 Messages.getMessage("j2wopttypeMapping00")), 195 new CLOptionDescriptor("soapAction", 196 CLOptionDescriptor.ARGUMENT_REQUIRED, 197 SOAPACTION_OPT, 198 Messages.getMessage("j2woptsoapAction00")), 199 new CLOptionDescriptor("style", 200 CLOptionDescriptor.ARGUMENT_REQUIRED, 201 STYLE_OPT, 202 Messages.getMessage("j2woptStyle00")), 203 new CLOptionDescriptor("use", 204 CLOptionDescriptor.ARGUMENT_REQUIRED, 205 USE_OPT, 206 Messages.getMessage("j2woptUse00")), 207 new CLOptionDescriptor("extraClasses", 208 CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENT_REQUIRED, 209 EXTRA_CLASSES_OPT, 210 Messages.getMessage("j2woptExtraClasses00")), 211 new CLOptionDescriptor("importSchema", 212 CLOptionDescriptor.ARGUMENT_OPTIONAL, 213 IMPORT_SCHEMA_OPT, 214 Messages.getMessage("j2woptImportSchema00")) 215 }; 216 217 protected Emitter emitter; 218 protected String className = null; 219 protected String wsdlFilename = null; 220 protected String wsdlImplFilename = null; 221 protected HashMap namespaceMap = new HashMap (); 222 protected int mode = Emitter.MODE_ALL; 223 boolean locationSet = false; 224 225 228 protected Java2WSDL() 229 { 230 emitter = createEmitter(); 231 } 233 234 237 protected Emitter createEmitter() 238 { 239 return new Emitter(); 240 } 242 249 protected void addOptions(CLOptionDescriptor[] newOptions) 250 { 251 if (newOptions != null && newOptions.length > 0) 252 { 253 CLOptionDescriptor[] allOptions = new CLOptionDescriptor[ 254 options.length + newOptions.length]; 255 System.arraycopy(options, 0, allOptions, 0, options.length); 256 System.arraycopy(newOptions, 0, allOptions, options.length, newOptions.length); 257 options = allOptions; 258 } 259 } 260 261 266 protected boolean parseOption(CLOption option) 267 { 268 String value; 269 boolean status = true; 270 271 switch (option.getId()) 272 { 273 case CLOption.TEXT_ARGUMENT: 274 if (className != null) 275 { 276 System.out.println(Messages.getMessage("j2wDuplicateClass00", 277 className, 278 option.getArgument())); 279 printUsage(); 280 status = false; } 282 className = option.getArgument(); 283 break; 284 285 case METHODS_ALLOWED_OPT: 286 emitter.setAllowedMethods(option.getArgument()); 287 break; 288 289 case INHERITED_CLASS_OPT: 290 emitter.setUseInheritedMethods(true); 291 break; 292 293 case IMPL_CLASS_OPT: 294 emitter.setImplCls(option.getArgument()); 295 break; 296 297 case HELP_OPT: 298 printUsage(); 299 status = false; 300 break; 301 302 case OUTPUT_WSDL_MODE_OPT: 303 String modeArg = option.getArgument(); 304 if ("All".equalsIgnoreCase(modeArg)) 305 mode = Emitter.MODE_ALL; 306 else if ("Interface".equalsIgnoreCase(modeArg)) 307 mode = Emitter.MODE_INTERFACE; 308 else if ("Implementation".equalsIgnoreCase(modeArg)) 309 mode = Emitter.MODE_IMPLEMENTATION; 310 else 311 { 312 mode = Emitter.MODE_ALL; 313 System.err.println(Messages.getMessage("j2wmodeerror", modeArg)); 314 } 315 break; 316 317 case OUTPUT_OPT: 318 wsdlFilename = option.getArgument(); 319 break; 320 321 case INPUT_OPT: 322 emitter.setInputWSDL(option.getArgument()); 323 break; 324 325 case OUTPUT_IMPL_OPT: 326 wsdlImplFilename = option.getArgument(); 327 break; 328 329 case PACKAGE_OPT: 330 String packageName = option.getArgument(0); 331 String namespace = option.getArgument(1); 332 namespaceMap.put(packageName, namespace); 333 break; 334 335 case NAMESPACE_OPT: 336 emitter.setIntfNamespace(option.getArgument()); 337 break; 338 339 case NAMESPACE_IMPL_OPT: 340 emitter.setImplNamespace(option.getArgument()); 341 break; 342 343 case SERVICE_ELEMENT_NAME_OPT: 344 emitter.setServiceElementName(option.getArgument()); 345 break; 346 347 case SERVICE_PORT_NAME_OPT: 348 emitter.setServicePortName(option.getArgument()); 349 break; 350 351 case LOCATION_OPT: 352 emitter.setLocationUrl(option.getArgument()); 353 locationSet = true; 354 break; 355 356 case LOCATION_IMPORT_OPT: 357 emitter.setImportUrl(option.getArgument()); 358 break; 359 360 case METHODS_NOTALLOWED_OPT: 361 emitter.setDisallowedMethods(option.getArgument()); 362 break; 363 364 case PORTTYPE_NAME_OPT: 365 emitter.setPortTypeName(option.getArgument()); 366 break; 367 368 case BINDING_NAME_OPT: 369 emitter.setBindingName(option.getArgument()); 370 break; 371 372 case STOP_CLASSES_OPT: 373 emitter.setStopClasses(option.getArgument()); 374 break; 375 376 case TYPEMAPPING_OPT: 377 value = option.getArgument(); 378 if (value.equals("1.1")) 379 { 380 emitter.setDefaultTypeMapping(DefaultTypeMappingImpl.getSingleton()); 381 } 382 else if (value.equals("1.2")) 383 { 384 emitter.setDefaultTypeMapping(DefaultSOAPEncodingTypeMappingImpl.create()); 385 } 386 else 387 { 388 System.out.println(Messages.getMessage("j2wBadTypeMapping00")); 389 status = false; 390 } 391 break; 392 393 case SOAPACTION_OPT: 394 value = option.getArgument(); 395 if (value.equalsIgnoreCase("DEFAULT")) 396 { 397 emitter.setSoapAction("DEFAULT"); 398 } 399 else if (value.equalsIgnoreCase("OPERATION")) 400 { 401 emitter.setSoapAction("OPERATION"); 402 } 403 else if (value.equalsIgnoreCase("NONE")) 404 { 405 emitter.setSoapAction("NONE"); 406 } 407 else 408 { 409 System.out.println(Messages.getMessage("j2wBadSoapAction00")); 410 status = false; 411 } 412 break; 413 414 case STYLE_OPT: 415 value = option.getArgument(); 416 if (value.equalsIgnoreCase("DOCUMENT") || 417 value.equalsIgnoreCase("RPC") || 418 value.equalsIgnoreCase("WRAPPED")) 419 { 420 emitter.setStyle(value); 421 } 422 else 423 { 424 System.out.println(Messages.getMessage("j2woptBadStyle00")); 425 status = false; 426 } 427 break; 428 case USE_OPT: 429 value = option.getArgument(); 430 if (value.equalsIgnoreCase("LITERAL") || 431 value.equalsIgnoreCase("ENCODED")) 432 { 433 emitter.setUse(value); 434 } 435 else 436 { 437 System.out.println(Messages.getMessage("j2woptBadUse00")); 438 status = false; 439 } 440 break; 441 case EXTRA_CLASSES_OPT: 442 try 443 { 444 emitter.setExtraClasses(option.getArgument()); 445 } 446 catch (ClassNotFoundException e) 447 { 448 System.out.println(Messages.getMessage("j2woptBadClass00", e.toString())); 449 status = false; 450 } 451 break; 452 453 case IMPORT_SCHEMA_OPT: 454 emitter.setInputSchema(option.getArgument()); 455 break; 456 457 default: 458 break; 459 } 460 return status; 461 } 462 463 468 protected boolean validateOptions() 469 { 470 if ((className == null)) 472 { 473 System.out.println(Messages.getMessage("j2wMissingClass00")); 474 printUsage(); 475 return false; 476 } 477 478 if (!locationSet && (mode == Emitter.MODE_ALL || 479 mode == Emitter.MODE_IMPLEMENTATION)) 480 { 481 System.out.println(Messages.getMessage("j2wMissingLocation00")); 482 printUsage(); 483 return false; 484 } 485 486 if (emitter.getDefaultTypeMapping() == null) 488 { 489 emitter.setDefaultTypeMapping(DefaultTypeMappingImpl.getSingleton()); 490 } 491 492 return true; } 494 495 501 protected int run(String [] args) 502 { 503 CLArgsParser argsParser = new CLArgsParser(args, options); 505 506 if (null != argsParser.getErrorString()) 508 { 509 System.err.println(Messages.getMessage("j2werror00", argsParser.getErrorString())); 510 printUsage(); 511 return (1); 512 } 513 514 List clOptions = argsParser.getArguments(); 516 int size = clOptions.size(); 517 518 try 519 { 520 for (int i = 0; i < size; i++) 522 { 523 if (parseOption((CLOption)clOptions.get(i)) == false) 524 { 525 return (1); 526 } 527 } 528 529 if (validateOptions() == false) 531 return (1); 532 533 if (!namespaceMap.isEmpty()) 535 { 536 emitter.setNamespaceMap(namespaceMap); 537 } 538 539 emitter.setCls(className); 541 542 if (wsdlImplFilename == null) 544 { 545 emitter.emit(wsdlFilename, mode); 546 } 547 else 548 { 549 emitter.emit(wsdlFilename, wsdlImplFilename); 550 } 551 552 return (0); 554 } 555 catch (Throwable t) 556 { 557 t.printStackTrace(); 558 return (1); 559 } 560 } 562 566 protected void printUsage() 567 { 568 String lSep = System.getProperty("line.separator"); 569 StringBuffer msg = new StringBuffer (); 570 msg.append("Java2WSDL " 571 + Messages.getMessage("j2wemitter00")).append(lSep); 572 msg.append(Messages.getMessage("j2wusage00", 573 "java " + getClass().getName() + " [options] class-of-portType")).append(lSep); 574 msg.append(Messages.getMessage("j2woptions00")).append(lSep); 575 msg.append(CLUtil.describeOptions(options).toString()); 576 msg.append(Messages.getMessage("j2wdetails00")).append(lSep); 577 System.out.println(msg.toString()); 578 } 579 580 586 public static void main(String args[]) 587 { 588 Java2WSDL java2wsdl = new Java2WSDL(); 589 System.exit(java2wsdl.run(args)); 590 } 591 } 592 | Popular Tags |