Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
ohair@286 | 1 | /* |
ohair@286 | 2 | * Copyright (c) 1997, 2010, 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.api.TJavaGeneratorExtension; |
ohair@286 | 30 | import com.sun.tools.internal.ws.processor.model.*; |
ohair@286 | 31 | import com.sun.tools.internal.ws.processor.model.java.JavaInterface; |
ohair@286 | 32 | import com.sun.tools.internal.ws.processor.model.java.JavaMethod; |
ohair@286 | 33 | import com.sun.tools.internal.ws.processor.model.java.JavaParameter; |
ohair@286 | 34 | import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType; |
ohair@286 | 35 | import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation; |
ohair@286 | 36 | import com.sun.tools.internal.ws.wscompile.ErrorReceiver; |
ohair@286 | 37 | import com.sun.tools.internal.ws.wscompile.Options; |
ohair@286 | 38 | import com.sun.tools.internal.ws.wscompile.WsimportOptions; |
ohair@286 | 39 | import com.sun.tools.internal.ws.wscompile.AbortException; |
ohair@286 | 40 | import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle; |
ohair@286 | 41 | import com.sun.tools.internal.ws.wsdl.document.PortType; |
ohair@286 | 42 | import com.sun.tools.internal.ws.wsdl.document.Kinds; |
ohair@286 | 43 | import com.sun.tools.internal.ws.resources.GeneratorMessages; |
ohair@286 | 44 | |
ohair@286 | 45 | import javax.jws.WebMethod; |
ohair@286 | 46 | import javax.jws.WebParam; |
ohair@286 | 47 | import javax.jws.WebService; |
ohair@286 | 48 | import javax.jws.soap.SOAPBinding; |
ohair@286 | 49 | import javax.xml.bind.annotation.XmlSeeAlso; |
ohair@286 | 50 | import javax.xml.namespace.QName; |
ohair@286 | 51 | import javax.xml.ws.Holder; |
ohair@286 | 52 | import java.util.ArrayList; |
ohair@286 | 53 | import java.util.List; |
ohair@286 | 54 | |
ohair@286 | 55 | import org.xml.sax.Locator; |
ohair@286 | 56 | |
ohair@286 | 57 | public class SeiGenerator extends GeneratorBase { |
ohair@286 | 58 | private String serviceNS; |
ohair@286 | 59 | private TJavaGeneratorExtension extension; |
ohair@286 | 60 | private List<TJavaGeneratorExtension> extensionHandlers; |
ohair@286 | 61 | |
ohair@286 | 62 | public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions){ |
ohair@286 | 63 | SeiGenerator seiGenerator = new SeiGenerator(); |
ohair@286 | 64 | seiGenerator.init(model, options, receiver, extensions); |
ohair@286 | 65 | seiGenerator.doGeneration(); |
ohair@286 | 66 | } |
ohair@286 | 67 | |
ohair@286 | 68 | public void init(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions) { |
ohair@286 | 69 | init(model, options, receiver); |
ohair@286 | 70 | extensionHandlers = new ArrayList<TJavaGeneratorExtension>(); |
ohair@286 | 71 | |
ohair@286 | 72 | // register handlers for default extensions |
ohair@286 | 73 | |
ohair@286 | 74 | // 2.2 Spec requires generation of @Action when wsam:Action is explicitly stated in wsdl |
ohair@286 | 75 | if (options.target.isLaterThan(Options.Target.V2_2)) { |
ohair@286 | 76 | register(new W3CAddressingJavaGeneratorExtension()); |
ohair@286 | 77 | } |
ohair@286 | 78 | |
ohair@286 | 79 | for (TJavaGeneratorExtension j : extensions) |
ohair@286 | 80 | register(j); |
ohair@286 | 81 | |
ohair@286 | 82 | this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[0])); |
ohair@286 | 83 | } |
ohair@286 | 84 | |
ohair@286 | 85 | private void write(Port port) { |
ohair@286 | 86 | JavaInterface intf = port.getJavaInterface(); |
ohair@286 | 87 | String className = Names.customJavaTypeClassName(intf); |
ohair@286 | 88 | |
ohair@286 | 89 | if (donotOverride && GeneratorUtil.classExists(options, className)) { |
ohair@286 | 90 | log("Class " + className + " exists. Not overriding."); |
ohair@286 | 91 | return; |
ohair@286 | 92 | } |
ohair@286 | 93 | |
ohair@286 | 94 | |
ohair@286 | 95 | JDefinedClass cls = null; |
ohair@286 | 96 | try { |
ohair@286 | 97 | cls = getClass(className, ClassType.INTERFACE); |
ohair@286 | 98 | } catch (JClassAlreadyExistsException e) { |
ohair@286 | 99 | QName portTypeName = |
ohair@286 | 100 | (QName) port.getProperty( |
ohair@286 | 101 | ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); |
ohair@286 | 102 | Locator loc = null; |
ohair@286 | 103 | if(portTypeName != null){ |
ohair@286 | 104 | PortType pt = port.portTypes.get(portTypeName); |
ohair@286 | 105 | if(pt!=null) |
ohair@286 | 106 | loc = pt.getLocator(); |
ohair@286 | 107 | } |
ohair@286 | 108 | receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName)); |
ohair@286 | 109 | return; |
ohair@286 | 110 | } |
ohair@286 | 111 | // If the class has methods it has already been defined |
ohair@286 | 112 | // so skip it. |
ohair@286 | 113 | if (!cls.methods().isEmpty()) |
ohair@286 | 114 | return; |
ohair@286 | 115 | |
ohair@286 | 116 | //write class comment - JAXWS warning |
ohair@286 | 117 | JDocComment comment = cls.javadoc(); |
ohair@286 | 118 | |
ohair@286 | 119 | String ptDoc = intf.getJavaDoc(); |
ohair@286 | 120 | if(ptDoc != null){ |
ohair@286 | 121 | comment.add(ptDoc); |
ohair@286 | 122 | comment.add("\n\n"); |
ohair@286 | 123 | } |
ohair@286 | 124 | |
ohair@286 | 125 | for(String doc:getJAXWSClassComment()){ |
ohair@286 | 126 | comment.add(doc); |
ohair@286 | 127 | } |
ohair@286 | 128 | |
ohair@286 | 129 | |
ohair@286 | 130 | //@WebService |
ohair@286 | 131 | JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class)); |
ohair@286 | 132 | writeWebServiceAnnotation(port, webServiceAnn); |
ohair@286 | 133 | |
ohair@286 | 134 | //@HandlerChain |
ohair@286 | 135 | writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options); |
ohair@286 | 136 | |
ohair@286 | 137 | //@SOAPBinding |
ohair@286 | 138 | writeSOAPBinding(port, cls); |
ohair@286 | 139 | |
ohair@286 | 140 | //@XmlSeeAlso |
ohair@286 | 141 | if(options.target.isLaterThan(Options.Target.V2_1)) |
ohair@286 | 142 | writeXmlSeeAlso(cls); |
ohair@286 | 143 | |
ohair@286 | 144 | for (Operation operation: port.getOperations()) { |
ohair@286 | 145 | JavaMethod method = operation.getJavaMethod(); |
ohair@286 | 146 | |
ohair@286 | 147 | //@WebMethod |
ohair@286 | 148 | JMethod m; |
ohair@286 | 149 | JDocComment methodDoc; |
ohair@286 | 150 | String methodJavaDoc = operation.getJavaDoc(); |
ohair@286 | 151 | if(method.getReturnType().getName().equals("void")){ |
ohair@286 | 152 | m = cls.method(JMod.PUBLIC, void.class, method.getName()); |
ohair@286 | 153 | methodDoc = m.javadoc(); |
ohair@286 | 154 | }else { |
ohair@286 | 155 | JAXBTypeAndAnnotation retType = method.getReturnType().getType(); |
ohair@286 | 156 | m = cls.method(JMod.PUBLIC, retType.getType(), method.getName()); |
ohair@286 | 157 | retType.annotate(m); |
ohair@286 | 158 | methodDoc = m.javadoc(); |
ohair@286 | 159 | JCommentPart ret = methodDoc.addReturn(); |
ohair@286 | 160 | ret.add("returns "+retType.getName()); |
ohair@286 | 161 | } |
ohair@286 | 162 | if(methodJavaDoc != null) |
ohair@286 | 163 | methodDoc.add(methodJavaDoc); |
ohair@286 | 164 | |
ohair@286 | 165 | writeWebMethod(operation, m); |
ohair@286 | 166 | JClass holder = cm.ref(Holder.class); |
ohair@286 | 167 | for (JavaParameter parameter: method.getParametersList()) { |
ohair@286 | 168 | JVar var; |
ohair@286 | 169 | JAXBTypeAndAnnotation paramType = parameter.getType().getType(); |
ohair@286 | 170 | if (parameter.isHolder()) { |
ohair@286 | 171 | var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName()); |
ohair@286 | 172 | }else{ |
ohair@286 | 173 | var = m.param(paramType.getType(), parameter.getName()); |
ohair@286 | 174 | } |
ohair@286 | 175 | |
ohair@286 | 176 | //annotate parameter with JAXB annotations |
ohair@286 | 177 | paramType.annotate(var); |
ohair@286 | 178 | methodDoc.addParam(var); |
ohair@286 | 179 | JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class)); |
ohair@286 | 180 | writeWebParam(operation, parameter, paramAnn); |
ohair@286 | 181 | } |
ohair@286 | 182 | com.sun.tools.internal.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation(); |
ohair@286 | 183 | for(Fault fault:operation.getFaultsSet()){ |
ohair@286 | 184 | m._throws(fault.getExceptionClass()); |
ohair@286 | 185 | methodDoc.addThrows(fault.getExceptionClass()); |
ohair@286 | 186 | wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass()); |
ohair@286 | 187 | } |
ohair@286 | 188 | |
ohair@286 | 189 | //It should be the last thing to invoke after JMethod is built completely |
ohair@286 | 190 | extension.writeMethodAnnotations(wsdlOp, m); |
ohair@286 | 191 | } |
ohair@286 | 192 | } |
ohair@286 | 193 | |
ohair@286 | 194 | private void writeXmlSeeAlso(JDefinedClass cls) { |
ohair@286 | 195 | if (model.getJAXBModel().getS2JJAXBModel() != null) { |
ohair@286 | 196 | List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories(); |
ohair@286 | 197 | |
ohair@286 | 198 | //if there are no object facotires, dont generate @XmlSeeAlso |
ohair@286 | 199 | if(objectFactories.size() == 0) |
ohair@286 | 200 | return; |
ohair@286 | 201 | |
ohair@286 | 202 | JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class)); |
ohair@286 | 203 | JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value"); |
ohair@286 | 204 | for (JClass of : objectFactories) { |
ohair@286 | 205 | paramArray = paramArray.param(of); |
ohair@286 | 206 | } |
ohair@286 | 207 | } |
ohair@286 | 208 | |
ohair@286 | 209 | } |
ohair@286 | 210 | |
ohair@286 | 211 | private void writeWebMethod(Operation operation, JMethod m) { |
ohair@286 | 212 | Response response = operation.getResponse(); |
ohair@286 | 213 | JAnnotationUse webMethodAnn = m.annotate(cm.ref(WebMethod.class)); |
ohair@286 | 214 | String operationName = (operation instanceof AsyncOperation)? |
ohair@286 | 215 | ((AsyncOperation)operation).getNormalOperation().getName().getLocalPart(): |
ohair@286 | 216 | operation.getName().getLocalPart(); |
ohair@286 | 217 | |
ohair@286 | 218 | if(!m.name().equals(operationName)){ |
ohair@286 | 219 | webMethodAnn.param("operationName", operationName); |
ohair@286 | 220 | } |
ohair@286 | 221 | |
ohair@286 | 222 | if (operation.getSOAPAction() != null && operation.getSOAPAction().length() > 0){ |
ohair@286 | 223 | webMethodAnn.param("action", operation.getSOAPAction()); |
ohair@286 | 224 | } |
ohair@286 | 225 | |
ohair@286 | 226 | if (operation.getResponse() == null){ |
ohair@286 | 227 | m.annotate(javax.jws.Oneway.class); |
ohair@286 | 228 | }else if (!operation.getJavaMethod().getReturnType().getName().equals("void") && |
ohair@286 | 229 | operation.getResponse().getParametersList().size() > 0){ |
ohair@286 | 230 | Block block; |
ohair@286 | 231 | String resultName = null; |
ohair@286 | 232 | String nsURI = null; |
ohair@286 | 233 | if (operation.getResponse().getBodyBlocks().hasNext()) { |
ohair@286 | 234 | block = operation.getResponse().getBodyBlocks().next(); |
ohair@286 | 235 | resultName = block.getName().getLocalPart(); |
ohair@286 | 236 | if(isDocStyle || block.getLocation() == Block.HEADER){ |
ohair@286 | 237 | nsURI = block.getName().getNamespaceURI(); |
ohair@286 | 238 | } |
ohair@286 | 239 | } |
ohair@286 | 240 | |
ohair@286 | 241 | for (Parameter parameter : operation.getResponse().getParametersList()) { |
ohair@286 | 242 | if (parameter.getParameterIndex() == -1) { |
ohair@286 | 243 | if(operation.isWrapped()||!isDocStyle){ |
ohair@286 | 244 | if(parameter.getBlock().getLocation() == Block.HEADER){ |
ohair@286 | 245 | resultName = parameter.getBlock().getName().getLocalPart(); |
ohair@286 | 246 | }else{ |
ohair@286 | 247 | resultName = parameter.getName(); |
ohair@286 | 248 | } |
ohair@286 | 249 | if (isDocStyle || (parameter.getBlock().getLocation() == Block.HEADER)) { |
ohair@286 | 250 | nsURI = parameter.getType().getName().getNamespaceURI(); |
ohair@286 | 251 | } |
ohair@286 | 252 | }else if(isDocStyle){ |
ohair@286 | 253 | JAXBType t = (JAXBType)parameter.getType(); |
ohair@286 | 254 | resultName = t.getName().getLocalPart(); |
ohair@286 | 255 | nsURI = t.getName().getNamespaceURI(); |
ohair@286 | 256 | } |
ohair@286 | 257 | if(!(operation instanceof AsyncOperation)){ |
ohair@286 | 258 | JAnnotationUse wr = null; |
ohair@286 | 259 | |
ohair@286 | 260 | if(!resultName.equals("return")){ |
ohair@286 | 261 | wr = m.annotate(javax.jws.WebResult.class); |
ohair@286 | 262 | wr.param("name", resultName); |
ohair@286 | 263 | } |
ohair@286 | 264 | if((nsURI != null) && (!nsURI.equals(serviceNS) || (isDocStyle && operation.isWrapped()))){ |
ohair@286 | 265 | if(wr == null) |
ohair@286 | 266 | wr = m.annotate(javax.jws.WebResult.class); |
ohair@286 | 267 | wr.param("targetNamespace", nsURI); |
ohair@286 | 268 | } |
ohair@286 | 269 | //doclit wrapped could have additional headers |
ohair@286 | 270 | if(!(isDocStyle && operation.isWrapped()) || |
ohair@286 | 271 | (parameter.getBlock().getLocation() == Block.HEADER)){ |
ohair@286 | 272 | if(wr == null) |
ohair@286 | 273 | wr = m.annotate(javax.jws.WebResult.class); |
ohair@286 | 274 | wr.param("partName", parameter.getName()); |
ohair@286 | 275 | } |
ohair@286 | 276 | if(parameter.getBlock().getLocation() == Block.HEADER){ |
ohair@286 | 277 | if(wr == null) |
ohair@286 | 278 | wr = m.annotate(javax.jws.WebResult.class); |
ohair@286 | 279 | wr.param("header",true); |
ohair@286 | 280 | } |
ohair@286 | 281 | } |
ohair@286 | 282 | } |
ohair@286 | 283 | |
ohair@286 | 284 | } |
ohair@286 | 285 | } |
ohair@286 | 286 | |
ohair@286 | 287 | //DOC/BARE |
ohair@286 | 288 | if (!sameParamStyle) { |
ohair@286 | 289 | if(!operation.isWrapped()) { |
ohair@286 | 290 | JAnnotationUse sb = m.annotate(SOAPBinding.class); |
ohair@286 | 291 | sb.param("parameterStyle", SOAPBinding.ParameterStyle.BARE); |
ohair@286 | 292 | } |
ohair@286 | 293 | } |
ohair@286 | 294 | |
ohair@286 | 295 | if (operation.isWrapped() && operation.getStyle().equals(SOAPStyle.DOCUMENT)) { |
ohair@286 | 296 | Block reqBlock = operation.getRequest().getBodyBlocks().next(); |
ohair@286 | 297 | JAnnotationUse reqW = m.annotate(javax.xml.ws.RequestWrapper.class); |
ohair@286 | 298 | reqW.param("localName", reqBlock.getName().getLocalPart()); |
ohair@286 | 299 | reqW.param("targetNamespace", reqBlock.getName().getNamespaceURI()); |
ohair@286 | 300 | reqW.param("className", reqBlock.getType().getJavaType().getName()); |
ohair@286 | 301 | |
ohair@286 | 302 | if (response != null) { |
ohair@286 | 303 | JAnnotationUse resW = m.annotate(javax.xml.ws.ResponseWrapper.class); |
ohair@286 | 304 | Block resBlock = response.getBodyBlocks().next(); |
ohair@286 | 305 | resW.param("localName", resBlock.getName().getLocalPart()); |
ohair@286 | 306 | resW.param("targetNamespace", resBlock.getName().getNamespaceURI()); |
ohair@286 | 307 | resW.param("className", resBlock.getType().getJavaType().getName()); |
ohair@286 | 308 | } |
ohair@286 | 309 | } |
ohair@286 | 310 | } |
ohair@286 | 311 | |
ohair@286 | 312 | private boolean isMessageParam(Parameter param, Message message) { |
ohair@286 | 313 | Block block = param.getBlock(); |
ohair@286 | 314 | |
ohair@286 | 315 | return (message.getBodyBlockCount() > 0 && block.equals(message.getBodyBlocks().next())) || |
ohair@286 | 316 | (message.getHeaderBlockCount() > 0 && |
ohair@286 | 317 | block.equals(message.getHeaderBlocks().next())); |
ohair@286 | 318 | } |
ohair@286 | 319 | |
ohair@286 | 320 | private boolean isHeaderParam(Parameter param, Message message) { |
ohair@286 | 321 | if (message.getHeaderBlockCount() == 0) |
ohair@286 | 322 | return false; |
ohair@286 | 323 | |
ohair@286 | 324 | for (Block headerBlock : message.getHeaderBlocksMap().values()) |
ohair@286 | 325 | if (param.getBlock().equals(headerBlock)) |
ohair@286 | 326 | return true; |
ohair@286 | 327 | |
ohair@286 | 328 | return false; |
ohair@286 | 329 | } |
ohair@286 | 330 | |
ohair@286 | 331 | private boolean isAttachmentParam(Parameter param, Message message){ |
ohair@286 | 332 | if (message.getAttachmentBlockCount() == 0) |
ohair@286 | 333 | return false; |
ohair@286 | 334 | |
ohair@286 | 335 | for (Block attBlock : message.getAttachmentBlocksMap().values()) |
ohair@286 | 336 | if (param.getBlock().equals(attBlock)) |
ohair@286 | 337 | return true; |
ohair@286 | 338 | |
ohair@286 | 339 | return false; |
ohair@286 | 340 | } |
ohair@286 | 341 | |
ohair@286 | 342 | private boolean isUnboundParam(Parameter param, Message message){ |
ohair@286 | 343 | if (message.getUnboundBlocksCount() == 0) |
ohair@286 | 344 | return false; |
ohair@286 | 345 | |
ohair@286 | 346 | for (Block unboundBlock : message.getUnboundBlocksMap().values()) |
ohair@286 | 347 | if (param.getBlock().equals(unboundBlock)) |
ohair@286 | 348 | return true; |
ohair@286 | 349 | |
ohair@286 | 350 | return false; |
ohair@286 | 351 | } |
ohair@286 | 352 | |
ohair@286 | 353 | private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) { |
ohair@286 | 354 | Parameter param = javaParameter.getParameter(); |
ohair@286 | 355 | Request req = operation.getRequest(); |
ohair@286 | 356 | Response res = operation.getResponse(); |
ohair@286 | 357 | |
ohair@286 | 358 | boolean header = isHeaderParam(param, req) || |
ohair@286 | 359 | (res != null && isHeaderParam(param, res)); |
ohair@286 | 360 | |
ohair@286 | 361 | String name; |
ohair@286 | 362 | boolean isWrapped = operation.isWrapped(); |
ohair@286 | 363 | |
ohair@286 | 364 | if((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) |
ohair@286 | 365 | name = param.getBlock().getName().getLocalPart(); |
ohair@286 | 366 | else |
ohair@286 | 367 | name = param.getName(); |
ohair@286 | 368 | |
ohair@286 | 369 | paramAnno.param("name", name); |
ohair@286 | 370 | |
ohair@286 | 371 | String ns= null; |
ohair@286 | 372 | |
ohair@286 | 373 | if (isDocStyle) { |
ohair@286 | 374 | ns = param.getBlock().getName().getNamespaceURI(); // its bare nsuri |
ohair@286 | 375 | if(isWrapped){ |
ohair@286 | 376 | ns = param.getType().getName().getNamespaceURI(); |
ohair@286 | 377 | } |
ohair@286 | 378 | }else if(header){ |
ohair@286 | 379 | ns = param.getBlock().getName().getNamespaceURI(); |
ohair@286 | 380 | } |
ohair@286 | 381 | |
ohair@286 | 382 | if((ns != null) && (!ns.equals(serviceNS) || (isDocStyle && isWrapped))) |
ohair@286 | 383 | paramAnno.param("targetNamespace", ns); |
ohair@286 | 384 | |
ohair@286 | 385 | if (header) { |
ohair@286 | 386 | paramAnno.param("header", true); |
ohair@286 | 387 | } |
ohair@286 | 388 | |
ohair@286 | 389 | if (param.isINOUT()){ |
ohair@286 | 390 | paramAnno.param("mode", javax.jws.WebParam.Mode.INOUT); |
ohair@286 | 391 | }else if ((res != null) && (isMessageParam(param, res) || isHeaderParam(param, res) || isAttachmentParam(param, res) || |
ohair@286 | 392 | isUnboundParam(param,res) || param.isOUT())){ |
ohair@286 | 393 | paramAnno.param("mode", javax.jws.WebParam.Mode.OUT); |
ohair@286 | 394 | } |
ohair@286 | 395 | |
ohair@286 | 396 | //doclit wrapped could have additional headers |
ohair@286 | 397 | if(!(isDocStyle && isWrapped) || header) |
ohair@286 | 398 | paramAnno.param("partName", javaParameter.getParameter().getName()); |
ohair@286 | 399 | } |
ohair@286 | 400 | |
ohair@286 | 401 | private boolean isDocStyle = true; |
ohair@286 | 402 | private boolean sameParamStyle = true; |
ohair@286 | 403 | private void writeSOAPBinding(Port port, JDefinedClass cls) { |
ohair@286 | 404 | JAnnotationUse soapBindingAnn = null; |
ohair@286 | 405 | isDocStyle = port.getStyle() == null || port.getStyle().equals(SOAPStyle.DOCUMENT); |
ohair@286 | 406 | if(!isDocStyle){ |
ohair@286 | 407 | soapBindingAnn = cls.annotate(SOAPBinding.class); |
ohair@286 | 408 | soapBindingAnn.param("style", SOAPBinding.Style.RPC); |
ohair@286 | 409 | port.setWrapped(true); |
ohair@286 | 410 | } |
ohair@286 | 411 | if(isDocStyle){ |
ohair@286 | 412 | boolean first = true; |
ohair@286 | 413 | boolean isWrapper = true; |
ohair@286 | 414 | for(Operation operation:port.getOperations()){ |
ohair@286 | 415 | if(first){ |
ohair@286 | 416 | isWrapper = operation.isWrapped(); |
ohair@286 | 417 | first = false; |
ohair@286 | 418 | continue; |
ohair@286 | 419 | } |
ohair@286 | 420 | sameParamStyle = (isWrapper == operation.isWrapped()); |
ohair@286 | 421 | if(!sameParamStyle) |
ohair@286 | 422 | break; |
ohair@286 | 423 | } |
ohair@286 | 424 | if(sameParamStyle) |
ohair@286 | 425 | port.setWrapped(isWrapper); |
ohair@286 | 426 | } |
ohair@286 | 427 | if(sameParamStyle && !port.isWrapped()){ |
ohair@286 | 428 | if(soapBindingAnn == null) |
ohair@286 | 429 | soapBindingAnn = cls.annotate(SOAPBinding.class); |
ohair@286 | 430 | soapBindingAnn.param("parameterStyle", SOAPBinding.ParameterStyle.BARE); |
ohair@286 | 431 | } |
ohair@286 | 432 | } |
ohair@286 | 433 | |
ohair@286 | 434 | private void writeWebServiceAnnotation(Port port, JAnnotationUse wsa) { |
ohair@286 | 435 | QName name = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); |
ohair@286 | 436 | wsa.param("name", name.getLocalPart()); |
ohair@286 | 437 | wsa.param("targetNamespace", name.getNamespaceURI()); |
ohair@286 | 438 | } |
ohair@286 | 439 | |
ohair@286 | 440 | |
ohair@286 | 441 | |
ohair@286 | 442 | |
ohair@286 | 443 | public void visit(Model model) throws Exception { |
ohair@286 | 444 | for(Service s:model.getServices()){ |
ohair@286 | 445 | s.accept(this); |
ohair@286 | 446 | } |
ohair@286 | 447 | } |
ohair@286 | 448 | |
ohair@286 | 449 | public void visit(Service service) throws Exception { |
ohair@286 | 450 | String jd = model.getJavaDoc(); |
ohair@286 | 451 | if(jd != null){ |
ohair@286 | 452 | JPackage pkg = cm._package(options.defaultPackage); |
ohair@286 | 453 | pkg.javadoc().add(jd); |
ohair@286 | 454 | } |
ohair@286 | 455 | |
ohair@286 | 456 | for(Port p:service.getPorts()){ |
ohair@286 | 457 | visitPort(service, p); |
ohair@286 | 458 | } |
ohair@286 | 459 | } |
ohair@286 | 460 | |
ohair@286 | 461 | private void visitPort(Service service, Port port) { |
ohair@286 | 462 | if (port.isProvider()) { |
ohair@286 | 463 | return; // Not generating for Provider based endpoint |
ohair@286 | 464 | } |
ohair@286 | 465 | write(port); |
ohair@286 | 466 | } |
ohair@286 | 467 | |
ohair@286 | 468 | private void register(TJavaGeneratorExtension h) { |
ohair@286 | 469 | extensionHandlers.add(h); |
ohair@286 | 470 | } |
ohair@286 | 471 | } |