1 16 package org.apache.axis.wsdl; 17 18 import org.apache.axis.constants.Scope; 19 import org.apache.axis.utils.CLOption; 20 import org.apache.axis.utils.CLOptionDescriptor; 21 import org.apache.axis.utils.ClassUtils; 22 import org.apache.axis.utils.JavaUtils; 23 import org.apache.axis.utils.Messages; 24 import org.apache.axis.wsdl.gen.Parser; 25 import org.apache.axis.wsdl.gen.WSDL2; 26 import org.apache.axis.wsdl.toJava.Emitter; 27 import org.apache.axis.wsdl.toJava.NamespaceSelector; 28 29 32 public class WSDL2Java extends WSDL2 { 33 34 36 37 protected static final int SERVER_OPT = 's'; 38 39 40 protected static final int SKELETON_DEPLOY_OPT = 'S'; 41 42 43 protected static final int NAMESPACE_OPT = 'N'; 44 45 46 protected static final int NAMESPACE_FILE_OPT = 'f'; 47 48 49 protected static final int OUTPUT_OPT = 'o'; 50 51 52 protected static final int SCOPE_OPT = 'd'; 53 54 55 protected static final int TEST_OPT = 't'; 56 57 protected static final int BUILDFILE_OPT = 'B'; 58 59 protected static final int PACKAGE_OPT = 'p'; 60 61 62 protected static final int ALL_OPT = 'a'; 63 64 65 protected static final int TYPEMAPPING_OPT = 'T'; 66 67 68 protected static final int FACTORY_CLASS_OPT = 'F'; 69 70 71 protected static final int HELPER_CLASS_OPT = 'H'; 72 73 74 protected static final int USERNAME_OPT = 'U'; 75 76 77 protected static final int PASSWORD_OPT = 'P'; 78 79 protected static final int CLASSPATH_OPT = 'X'; 80 81 82 protected boolean bPackageOpt = false; 83 84 85 protected static final int NS_INCLUDE_OPT = 'i'; 86 87 88 protected static final int NS_EXCLUDE_OPT = 'x'; 89 90 91 protected static final int IMPL_CLASS_OPT = 'c'; 92 93 94 protected static final int ALLOW_INVALID_URL_OPT = 'u'; 95 96 97 protected static final int WRAP_ARRAYS_OPT = 'w'; 98 99 100 private Emitter emitter; 101 102 111 112 protected static final CLOptionDescriptor[] options = 113 new CLOptionDescriptor[]{ 114 new CLOptionDescriptor("server-side", 115 CLOptionDescriptor.ARGUMENT_DISALLOWED, 116 SERVER_OPT, Messages.getMessage("optionSkel00")), 117 new CLOptionDescriptor("skeletonDeploy", 118 CLOptionDescriptor.ARGUMENT_REQUIRED, 119 SKELETON_DEPLOY_OPT, 120 Messages.getMessage("optionSkeletonDeploy00")), 121 new CLOptionDescriptor("NStoPkg", 122 CLOptionDescriptor.DUPLICATES_ALLOWED 123 + CLOptionDescriptor.ARGUMENTS_REQUIRED_2, 124 NAMESPACE_OPT, 125 Messages.getMessage("optionNStoPkg00")), 126 new CLOptionDescriptor("fileNStoPkg", 127 CLOptionDescriptor.ARGUMENT_REQUIRED, 128 NAMESPACE_FILE_OPT, 129 Messages.getMessage("optionFileNStoPkg00")), 130 new CLOptionDescriptor("package", CLOptionDescriptor.ARGUMENT_REQUIRED, 131 PACKAGE_OPT, 132 Messages.getMessage("optionPackage00")), 133 new CLOptionDescriptor("output", CLOptionDescriptor.ARGUMENT_REQUIRED, 134 OUTPUT_OPT, 135 Messages.getMessage("optionOutput00")), 136 new CLOptionDescriptor("deployScope", 137 CLOptionDescriptor.ARGUMENT_REQUIRED, SCOPE_OPT, 138 Messages.getMessage("optionScope00")), 139 new CLOptionDescriptor("testCase", 140 CLOptionDescriptor.ARGUMENT_DISALLOWED, 141 TEST_OPT, Messages.getMessage("optionTest00")), 142 new CLOptionDescriptor("all", CLOptionDescriptor.ARGUMENT_DISALLOWED, 143 ALL_OPT, Messages.getMessage("optionAll00")), 144 new CLOptionDescriptor("typeMappingVersion", 145 CLOptionDescriptor.ARGUMENT_REQUIRED, 146 TYPEMAPPING_OPT, 147 Messages.getMessage("optionTypeMapping00")), 148 new CLOptionDescriptor("factory", CLOptionDescriptor.ARGUMENT_REQUIRED, 149 FACTORY_CLASS_OPT, 150 Messages.getMessage("optionFactory00")), 151 new CLOptionDescriptor("helperGen", 152 CLOptionDescriptor.ARGUMENT_DISALLOWED, 153 HELPER_CLASS_OPT, 154 Messages.getMessage("optionHelper00")), 155 new CLOptionDescriptor("buildFile", CLOptionDescriptor.ARGUMENT_DISALLOWED, 156 BUILDFILE_OPT, 157 Messages.getMessage("optionBuildFile00")), 158 new CLOptionDescriptor("user", CLOptionDescriptor.ARGUMENT_REQUIRED, 159 USERNAME_OPT, 160 Messages.getMessage("optionUsername")), 161 new CLOptionDescriptor("password", 162 CLOptionDescriptor.ARGUMENT_REQUIRED, 163 PASSWORD_OPT, 164 Messages.getMessage("optionPassword")), 165 new CLOptionDescriptor("classpath", 166 CLOptionDescriptor.ARGUMENT_OPTIONAL, 167 CLASSPATH_OPT, 168 Messages.getMessage("optionClasspath")), 169 new CLOptionDescriptor("nsInclude", 170 CLOptionDescriptor.DUPLICATES_ALLOWED 171 + CLOptionDescriptor.ARGUMENT_REQUIRED, 172 NS_INCLUDE_OPT, 173 Messages.getMessage("optionNSInclude")), 174 new CLOptionDescriptor("nsExclude", 175 CLOptionDescriptor.DUPLICATES_ALLOWED 176 + CLOptionDescriptor.ARGUMENT_REQUIRED, 177 NS_EXCLUDE_OPT, 178 Messages.getMessage("optionNSExclude")), 179 new CLOptionDescriptor("implementationClassName", 180 CLOptionDescriptor.ARGUMENT_REQUIRED, 181 IMPL_CLASS_OPT, 182 Messages.getMessage("implementationClassName")), 183 new CLOptionDescriptor("allowInvalidURL", CLOptionDescriptor.ARGUMENT_DISALLOWED, 184 ALLOW_INVALID_URL_OPT, Messages.getMessage("optionAllowInvalidURL")), 185 new CLOptionDescriptor("wrapArrays", 186 CLOptionDescriptor.ARGUMENT_OPTIONAL, 187 WRAP_ARRAYS_OPT, 188 Messages.getMessage("optionWrapArrays")), 189 }; 190 191 194 protected WSDL2Java() { 195 196 emitter = (Emitter) parser; 199 200 addOptions(options); 201 } 203 208 protected Parser createParser() { 209 return new Emitter(); 210 } 212 217 protected void parseOption(CLOption option) { 218 219 switch (option.getId()) { 220 221 case FACTORY_CLASS_OPT: 222 emitter.setFactory(option.getArgument()); 223 break; 224 225 case HELPER_CLASS_OPT: 226 emitter.setHelperWanted(true); 227 break; 228 229 case SKELETON_DEPLOY_OPT: 230 emitter.setSkeletonWanted( 231 JavaUtils.isTrueExplicitly(option.getArgument(0))); 232 233 case SERVER_OPT: 235 emitter.setServerSide(true); 236 break; 237 238 case NAMESPACE_OPT: 239 String namespace = option.getArgument(0); 240 String packageName = option.getArgument(1); 241 242 emitter.getNamespaceMap().put(namespace, packageName); 243 break; 244 245 case NAMESPACE_FILE_OPT: 246 emitter.setNStoPkg(option.getArgument()); 247 break; 248 249 case PACKAGE_OPT: 250 bPackageOpt = true; 251 252 emitter.setPackageName(option.getArgument()); 253 break; 254 255 case OUTPUT_OPT: 256 emitter.setOutputDir(option.getArgument()); 257 break; 258 259 case SCOPE_OPT: 260 String arg = option.getArgument(); 261 262 Scope scope = Scope.getScope(arg, null); 265 266 if (scope != null) { 267 emitter.setScope(scope); 268 } else { 269 System.err.println(Messages.getMessage("badScope00", arg)); 270 } 271 break; 272 273 case TEST_OPT: 274 emitter.setTestCaseWanted(true); 275 break; 276 case BUILDFILE_OPT: 277 emitter.setBuildFileWanted(true); 278 break; 279 case ALL_OPT: 280 emitter.setAllWanted(true); 281 break; 282 283 case TYPEMAPPING_OPT: 284 String tmValue = option.getArgument(); 285 286 if (tmValue.equals("1.0")) { 287 emitter.setTypeMappingVersion("1.0"); 288 } else if (tmValue.equals("1.1")) { 289 emitter.setTypeMappingVersion("1.1"); 290 } else if (tmValue.equals("1.2")) { 291 emitter.setTypeMappingVersion("1.2"); 292 } else if (tmValue.equals("1.3")) { 293 emitter.setTypeMappingVersion("1.3"); 294 } else { 295 System.out.println( 296 Messages.getMessage("badTypeMappingOption00")); 297 } 298 break; 299 300 case USERNAME_OPT: 301 emitter.setUsername(option.getArgument()); 302 break; 303 304 case PASSWORD_OPT: 305 emitter.setPassword(option.getArgument()); 306 break; 307 308 case CLASSPATH_OPT: 309 ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader( 310 option.getArgument(), 311 this.getClass().getClassLoader())); 312 break; 313 314 case NS_INCLUDE_OPT: 315 NamespaceSelector include = new NamespaceSelector(); 316 include.setNamespace(option.getArgument()); 317 emitter.getNamespaceIncludes().add(include); 318 break; 319 case NS_EXCLUDE_OPT: 320 NamespaceSelector exclude = new NamespaceSelector(); 321 exclude.setNamespace(option.getArgument()); 322 emitter.getNamespaceExcludes().add(exclude); 323 break; 324 325 case IMPL_CLASS_OPT: 326 emitter.setImplementationClassName(option.getArgument()); 327 break; 328 329 case ALLOW_INVALID_URL_OPT: 330 emitter.setAllowInvalidURL(true); 331 break; 332 333 case WRAP_ARRAYS_OPT: 334 emitter.setWrapArrays(true); 335 break; 336 337 default : 338 super.parseOption(option); 339 } 340 } 342 347 protected void validateOptions() { 348 349 super.validateOptions(); 350 351 if (emitter.isSkeletonWanted() && !emitter.isServerSide()) { 353 System.out.println(Messages.getMessage("badSkeleton00")); 354 printUsage(); 355 } 356 357 if (!emitter.getNamespaceMap().isEmpty() && bPackageOpt) { 358 System.out.println(Messages.getMessage("badpackage00")); 359 printUsage(); 360 } 361 } 363 369 public static void main(String args[]) { 370 371 WSDL2Java wsdl2java = new WSDL2Java(); 372 373 wsdl2java.run(args); 374 } 375 } 376 | Popular Tags |