src/share/jaxws_classes/com/sun/tools/internal/ws/processor/generator/JwsImplGenerator.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.tools.internal.ws.processor.generator;
ohair@286 27
ohair@286 28 import com.sun.codemodel.internal.*;
ohair@286 29 import com.sun.tools.internal.ws.processor.model.*;
ohair@286 30 import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
ohair@286 31 import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
ohair@286 32 import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
ohair@286 33 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
ohair@286 34 import com.sun.tools.internal.ws.wsdl.document.Definitions;
ohair@286 35 import com.sun.tools.internal.ws.wsdl.document.Binding;
ohair@286 36 import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Binding;
ohair@286 37 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
ohair@286 38 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPConstants;
ohair@286 39 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
ohair@286 40 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
ohair@286 41 import com.sun.tools.internal.ws.processor.model.ModelProperties;
ohair@286 42 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
ohair@286 43 import com.sun.codemodel.internal.JClassAlreadyExistsException;
ohair@286 44 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 45
ohair@286 46 import com.sun.xml.internal.ws.util.ServiceFinder;
ohair@286 47
ohair@286 48 import javax.jws.WebService;
ohair@286 49 import javax.xml.ws.BindingType;
ohair@286 50 import javax.xml.namespace.QName;
ohair@286 51 import javax.xml.ws.Holder;
ohair@286 52 import java.io.File;
ohair@286 53 import java.util.ArrayList;
ohair@286 54 import java.util.HashMap;
ohair@286 55 import java.util.List;
ohair@286 56 import java.util.Iterator;
ohair@286 57 import java.util.Map;
ohair@286 58
ohair@286 59 /**
ohair@286 60 * Generator for placeholder JWS implementations
ohair@286 61 *
ohair@286 62 * @since 2.2.6
ohair@286 63 */
ohair@286 64 public final class JwsImplGenerator extends GeneratorBase {
ohair@286 65 private static final Map<String, String> TRANSLATION_MAP = new HashMap<String, String>(
ohair@286 66 1);
ohair@286 67 static
ohair@286 68 {
ohair@286 69 TRANSLATION_MAP.put(SOAPConstants.URI_SOAP_TRANSPORT_HTTP,
ohair@286 70 javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING);
ohair@286 71 }
ohair@286 72 // save the generated impl files' info
ohair@286 73 private final List<String> implFiles = new ArrayList<String>();
ohair@286 74
ohair@286 75 public static List<String> generate(Model model, WsimportOptions options,
ohair@286 76 ErrorReceiver receiver) {
ohair@286 77 // options check
ohair@286 78
ohair@286 79 // Generate it according the implDestDir option
ohair@286 80 if (options.implDestDir == null)
ohair@286 81 return null;
ohair@286 82
ohair@286 83 JwsImplGenerator jwsImplGenerator = new JwsImplGenerator();
ohair@286 84 jwsImplGenerator.init(model, options, receiver);
ohair@286 85 jwsImplGenerator.doGeneration();
ohair@286 86 // print a warning message while implFiles.size() is zero
ohair@286 87 if (jwsImplGenerator.implFiles.size() == 0) {
ohair@286 88 StringBuffer msg = new StringBuffer();
ohair@286 89 if (options.implServiceName != null)
ohair@286 90 msg.append("serviceName=[" + options.implServiceName + "] ");
ohair@286 91 if (options.implPortName != null)
ohair@286 92 msg.append("portName=[" + options.implPortName + "] ");
ohair@286 93
ohair@286 94 if (msg.length() > 0)
ohair@286 95 msg.append(", Not found in wsdl file.\n");
ohair@286 96
ohair@286 97 msg.append("No impl files generated!");
ohair@286 98 receiver.warning(null, msg.toString());
ohair@286 99 }
ohair@286 100
ohair@286 101 return jwsImplGenerator.implFiles;
ohair@286 102 }
ohair@286 103
ohair@286 104 /**
ohair@286 105 * Move impl files to implDestDir
ohair@286 106 */
ohair@286 107 public static boolean moveToImplDestDir(List<String> gImplFiles,
ohair@286 108 WsimportOptions options, ErrorReceiver receiver) {
ohair@286 109 if (options.implDestDir == null || gImplFiles == null
ohair@286 110 || gImplFiles.size() == 0)
ohair@286 111 return true;
ohair@286 112
ohair@286 113 List<ImplFile> generatedImplFiles = ImplFile.toImplFiles(gImplFiles);
ohair@286 114
ohair@286 115 try {
ohair@286 116 File implDestDir = makePackageDir(options);
ohair@286 117
ohair@286 118 File movedF;
ohair@286 119 File f;
ohair@286 120 for (ImplFile implF : generatedImplFiles) {
ohair@286 121 movedF = findFile(options, implF.qualifiedName);
ohair@286 122 if (movedF == null) {
ohair@286 123 // should never happen
ohair@286 124 receiver.warning(null, "Class " + implF.qualifiedName
ohair@286 125 + " is not generated. Not moving.");
ohair@286 126 return false;
ohair@286 127 }
ohair@286 128
ohair@286 129 f = new File(implDestDir, implF.name);
ohair@286 130 if (!movedF.equals(f)) { //bug 10102169
ohair@286 131
ohair@286 132 if (f.exists())
ohair@286 133 {
ohair@286 134 if (!f.delete()){
ohair@286 135 receiver.error("Class " + implF.qualifiedName
ohair@286 136 + " has existed in destImplDir, and it "
ohair@286 137 + "can not be written!", null);
ohair@286 138 }
ohair@286 139 }
ohair@286 140 if(!movedF.renameTo(f))
ohair@286 141 {
ohair@286 142 throw new Exception();
ohair@286 143 }
ohair@286 144 }
ohair@286 145 }
ohair@286 146 } catch (Exception e) {
ohair@286 147 receiver.error("Moving WebService Impl files failed!", e);
ohair@286 148 return false;
ohair@286 149 }
ohair@286 150 return true;
ohair@286 151 }
ohair@286 152
ohair@286 153 private JwsImplGenerator() {
ohair@286 154 donotOverride = true;
ohair@286 155 }
ohair@286 156
ohair@286 157 @Override
ohair@286 158 public void visit(Service service) {
ohair@286 159 QName serviceName = service.getName();
ohair@286 160 // process the ordered service only if it is defined
ohair@286 161 if (options.implServiceName != null
ohair@286 162 && !equalsNSOptional(options.implServiceName, serviceName))
ohair@286 163 return;
ohair@286 164
ohair@286 165 for (Port port : service.getPorts()) {
ohair@286 166 if (port.isProvider()) {
ohair@286 167 continue; // Not generating for Provider based endpoint
ohair@286 168 }
ohair@286 169
ohair@286 170 // Generate the impl class name according to
ohair@286 171 // Xpath(/definitions/service/port[@name]);
ohair@286 172 QName portName = port.getName();
ohair@286 173
ohair@286 174 // process the ordered port only if it is defined
ohair@286 175 if (options.implPortName != null
ohair@286 176 && !equalsNSOptional(options.implPortName, portName))
ohair@286 177 continue;
ohair@286 178
ohair@286 179 String simpleClassName = serviceName.getLocalPart() + "_"
ohair@286 180 + portName.getLocalPart() + "Impl";
ohair@286 181 String className = makePackageQualified(simpleClassName);
ohair@286 182 implFiles.add(className);
ohair@286 183
ohair@286 184 if (donotOverride && GeneratorUtil.classExists(options, className)) {
ohair@286 185 log("Class " + className + " exists. Not overriding.");
ohair@286 186 return;
ohair@286 187 }
ohair@286 188
ohair@286 189 JDefinedClass cls = null;
ohair@286 190 try {
ohair@286 191 cls = getClass(className, ClassType.CLASS);
ohair@286 192 } catch (JClassAlreadyExistsException e) {
ohair@286 193 log("Class " + className
ohair@286 194 + " generates failed. JClassAlreadyExistsException[" + className
ohair@286 195 + "].");
ohair@286 196 return;
ohair@286 197 }
ohair@286 198
ohair@286 199 // Each serviceImpl will implements one port interface
ohair@286 200 JavaInterface portIntf = port.getJavaInterface();
ohair@286 201 String portClassName = Names.customJavaTypeClassName(portIntf);
ohair@286 202 JDefinedClass portCls = null;
ohair@286 203 try {
ohair@286 204 portCls = getClass(portClassName, ClassType.INTERFACE);
ohair@286 205 } catch (JClassAlreadyExistsException e) {
ohair@286 206 log("Class " + className
ohair@286 207 + " generates failed. JClassAlreadyExistsException["
ohair@286 208 + portClassName + "].");
ohair@286 209 return;
ohair@286 210 }
ohair@286 211 cls._implements(portCls);
ohair@286 212
ohair@286 213 // create a default constructor
ohair@286 214 cls.constructor(JMod.PUBLIC);
ohair@286 215
ohair@286 216 // write class comment - JAXWS warning
ohair@286 217 JDocComment comment = cls.javadoc();
ohair@286 218
ohair@286 219 if (service.getJavaDoc() != null) {
ohair@286 220 comment.add(service.getJavaDoc());
ohair@286 221 comment.add("\n\n");
ohair@286 222 }
ohair@286 223
ohair@286 224 for (String doc : getJAXWSClassComment()) {
ohair@286 225 comment.add(doc);
ohair@286 226 }
ohair@286 227
ohair@286 228 // @WebService
ohair@286 229 JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
ohair@286 230 writeWebServiceAnnotation(service, port, webServiceAnn);
ohair@286 231
ohair@286 232 // @BindingType
ohair@286 233 JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
ohair@286 234 writeBindingTypeAnnotation(port, bindingTypeAnn);
ohair@286 235
ohair@286 236 // extra annotation
ohair@286 237 for( GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
ohair@286 238 f.writeWebServiceAnnotation(model, cm, cls, port);
ohair@286 239 }
ohair@286 240
ohair@286 241 // WebMethods
ohair@286 242 for (Operation operation : port.getOperations()) {
ohair@286 243 JavaMethod method = operation.getJavaMethod();
ohair@286 244
ohair@286 245 // @WebMethod
ohair@286 246 JMethod m;
ohair@286 247 JDocComment methodDoc;
ohair@286 248 String methodJavaDoc = operation.getJavaDoc();
ohair@286 249 if (method.getReturnType().getName().equals("void")) {
ohair@286 250 m = cls.method(JMod.PUBLIC, void.class, method.getName());
ohair@286 251 methodDoc = m.javadoc();
ohair@286 252 } else {
ohair@286 253 JAXBTypeAndAnnotation retType = method.getReturnType().getType();
ohair@286 254 m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
ohair@286 255 retType.annotate(m);
ohair@286 256 methodDoc = m.javadoc();
ohair@286 257 JCommentPart ret = methodDoc.addReturn();
ohair@286 258 ret.add("returns " + retType.getName());
ohair@286 259 }
ohair@286 260
ohair@286 261 if (methodJavaDoc != null)
ohair@286 262 methodDoc.add(methodJavaDoc);
ohair@286 263
ohair@286 264 JClass holder = cm.ref(Holder.class);
ohair@286 265 for (JavaParameter parameter : method.getParametersList()) {
ohair@286 266 JVar var;
ohair@286 267 JAXBTypeAndAnnotation paramType = parameter.getType().getType();
ohair@286 268 if (parameter.isHolder()) {
ohair@286 269 var = m.param(holder.narrow(paramType.getType().boxify()),
ohair@286 270 parameter.getName());
ohair@286 271 } else {
ohair@286 272 var = m.param(paramType.getType(), parameter.getName());
ohair@286 273 }
ohair@286 274 methodDoc.addParam(var);
ohair@286 275 }
ohair@286 276
ohair@286 277 com.sun.tools.internal.ws.wsdl.document.Operation wsdlOp = operation
ohair@286 278 .getWSDLPortTypeOperation();
ohair@286 279 for (Fault fault : operation.getFaultsSet()) {
ohair@286 280 m._throws(fault.getExceptionClass());
ohair@286 281 methodDoc.addThrows(fault.getExceptionClass());
ohair@286 282 wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
ohair@286 283 }
ohair@286 284 m.body().block().directStatement("//replace with your impl here");
ohair@286 285 m.body().block().directStatement(
ohair@286 286 getReturnString(method.getReturnType().getName()));
ohair@286 287 }
ohair@286 288 }
ohair@286 289 }
ohair@286 290
ohair@286 291 /**
ohair@286 292 * Generate return statement according to return type.
ohair@286 293 *
ohair@286 294 * @param type
ohair@286 295 * The method's return type
ohair@286 296 * @return The whole return statement
ohair@286 297 */
ohair@286 298 private String getReturnString(String type) {
ohair@286 299 final String nullReturnStr = "return null;";
ohair@286 300 // complex type or array
ohair@286 301 if (type.indexOf('.') > -1 || type.indexOf('[') > -1) {
ohair@286 302 return nullReturnStr;
ohair@286 303 }
ohair@286 304
ohair@286 305 // primitive type
ohair@286 306 if (type.equals("void")) {
ohair@286 307 return "return;";
ohair@286 308 }
ohair@286 309 if (type.equals("boolean")) {
ohair@286 310 return "return false;";
ohair@286 311 }
ohair@286 312 if (type.equals("int") || type.equals("byte") || type.equals("short")
ohair@286 313 || type.equals("long") || type.equals("double") || type.equals("float")) {
ohair@286 314 return "return 0;";
ohair@286 315 }
ohair@286 316 if (type.equals("char")) {
ohair@286 317 return "return '0';";
ohair@286 318 }
ohair@286 319
ohair@286 320 return nullReturnStr;
ohair@286 321 }
ohair@286 322
ohair@286 323 /**
ohair@286 324 *
ohair@286 325 * @param service
ohair@286 326 * @param port
ohair@286 327 * @param webServiceAnn
ohair@286 328 * @param options
ohair@286 329 */
ohair@286 330 private void writeWebServiceAnnotation(Service service, Port port,
ohair@286 331 JAnnotationUse webServiceAnn) {
ohair@286 332 webServiceAnn.param("portName", port.getName().getLocalPart());
ohair@286 333 webServiceAnn.param("serviceName", service.getName().getLocalPart());
ohair@286 334 webServiceAnn.param("targetNamespace", service.getName().getNamespaceURI());
ohair@286 335 webServiceAnn.param("wsdlLocation", wsdlLocation);
ohair@286 336 webServiceAnn.param("endpointInterface", port.getJavaInterface().getName());
ohair@286 337 }
ohair@286 338 //CR373098 To transform the java class name as validate.
ohair@286 339 private String transToValidJavaIdentifier(String s) {
ohair@286 340 if (s == null) return null;
ohair@286 341 final int len = s.length();
ohair@286 342 StringBuffer retSB = new StringBuffer();
ohair@286 343 if (len == 0 || !Character.isJavaIdentifierStart(s.charAt(0)))
ohair@286 344 retSB.append("J"); //update to a default start char
ohair@286 345 else
ohair@286 346 retSB.append(s.charAt(0));
ohair@286 347
ohair@286 348 for (int i = 1; i < len; i++) {
ohair@286 349 if (!Character.isJavaIdentifierPart(s.charAt(i)))
ohair@286 350 ; //delete it if it is illegal //TODO: It might conflict "a-b" vs. "ab"
ohair@286 351 else
ohair@286 352 retSB.append(s.charAt(i));
ohair@286 353 }
ohair@286 354 return retSB.toString();
ohair@286 355 }
ohair@286 356
ohair@286 357 private String makePackageQualified(String s) {
ohair@286 358 s = transToValidJavaIdentifier(s);
ohair@286 359 if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
ohair@286 360 return options.defaultPackage + "." + s;
ohair@286 361 } else {
ohair@286 362 return s;
ohair@286 363 }
ohair@286 364 }
ohair@286 365
ohair@286 366
ohair@286 367 /**
ohair@286 368 * TODO
ohair@286 369 *
ohair@286 370 * @param port
ohair@286 371 * @param bindingTypeAnn
ohair@286 372 */
ohair@286 373 private void writeBindingTypeAnnotation(Port port,
ohair@286 374 JAnnotationUse bindingTypeAnn) {
ohair@286 375 QName bName = (QName) port
ohair@286 376 .getProperty(ModelProperties.PROPERTY_WSDL_BINDING_NAME);
ohair@286 377 if (bName == null)
ohair@286 378 return;
ohair@286 379
ohair@286 380 String v = getBindingType(bName);
ohair@286 381
ohair@286 382 // TODO: How to decide if it is a mtom?
ohair@286 383 if (v != null) {
ohair@286 384 // transport = translate(transport);
ohair@286 385 bindingTypeAnn.param("value", v);
ohair@286 386 }
ohair@286 387
ohair@286 388 }
ohair@286 389
ohair@286 390 private String resolveBindingValue(TWSDLExtension wsdlext) {
ohair@286 391 if (wsdlext.getClass().equals(SOAPBinding.class)) {
ohair@286 392 SOAPBinding sb = (SOAPBinding) wsdlext;
ohair@286 393 if(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(sb.getTransport()))
ohair@286 394 return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING;
ohair@286 395 else {
ohair@286 396 for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
ohair@286 397 String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_11);
ohair@286 398 if(bindingValue!=null) {
ohair@286 399 return bindingValue;
ohair@286 400 }
ohair@286 401 }
ohair@286 402 return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
ohair@286 403 }
ohair@286 404 }
ohair@286 405 if (wsdlext.getClass().equals(SOAP12Binding.class)) {
ohair@286 406 SOAP12Binding sb = (SOAP12Binding) wsdlext;
ohair@286 407 if(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(sb.getTransport()))
ohair@286 408 return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING;
ohair@286 409 else {
ohair@286 410 for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
ohair@286 411 String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_12);
ohair@286 412 if(bindingValue!=null) {
ohair@286 413 return bindingValue;
ohair@286 414 }
ohair@286 415 }
ohair@286 416 return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING;
ohair@286 417 }
ohair@286 418 }
ohair@286 419 return null;
ohair@286 420 }
ohair@286 421
ohair@286 422 private String getBindingType(QName bName) {
ohair@286 423
ohair@286 424 String value = null;
ohair@286 425 // process the bindings in definitions of model.entity
ohair@286 426 if (model.getEntity() instanceof Definitions) {
ohair@286 427 Definitions definitions = (Definitions) model.getEntity();
ohair@286 428 if (definitions != null) {
ohair@286 429 Iterator bindings = definitions.bindings();
ohair@286 430 if (bindings != null) {
ohair@286 431 while (bindings.hasNext()) {
ohair@286 432 Binding binding = (Binding) bindings.next();
ohair@286 433 if (bName.getLocalPart().equals(binding.getName())
ohair@286 434 && bName.getNamespaceURI().equals(binding.getNamespaceURI())) {
ohair@286 435 List<TWSDLExtension> bindextends = (List<TWSDLExtension>) binding
ohair@286 436 .extensions();
ohair@286 437 for (TWSDLExtension wsdlext : bindextends) {
ohair@286 438 value = resolveBindingValue(wsdlext);
ohair@286 439 if (value != null)
ohair@286 440 break;
ohair@286 441 }
ohair@286 442 break;
ohair@286 443 }
ohair@286 444 }
ohair@286 445 }
ohair@286 446 }
ohair@286 447 }
ohair@286 448
ohair@286 449 // process the bindings in backup list of model
ohair@286 450 if (value == null) {
ohair@286 451 // TODO: The property "BAKEUP_BINDINGS" is set in WsdlModeler when init
ohair@286 452 // the model
ohair@286 453 // make this as a const if needed.
ohair@286 454 HashMap hm = (HashMap) model.getProperty("BAKEUP_BINDINGS");
ohair@286 455 Binding b = (Binding) hm.get(bName);
ohair@286 456 if (b != null) {
ohair@286 457 List<TWSDLExtension> bindextends = (List<TWSDLExtension>) b
ohair@286 458 .extensions();
ohair@286 459 for (TWSDLExtension wsdlext : bindextends) {
ohair@286 460 value = resolveBindingValue(wsdlext);
ohair@286 461 if (value != null)
ohair@286 462 break;
ohair@286 463 }
ohair@286 464 }
ohair@286 465 }
ohair@286 466
ohair@286 467 return value;
ohair@286 468 }
ohair@286 469
ohair@286 470 /**
ohair@286 471 * Since the SOAP 1.1 binding transport URI defined in WSDL 1.1 specification
ohair@286 472 * is different with the SOAPBinding URI defined by JAX-WS 2.0 specification.
ohair@286 473 * We must translate the wsdl version into JAX-WS version. If the given
ohair@286 474 * transport URI is NOT one of the predefined transport URIs, it is returned
ohair@286 475 * as is.
ohair@286 476 *
ohair@286 477 * @param transportURI
ohair@286 478 * retrieved from WSDL
ohair@286 479 * @return Standard BindingType URI defined by JAX-WS 2.0 specification.
ohair@286 480 */
ohair@286 481 private String translate(String transportURI)
ohair@286 482 {
ohair@286 483 String translatedBindingId = TRANSLATION_MAP.get(transportURI);
ohair@286 484 if (translatedBindingId == null)
ohair@286 485 translatedBindingId = transportURI;
ohair@286 486
ohair@286 487 return translatedBindingId;
ohair@286 488 }
ohair@286 489
ohair@286 490 /*****************************************************************************
ohair@286 491 * Inner classes definition
ohair@286 492 */
ohair@286 493 static final class ImplFile {
ohair@286 494 public String qualifiedName; // package+"."+simpleClassName + ".java"
ohair@286 495
ohair@286 496 public String name; // simpleClassName + ".java"
ohair@286 497
ohair@286 498 private ImplFile(String qualifiedClassName) {
ohair@286 499 this.qualifiedName = qualifiedClassName + ".java";
ohair@286 500
ohair@286 501 String simpleClassName = qualifiedClassName;
ohair@286 502 int i = qualifiedClassName.lastIndexOf(".");
ohair@286 503 if (i != -1)
ohair@286 504 simpleClassName = qualifiedClassName.substring(i + 1);
ohair@286 505
ohair@286 506 this.name = simpleClassName + ".java";
ohair@286 507 }
ohair@286 508
ohair@286 509 public static List<ImplFile> toImplFiles(List<String> qualifiedClassNames) {
ohair@286 510 List<ImplFile> ret = new ArrayList<ImplFile>();
ohair@286 511
ohair@286 512 for (String qualifiedClassName : qualifiedClassNames)
ohair@286 513 ret.add(new ImplFile(qualifiedClassName));
ohair@286 514
ohair@286 515 return ret;
ohair@286 516 }
ohair@286 517 }
ohair@286 518
ohair@286 519 /*****************************************************************************
ohair@286 520 * Other utility methods
ohair@286 521 */
ohair@286 522
ohair@286 523 private static File makePackageDir(WsimportOptions options) {
ohair@286 524 File ret = null;
ohair@286 525 if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
ohair@286 526 String subDir = options.defaultPackage.replace('.', '/');
ohair@286 527 ret = new File(options.implDestDir, subDir);
ohair@286 528 } else {
ohair@286 529 ret = options.implDestDir;
ohair@286 530 }
ohair@286 531
ohair@286 532 ret.mkdirs();
ohair@286 533 return ret;
ohair@286 534 }
ohair@286 535
ohair@286 536 private static String getQualifiedFileName(String canonicalBaseDir, File f)
ohair@286 537 throws java.io.IOException {
ohair@286 538 String fp = f.getCanonicalPath();
ohair@286 539 if (fp == null)
ohair@286 540 return null;
ohair@286 541 fp = fp.replace(canonicalBaseDir, "");
ohair@286 542 fp = fp.replace('\\', '.');
ohair@286 543 fp = fp.replace('/', '.');
ohair@286 544 if (fp.startsWith("."))
ohair@286 545 fp = fp.substring(1);
ohair@286 546
ohair@286 547 return fp;
ohair@286 548 }
ohair@286 549
ohair@286 550 private static File findFile(WsimportOptions options, String qualifiedFileName)
ohair@286 551 throws java.io.IOException {
ohair@286 552 String baseDir = options.destDir.getCanonicalPath();
ohair@286 553 String fp = null;
ohair@286 554 for (File f : options.getGeneratedFiles()) {
ohair@286 555 fp = getQualifiedFileName(baseDir, f);
ohair@286 556 if (qualifiedFileName.equals(fp))
ohair@286 557 return f;
ohair@286 558 }
ohair@286 559
ohair@286 560 return null;
ohair@286 561 }
ohair@286 562
ohair@286 563 private static boolean equalsNSOptional(String strQName, QName checkQN) {
ohair@286 564 if (strQName == null)
ohair@286 565 return false;
ohair@286 566 strQName = strQName.trim();
ohair@286 567 QName reqQN = QName.valueOf(strQName);
ohair@286 568
ohair@286 569 if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
ohair@286 570 return reqQN.getLocalPart().equals(checkQN.getLocalPart());
ohair@286 571
ohair@286 572 return reqQN.equals(checkQN);
ohair@286 573 }
ohair@286 574 }

mercurial