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