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