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

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
34 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType; 34 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType;
35 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation; 35 import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
36 import com.sun.tools.internal.ws.wscompile.ErrorReceiver; 36 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
37 import com.sun.tools.internal.ws.wscompile.Options; 37 import com.sun.tools.internal.ws.wscompile.Options;
38 import com.sun.tools.internal.ws.wscompile.WsimportOptions; 38 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
39 import com.sun.tools.internal.ws.wscompile.AbortException;
40 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle; 39 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
41 import com.sun.tools.internal.ws.wsdl.document.PortType; 40 import com.sun.tools.internal.ws.wsdl.document.PortType;
42 import com.sun.tools.internal.ws.wsdl.document.Kinds;
43 import com.sun.tools.internal.ws.resources.GeneratorMessages; 41 import com.sun.tools.internal.ws.resources.GeneratorMessages;
44 42
45 import javax.jws.WebMethod; 43 import javax.jws.WebMethod;
46 import javax.jws.WebParam; 44 import javax.jws.WebParam;
47 import javax.jws.WebService; 45 import javax.jws.WebService;
53 import java.util.List; 51 import java.util.List;
54 52
55 import org.xml.sax.Locator; 53 import org.xml.sax.Locator;
56 54
57 public class SeiGenerator extends GeneratorBase { 55 public class SeiGenerator extends GeneratorBase {
58 private String serviceNS;
59 private TJavaGeneratorExtension extension; 56 private TJavaGeneratorExtension extension;
60 private List<TJavaGeneratorExtension> extensionHandlers; 57 private List<TJavaGeneratorExtension> extensionHandlers;
61 58
62 public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions){ 59 public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions){
63 SeiGenerator seiGenerator = new SeiGenerator(); 60 SeiGenerator seiGenerator = new SeiGenerator();
74 // 2.2 Spec requires generation of @Action when wsam:Action is explicitly stated in wsdl 71 // 2.2 Spec requires generation of @Action when wsam:Action is explicitly stated in wsdl
75 if (options.target.isLaterThan(Options.Target.V2_2)) { 72 if (options.target.isLaterThan(Options.Target.V2_2)) {
76 register(new W3CAddressingJavaGeneratorExtension()); 73 register(new W3CAddressingJavaGeneratorExtension());
77 } 74 }
78 75
79 for (TJavaGeneratorExtension j : extensions) 76 for (TJavaGeneratorExtension j : extensions) {
80 register(j); 77 register(j);
81 78 }
82 this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[0])); 79
80 this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[extensionHandlers.size()]));
83 } 81 }
84 82
85 private void write(Port port) { 83 private void write(Port port) {
86 JavaInterface intf = port.getJavaInterface(); 84 JavaInterface intf = port.getJavaInterface();
87 String className = Names.customJavaTypeClassName(intf); 85 String className = Names.customJavaTypeClassName(intf);
90 log("Class " + className + " exists. Not overriding."); 88 log("Class " + className + " exists. Not overriding.");
91 return; 89 return;
92 } 90 }
93 91
94 92
95 JDefinedClass cls = null; 93 JDefinedClass cls;
96 try { 94 try {
97 cls = getClass(className, ClassType.INTERFACE); 95 cls = getClass(className, ClassType.INTERFACE);
98 } catch (JClassAlreadyExistsException e) { 96 } catch (JClassAlreadyExistsException e) {
99 QName portTypeName = 97 QName portTypeName =
100 (QName) port.getProperty( 98 (QName) port.getProperty(
101 ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); 99 ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
102 Locator loc = null; 100 Locator loc = null;
103 if(portTypeName != null){ 101 if(portTypeName != null){
104 PortType pt = port.portTypes.get(portTypeName); 102 PortType pt = port.portTypes.get(portTypeName);
105 if(pt!=null) 103 if (pt!=null) {
106 loc = pt.getLocator(); 104 loc = pt.getLocator();
105 }
107 } 106 }
108 receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName)); 107 receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
109 return; 108 return;
110 } 109 }
111 // If the class has methods it has already been defined 110 // If the class has methods it has already been defined
112 // so skip it. 111 // so skip it.
113 if (!cls.methods().isEmpty()) 112 if (!cls.methods().isEmpty()) {
114 return; 113 return;
114 }
115 115
116 //write class comment - JAXWS warning 116 //write class comment - JAXWS warning
117 JDocComment comment = cls.javadoc(); 117 JDocComment comment = cls.javadoc();
118 118
119 String ptDoc = intf.getJavaDoc(); 119 String ptDoc = intf.getJavaDoc();
136 136
137 //@SOAPBinding 137 //@SOAPBinding
138 writeSOAPBinding(port, cls); 138 writeSOAPBinding(port, cls);
139 139
140 //@XmlSeeAlso 140 //@XmlSeeAlso
141 if(options.target.isLaterThan(Options.Target.V2_1)) 141 if (options.target.isLaterThan(Options.Target.V2_1)) {
142 writeXmlSeeAlso(cls); 142 writeXmlSeeAlso(cls);
143 }
143 144
144 for (Operation operation: port.getOperations()) { 145 for (Operation operation: port.getOperations()) {
145 JavaMethod method = operation.getJavaMethod(); 146 JavaMethod method = operation.getJavaMethod();
146 147
147 //@WebMethod 148 //@WebMethod
157 retType.annotate(m); 158 retType.annotate(m);
158 methodDoc = m.javadoc(); 159 methodDoc = m.javadoc();
159 JCommentPart ret = methodDoc.addReturn(); 160 JCommentPart ret = methodDoc.addReturn();
160 ret.add("returns "+retType.getName()); 161 ret.add("returns "+retType.getName());
161 } 162 }
162 if(methodJavaDoc != null) 163 if (methodJavaDoc != null) {
163 methodDoc.add(methodJavaDoc); 164 methodDoc.add(methodJavaDoc);
165 }
164 166
165 writeWebMethod(operation, m); 167 writeWebMethod(operation, m);
166 JClass holder = cm.ref(Holder.class); 168 JClass holder = cm.ref(Holder.class);
167 for (JavaParameter parameter: method.getParametersList()) { 169 for (JavaParameter parameter: method.getParametersList()) {
168 JVar var; 170 JVar var;
194 private void writeXmlSeeAlso(JDefinedClass cls) { 196 private void writeXmlSeeAlso(JDefinedClass cls) {
195 if (model.getJAXBModel().getS2JJAXBModel() != null) { 197 if (model.getJAXBModel().getS2JJAXBModel() != null) {
196 List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories(); 198 List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories();
197 199
198 //if there are no object facotires, dont generate @XmlSeeAlso 200 //if there are no object facotires, dont generate @XmlSeeAlso
199 if(objectFactories.size() == 0) 201 if (objectFactories.isEmpty()) {
200 return; 202 return;
203 }
201 204
202 JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class)); 205 JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class));
203 JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value"); 206 JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value");
204 for (JClass of : objectFactories) { 207 for (JClass of : objectFactories) {
205 paramArray = paramArray.param(of); 208 paramArray = paramArray.param(of);
259 262
260 if(!resultName.equals("return")){ 263 if(!resultName.equals("return")){
261 wr = m.annotate(javax.jws.WebResult.class); 264 wr = m.annotate(javax.jws.WebResult.class);
262 wr.param("name", resultName); 265 wr.param("name", resultName);
263 } 266 }
264 if((nsURI != null) && (!nsURI.equals(serviceNS) || (isDocStyle && operation.isWrapped()))){ 267 if (nsURI != null || (isDocStyle && operation.isWrapped())) {
265 if(wr == null) 268 if(wr == null) {
266 wr = m.annotate(javax.jws.WebResult.class); 269 wr = m.annotate(javax.jws.WebResult.class);
270 }
267 wr.param("targetNamespace", nsURI); 271 wr.param("targetNamespace", nsURI);
268 } 272 }
269 //doclit wrapped could have additional headers 273 //doclit wrapped could have additional headers
270 if(!(isDocStyle && operation.isWrapped()) || 274 if(!(isDocStyle && operation.isWrapped()) ||
271 (parameter.getBlock().getLocation() == Block.HEADER)){ 275 (parameter.getBlock().getLocation() == Block.HEADER)){
272 if(wr == null) 276 if (wr == null) {
273 wr = m.annotate(javax.jws.WebResult.class); 277 wr = m.annotate(javax.jws.WebResult.class);
278 }
274 wr.param("partName", parameter.getName()); 279 wr.param("partName", parameter.getName());
275 } 280 }
276 if(parameter.getBlock().getLocation() == Block.HEADER){ 281 if(parameter.getBlock().getLocation() == Block.HEADER){
277 if(wr == null) 282 if (wr == null) {
278 wr = m.annotate(javax.jws.WebResult.class); 283 wr = m.annotate(javax.jws.WebResult.class);
284 }
279 wr.param("header",true); 285 wr.param("header",true);
280 } 286 }
281 } 287 }
282 } 288 }
283 289
316 (message.getHeaderBlockCount() > 0 && 322 (message.getHeaderBlockCount() > 0 &&
317 block.equals(message.getHeaderBlocks().next())); 323 block.equals(message.getHeaderBlocks().next()));
318 } 324 }
319 325
320 private boolean isHeaderParam(Parameter param, Message message) { 326 private boolean isHeaderParam(Parameter param, Message message) {
321 if (message.getHeaderBlockCount() == 0) 327 if (message.getHeaderBlockCount() == 0) {
322 return false; 328 return false;
323 329 }
324 for (Block headerBlock : message.getHeaderBlocksMap().values()) 330
325 if (param.getBlock().equals(headerBlock)) 331 for (Block headerBlock : message.getHeaderBlocksMap().values()) {
332 if (param.getBlock().equals(headerBlock)) {
326 return true; 333 return true;
334 }
335 }
327 336
328 return false; 337 return false;
329 } 338 }
330 339
331 private boolean isAttachmentParam(Parameter param, Message message){ 340 private boolean isAttachmentParam(Parameter param, Message message){
332 if (message.getAttachmentBlockCount() == 0) 341 if (message.getAttachmentBlockCount() == 0) {
333 return false; 342 return false;
334 343 }
335 for (Block attBlock : message.getAttachmentBlocksMap().values()) 344
336 if (param.getBlock().equals(attBlock)) 345 for (Block attBlock : message.getAttachmentBlocksMap().values()) {
346 if (param.getBlock().equals(attBlock)) {
337 return true; 347 return true;
348 }
349 }
338 350
339 return false; 351 return false;
340 } 352 }
341 353
342 private boolean isUnboundParam(Parameter param, Message message){ 354 private boolean isUnboundParam(Parameter param, Message message){
343 if (message.getUnboundBlocksCount() == 0) 355 if (message.getUnboundBlocksCount() == 0) {
344 return false; 356 return false;
345 357 }
346 for (Block unboundBlock : message.getUnboundBlocksMap().values()) 358
347 if (param.getBlock().equals(unboundBlock)) 359 for (Block unboundBlock : message.getUnboundBlocksMap().values()) {
360 if (param.getBlock().equals(unboundBlock)) {
348 return true; 361 return true;
362 }
363 }
349 364
350 return false; 365 return false;
351 } 366 }
352 367
353 private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) { 368 private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) {
359 (res != null && isHeaderParam(param, res)); 374 (res != null && isHeaderParam(param, res));
360 375
361 String name; 376 String name;
362 boolean isWrapped = operation.isWrapped(); 377 boolean isWrapped = operation.isWrapped();
363 378
364 if((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) 379 if ((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) {
365 name = param.getBlock().getName().getLocalPart(); 380 name = param.getBlock().getName().getLocalPart();
366 else 381 } else {
367 name = param.getName(); 382 name = param.getName();
383 }
368 384
369 paramAnno.param("name", name); 385 paramAnno.param("name", name);
370 386
371 String ns= null; 387 String ns= null;
372 388
377 } 393 }
378 }else if(header){ 394 }else if(header){
379 ns = param.getBlock().getName().getNamespaceURI(); 395 ns = param.getBlock().getName().getNamespaceURI();
380 } 396 }
381 397
382 if((ns != null) && (!ns.equals(serviceNS) || (isDocStyle && isWrapped))) 398 if (ns != null || (isDocStyle && isWrapped)) {
383 paramAnno.param("targetNamespace", ns); 399 paramAnno.param("targetNamespace", ns);
400 }
384 401
385 if (header) { 402 if (header) {
386 paramAnno.param("header", true); 403 paramAnno.param("header", true);
387 } 404 }
388 405
392 isUnboundParam(param,res) || param.isOUT())){ 409 isUnboundParam(param,res) || param.isOUT())){
393 paramAnno.param("mode", javax.jws.WebParam.Mode.OUT); 410 paramAnno.param("mode", javax.jws.WebParam.Mode.OUT);
394 } 411 }
395 412
396 //doclit wrapped could have additional headers 413 //doclit wrapped could have additional headers
397 if(!(isDocStyle && isWrapped) || header) 414 if (!(isDocStyle && isWrapped) || header) {
398 paramAnno.param("partName", javaParameter.getParameter().getName()); 415 paramAnno.param("partName", javaParameter.getParameter().getName());
416 }
399 } 417 }
400 418
401 private boolean isDocStyle = true; 419 private boolean isDocStyle = true;
402 private boolean sameParamStyle = true; 420 private boolean sameParamStyle = true;
403 private void writeSOAPBinding(Port port, JDefinedClass cls) { 421 private void writeSOAPBinding(Port port, JDefinedClass cls) {
416 isWrapper = operation.isWrapped(); 434 isWrapper = operation.isWrapped();
417 first = false; 435 first = false;
418 continue; 436 continue;
419 } 437 }
420 sameParamStyle = (isWrapper == operation.isWrapped()); 438 sameParamStyle = (isWrapper == operation.isWrapped());
421 if(!sameParamStyle) 439 if (!sameParamStyle) {
422 break; 440 break;
423 } 441 }
424 if(sameParamStyle) 442 }
443 if (sameParamStyle) {
425 port.setWrapped(isWrapper); 444 port.setWrapped(isWrapper);
445 }
426 } 446 }
427 if(sameParamStyle && !port.isWrapped()){ 447 if(sameParamStyle && !port.isWrapped()){
428 if(soapBindingAnn == null) 448 if (soapBindingAnn == null) {
429 soapBindingAnn = cls.annotate(SOAPBinding.class); 449 soapBindingAnn = cls.annotate(SOAPBinding.class);
450 }
430 soapBindingAnn.param("parameterStyle", SOAPBinding.ParameterStyle.BARE); 451 soapBindingAnn.param("parameterStyle", SOAPBinding.ParameterStyle.BARE);
431 } 452 }
432 } 453 }
433 454
434 private void writeWebServiceAnnotation(Port port, JAnnotationUse wsa) { 455 private void writeWebServiceAnnotation(Port port, JAnnotationUse wsa) {
435 QName name = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); 456 QName name = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
436 wsa.param("name", name.getLocalPart()); 457 wsa.param("name", name.getLocalPart());
437 wsa.param("targetNamespace", name.getNamespaceURI()); 458 wsa.param("targetNamespace", name.getNamespaceURI());
438 } 459 }
439 460
440 461 @Override
441
442
443 public void visit(Model model) throws Exception { 462 public void visit(Model model) throws Exception {
444 for(Service s:model.getServices()){ 463 for(Service s:model.getServices()){
445 s.accept(this); 464 s.accept(this);
446 } 465 }
447 } 466 }
448 467
468 @Override
449 public void visit(Service service) throws Exception { 469 public void visit(Service service) throws Exception {
450 String jd = model.getJavaDoc(); 470 String jd = model.getJavaDoc();
451 if(jd != null){ 471 if(jd != null){
452 JPackage pkg = cm._package(options.defaultPackage); 472 JPackage pkg = cm._package(options.defaultPackage);
453 pkg.javadoc().add(jd); 473 pkg.javadoc().add(jd);

mercurial