Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.internal.ws.processor.modeler.wsdl;
28 import com.sun.codemodel.internal.JType;
29 import com.sun.istack.internal.SAXParseException2;
30 import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
31 import com.sun.tools.internal.ws.processor.generator.Names;
32 import com.sun.tools.internal.ws.processor.model.*;
33 import com.sun.tools.internal.ws.processor.model.Fault;
34 import com.sun.tools.internal.ws.processor.model.Operation;
35 import com.sun.tools.internal.ws.processor.model.Port;
36 import com.sun.tools.internal.ws.processor.model.Service;
37 import com.sun.tools.internal.ws.processor.model.java.*;
38 import com.sun.tools.internal.ws.processor.model.jaxb.*;
39 import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
40 import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
41 import com.sun.tools.internal.ws.resources.ModelerMessages;
42 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
43 import com.sun.tools.internal.ws.wscompile.WsimportOptions;
44 import com.sun.tools.internal.ws.wsdl.document.*;
45 import com.sun.tools.internal.ws.wsdl.document.Message;
46 import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
47 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
48 import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
49 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
50 import com.sun.tools.internal.ws.wsdl.document.soap.*;
51 import com.sun.tools.internal.ws.wsdl.framework.*;
52 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
53 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
54 import com.sun.tools.internal.xjc.api.S2JJAXBModel;
55 import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
56 import com.sun.tools.internal.xjc.api.XJC;
57 import com.sun.xml.internal.ws.spi.db.BindingContext;
58 import com.sun.xml.internal.ws.spi.db.BindingHelper;
59 import com.sun.xml.internal.ws.util.xml.XmlUtil;
60 import org.xml.sax.InputSource;
61 import org.xml.sax.Locator;
62 import org.xml.sax.SAXException;
63 import org.xml.sax.SAXParseException;
64 import org.xml.sax.helpers.LocatorImpl;
66 import javax.jws.WebParam.Mode;
67 import javax.xml.namespace.QName;
68 import java.util.*;
69 import java.io.IOException;
72 /**
73 * The WSDLModeler processes a WSDL to create a Model.
74 *
75 * @author WS Development Team
76 */
77 public class WSDLModeler extends WSDLModelerBase {
79 //map of wsdl:operation QName to <soapenv:Body> child, as per BP it must be unique in a port
80 private final Map<QName, Operation> uniqueBodyBlocks = new HashMap<QName, Operation>();
81 private final QName VOID_BODYBLOCK = new QName("");
82 private final ClassNameCollector classNameCollector;
83 private final String explicitDefaultPackage;
85 public WSDLModeler(WsimportOptions options, ErrorReceiver receiver, MetadataFinder forest) {
86 super(options, receiver,forest);
87 this.classNameCollector = new ClassNameCollector();
88 this.explicitDefaultPackage = options.defaultPackage;
89 }
92 protected enum StyleAndUse {
93 RPC_LITERAL, DOC_LITERAL
94 }
96 private JAXBModelBuilder jaxbModelBuilder;
98 public Model buildModel() {
99 try {
100 parser = new WSDLParser(options, errReceiver, forest);
101 parser.addParserListener(new ParserListener() {
102 public void ignoringExtension(Entity entity, QName name, QName parent) {
103 if (parent.equals(WSDLConstants.QNAME_TYPES)) {
104 // check for a schema element with the wrong namespace URI
105 if (name.getLocalPart().equals("schema")
106 && !name.getNamespaceURI().equals("")) {
107 warning(entity, ModelerMessages.WSDLMODELER_WARNING_IGNORING_UNRECOGNIZED_SCHEMA_EXTENSION(name.getNamespaceURI()));
108 }
109 }
111 }
113 public void doneParsingEntity(QName element, Entity entity) {
114 }
115 });
117 document = parser.parse();
118 if (document == null || document.getDefinitions() == null)
119 return null;
121 document.validateLocally();
122 Model model = internalBuildModel(document);
123 if(model == null || errReceiver.hadError())
124 return null;
125 //ClassNameCollector classNameCollector = new ClassNameCollector();
126 classNameCollector.process(model);
127 if (classNameCollector.getConflictingClassNames().isEmpty()) {
128 if(errReceiver.hadError())
129 return null;
130 return model;
131 }
132 // do another pass, this time with conflict resolution enabled
133 model = internalBuildModel(document);
135 classNameCollector.process(model);
136 if (classNameCollector.getConflictingClassNames().isEmpty()) {
137 // we're done
138 if(errReceiver.hadError())
139 return null;
140 return model;
141 }
142 // give up
143 StringBuffer conflictList = new StringBuffer();
144 boolean first = true;
145 for (Iterator iter =
146 classNameCollector.getConflictingClassNames().iterator();
147 iter.hasNext();
148 ) {
149 if (!first) {
150 conflictList.append(", ");
151 } else {
152 first = false;
153 }
154 conflictList.append((String) iter.next());
155 }
156 error(document.getDefinitions(), ModelerMessages.WSDLMODELER_UNSOLVABLE_NAMING_CONFLICTS(conflictList.toString()));
157 } catch (ModelException e) {
158 reportError(document.getDefinitions(), e.getMessage(), e);
159 } catch (ParseException e) {
160 errReceiver.error(e);
161 } catch (ValidationException e) {
162 errReceiver.error(e.getMessage(), e);
163 } catch (SAXException e) {
164 errReceiver.error(e);
165 } catch (IOException e) {
166 errReceiver.error(e);
167 }
168 //should never reach here
169 return null;
170 }
172 private Model internalBuildModel(WSDLDocument document) {
173 numPasses++;
175 //build the jaxbModel to be used latter
176 buildJAXBModel(document);
178 QName modelName =
179 new QName(
180 document.getDefinitions().getTargetNamespaceURI(),
181 document.getDefinitions().getName() == null
182 ? "model"
183 : document.getDefinitions().getName());
184 Model model = new Model(modelName, document.getDefinitions());
185 model.setJAXBModel(getJAXBModelBuilder().getJAXBModel());
187 // This fails with the changed classname (WSDLModeler to WSDLModeler11 etc.)
188 // with this source comaptibility change the WSDL Modeler class name is changed. Right now hardcoding the
189 // modeler class name to the same one being checked in WSDLGenerator.
191 model.setProperty(
192 ModelProperties.PROPERTY_MODELER_NAME,
193 ModelProperties.WSDL_MODELER_NAME);
195 _javaExceptions = new HashMap<String, JavaException>();
196 _bindingNameToPortMap = new HashMap<QName, Port>();
198 // grab target namespace
199 model.setTargetNamespaceURI(document.getDefinitions().getTargetNamespaceURI());
201 setDocumentationIfPresent(model,
202 document.getDefinitions().getDocumentation());
204 boolean hasServices = document.getDefinitions().services().hasNext();
205 if (hasServices) {
206 for (Iterator iter = document.getDefinitions().services();
207 iter.hasNext();
208 ) {
209 processService((com.sun.tools.internal.ws.wsdl.document.Service) iter.next(),
210 model, document);
211 hasServices = true;
212 }
213 } else {
214 // emit a warning if there are no service definitions
215 warning(model.getEntity(), ModelerMessages.WSDLMODELER_WARNING_NO_SERVICE_DEFINITIONS_FOUND());
216 }
218 return model;
219 }
221 /* (non-Javadoc)
222 * @see WSDLModelerBase#processService(Service, Model, WSDLDocument)
223 */
224 protected void processService(com.sun.tools.internal.ws.wsdl.document.Service wsdlService, Model model, WSDLDocument document) {
225 QName serviceQName = getQNameOf(wsdlService);
226 String serviceInterface = getServiceInterfaceName(serviceQName, wsdlService);
227 if (isConflictingServiceClassName(serviceInterface)) {
228 serviceInterface += "_Service";
229 }
230 Service service =
231 new Service(
232 serviceQName,
233 new JavaInterface(serviceInterface, serviceInterface + "Impl"), wsdlService);
235 setDocumentationIfPresent(service, wsdlService.getDocumentation());
236 boolean hasPorts = false;
237 for (Iterator iter = wsdlService.ports(); iter.hasNext();) {
238 boolean processed =
239 processPort(
240 (com.sun.tools.internal.ws.wsdl.document.Port) iter.next(),
241 service,
242 document);
243 hasPorts = hasPorts || processed;
244 }
245 if (!hasPorts) {
246 // emit a warning if there are no ports
247 warning(wsdlService, ModelerMessages.WSDLMODELER_WARNING_NO_PORTS_IN_SERVICE(wsdlService.getName()));
248 } else {
249 model.addService(service);
250 }
251 }
253 /* (non-Javadoc)
254 * @see WSDLModelerBase#processPort(WSDLPort, Service, WSDLDocument)
255 */
256 protected boolean processPort(com.sun.tools.internal.ws.wsdl.document.Port wsdlPort,
257 Service service, WSDLDocument document) {
258 try {
260 //clear the unique block map
261 uniqueBodyBlocks.clear();
263 QName portQName = getQNameOf(wsdlPort);
264 Port port = new Port(portQName, wsdlPort);
266 setDocumentationIfPresent(port, wsdlPort.getDocumentation());
268 SOAPAddress soapAddress =
269 (SOAPAddress) getExtensionOfType(wsdlPort, SOAPAddress.class);
270 if (soapAddress == null) {
271 if(options.isExtensionMode()){
272 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_SOAP_ADDRESS(wsdlPort.getName()));
273 }else{
274 // not a SOAP port, ignore it
275 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT_NO_ADDRESS(wsdlPort.getName()));
276 return false;
277 }
278 }
279 if(soapAddress != null)
280 port.setAddress(soapAddress.getLocation());
281 Binding binding = wsdlPort.resolveBinding(document);
282 QName bindingName = getQNameOf(binding);
283 PortType portType = binding.resolvePortType(document);
285 port.setProperty(
286 ModelProperties.PROPERTY_WSDL_PORT_NAME,
287 getQNameOf(wsdlPort));
288 port.setProperty(
289 ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
290 getQNameOf(portType));
291 port.setProperty(
292 ModelProperties.PROPERTY_WSDL_BINDING_NAME,
293 bindingName);
295 boolean isProvider = isProvider(wsdlPort);
296 if (_bindingNameToPortMap.containsKey(bindingName) && !isProvider) {
297 // this binding has been processed before
298 Port existingPort =
299 _bindingNameToPortMap.get(bindingName);
300 port.setOperations(existingPort.getOperations());
301 port.setJavaInterface(existingPort.getJavaInterface());
302 port.setStyle(existingPort.getStyle());
303 port.setWrapped(existingPort.isWrapped());
304 } else {
305 // find out the SOAP binding extension, if any
306 SOAPBinding soapBinding =
307 (SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
309 if (soapBinding == null) {
310 soapBinding =
311 (SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
312 if (soapBinding == null) {
313 if(!options.isExtensionMode()){
314 // cannot deal with non-SOAP ports
315 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT(wsdlPort.getName()));
316 return false;
317 }else{
318 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NON_SOAP_PORT(wsdlPort.getName()));
319 }
320 }else{
321 // we can only do soap1.2 if extensions are on
322 if (options.isExtensionMode()) {
323 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_PORT_SOAP_BINDING_12(wsdlPort.getName()));
324 } else {
325 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_12(wsdlPort.getName()));
326 return false;
327 }
328 }
329 }
331 if (soapBinding != null && (soapBinding.getTransport() == null
332 || (!soapBinding.getTransport().equals(
333 SOAPConstants.URI_SOAP_TRANSPORT_HTTP) && !soapBinding.getTransport().equals(
334 SOAP12Constants.URI_SOAP_TRANSPORT_HTTP)))) {
335 if (!options.isExtensionMode()) {
336 // cannot deal with non-HTTP ports
337 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_NON_HTTP_TRANSPORT(wsdlPort.getName()));
338 return false;
339 }
341 }
343 /**
344 * validate wsdl:binding uniqueness in style, e.g. rpclit or doclit
345 * ref: WSI BP 1.1 R 2705
346 */
347 if (soapBinding != null && !validateWSDLBindingStyle(binding)) {
348 if (options.isExtensionMode()) {
349 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_PORT_SOAP_BINDING_MIXED_STYLE(wsdlPort.getName()));
350 } else {
351 error(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_MIXED_STYLE(wsdlPort.getName()));
352 }
353 }
355 if(soapBinding != null){
356 port.setStyle(soapBinding.getStyle());
357 }
359 boolean hasOverloadedOperations = false;
360 Set<String> operationNames = new HashSet<String>();
361 for (Iterator iter = portType.operations(); iter.hasNext();) {
362 com.sun.tools.internal.ws.wsdl.document.Operation operation =
363 (com.sun.tools.internal.ws.wsdl.document.Operation) iter.next();
365 if (operationNames.contains(operation.getName())) {
366 hasOverloadedOperations = true;
367 break;
368 }
369 operationNames.add(operation.getName());
371 for (Iterator itr = binding.operations();
372 iter.hasNext();
373 ) {
374 BindingOperation bindingOperation =
375 (BindingOperation) itr.next();
376 if (operation
377 .getName()
378 .equals(bindingOperation.getName())) {
379 break;
380 } else if (!itr.hasNext()) {
381 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(operation.getName(), bindingOperation.getName()));
382 }
383 }
384 }
386 Map headers = new HashMap();
387 boolean hasOperations = false;
388 for (Iterator iter = binding.operations(); iter.hasNext();) {
389 BindingOperation bindingOperation =
390 (BindingOperation) iter.next();
392 com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation =
393 null;
394 Set operations =
395 portType.getOperationsNamed(bindingOperation.getName());
396 if (operations.size() == 0) {
397 // the WSDL document is invalid
398 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_IN_PORT_TYPE(bindingOperation.getName(), binding.getName()));
399 } else if (operations.size() == 1) {
400 portTypeOperation =
401 (com.sun.tools.internal.ws.wsdl.document.Operation) operations
402 .iterator()
403 .next();
404 } else {
405 boolean found = false;
406 String expectedInputName =
407 bindingOperation.getInput().getName();
408 String expectedOutputName =
409 bindingOperation.getOutput().getName();
411 for (Iterator iter2 = operations.iterator(); iter2.hasNext();) {
412 com.sun.tools.internal.ws.wsdl.document.Operation candidateOperation =
413 (com.sun.tools.internal.ws.wsdl.document.Operation) iter2
414 .next();
416 if (expectedInputName == null) {
417 // the WSDL document is invalid
418 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_INPUT_NAME(bindingOperation.getName()));
419 }
420 if (expectedOutputName == null) {
421 // the WSDL document is invalid
422 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_OUTPUT_NAME(bindingOperation.getName()));
423 }
424 if (expectedInputName
425 .equals(candidateOperation.getInput().getName())
426 && expectedOutputName.equals(
427 candidateOperation
428 .getOutput()
429 .getName())) {
430 if (found) {
431 // the WSDL document is invalid
432 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_MATCHING_OPERATIONS(bindingOperation.getName(), bindingOperation.getName()));
433 }
434 // got it!
435 found = true;
436 portTypeOperation = candidateOperation;
437 }
438 }
439 if (!found) {
440 // the WSDL document is invalid
441 error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(bindingOperation.getName(), binding.getName()));
442 }
443 }
444 if (!isProvider) {
445 this.info =
446 new ProcessSOAPOperationInfo(
447 port,
448 wsdlPort,
449 portTypeOperation,
450 bindingOperation,
451 soapBinding,
452 document,
453 hasOverloadedOperations,
454 headers);
457 Operation operation;
458 if(soapBinding != null)
459 operation = processSOAPOperation();
460 else{
461 operation = processNonSOAPOperation();
462 }
463 if (operation != null) {
464 port.addOperation(operation);
465 hasOperations = true;
466 }
467 }
468 }
469 if (!isProvider && !hasOperations) {
470 // emit a warning if there are no operations, except when its a provider port
471 warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_OPERATIONS_IN_PORT(wsdlPort.getName()));
472 return false;
473 }
474 createJavaInterfaceForPort(port, isProvider);
475 PortType pt = binding.resolvePortType(document);
476 String jd = (pt.getDocumentation() != null) ? pt.getDocumentation().getContent() : null;
477 port.getJavaInterface().setJavaDoc(jd);
478 _bindingNameToPortMap.put(bindingName, port);
479 }
481 service.addPort(port);
482 applyPortMethodCustomization(port, wsdlPort);
483 applyWrapperStyleCustomization(port, binding.resolvePortType(document));
485 return true;
487 } catch (NoSuchEntityException e) {
488 warning(document.getDefinitions(), e.getMessage());
489 // should not happen
490 return false;
491 }
492 }
494 /**
495 * Returns an operation purely from abstract operation
496 */
497 private Operation processNonSOAPOperation() {
498 Operation operation =
499 new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
501 setDocumentationIfPresent(
502 operation,
503 info.portTypeOperation.getDocumentation());
505 if (info.portTypeOperation.getStyle()
506 != OperationStyle.REQUEST_RESPONSE
507 && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
508 if (options.isExtensionMode()) {
509 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
510 return null;
511 } else {
512 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName(),
513 info.port.resolveBinding(document).resolvePortType(document).getName()));
514 }
515 }
517 boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
518 Message inputMessage = getInputMessage();
519 Request request = new Request(inputMessage, errReceiver);
520 request.setErrorReceiver(errReceiver);
521 info.operation = operation;
522 info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
524 Response response;
526 Message outputMessage = null;
527 if (isRequestResponse) {
528 outputMessage = getOutputMessage();
529 response = new Response(outputMessage, errReceiver);
530 }else{
531 response = new Response(null, errReceiver);
532 }
534 //set the style based on heuristic that message has either all parts defined
535 // using type(RPC) or element(DOCUMENT)
536 setNonSoapStyle(inputMessage, outputMessage);
538 // Process parameterOrder and get the parameterList
539 List<MessagePart> parameterList = getParameterOrder();
541 boolean unwrappable = isUnwrappable();
542 info.operation.setWrapped(unwrappable);
543 List<Parameter> params = getDoclitParameters(request, response, parameterList);
544 if (!validateParameterName(params)) {
545 return null;
546 }
548 // create a definitive list of parameters to match what we'd like to get
549 // in the java interface (which is generated much later), parameterOrder
550 List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
551 for (Parameter param : params) {
552 if (param.isReturn()) {
553 info.operation.setProperty(WSDL_RESULT_PARAMETER, param);
554 response.addParameter(param);
555 continue;
556 }
557 if (param.isIN()) {
558 request.addParameter(param);
559 } else if (param.isOUT()) {
560 response.addParameter(param);
561 } else if (param.isINOUT()) {
562 request.addParameter(param);
563 response.addParameter(param);
564 }
565 definitiveParameterList.add(param);
566 }
568 info.operation.setRequest(request);
570 if (isRequestResponse) {
571 info.operation.setResponse(response);
572 }
574 // faults with duplicate names
575 Set duplicateNames = getDuplicateFaultNames();
577 // handle soap:fault
578 handleLiteralSOAPFault(response, duplicateNames);
579 info.operation.setProperty(
580 WSDL_PARAMETER_ORDER,
581 definitiveParameterList);
583 Binding binding = info.port.resolveBinding(document);
584 PortType portType = binding.resolvePortType(document);
585 if (isAsync(portType, info.portTypeOperation)) {
586 warning(portType, "Can not generate Async methods for non-soap binding!");
587 }
588 return info.operation;
589 }
591 /**
592 * This method is added to fix one of the use case for j2ee se folks, so that we determine
593 * for non_soap wsdl what could be the style - rpc or document based on parts in the message.
594 *
595 * We assume that the message parts could have either all of them with type attribute (RPC)
596 * or element (DOCUMENT)
597 *
598 * Shall this check if parts are mixed and throw error message?
599 */
600 private void setNonSoapStyle(Message inputMessage, Message outputMessage) {
601 SOAPStyle style = SOAPStyle.DOCUMENT;
602 for(MessagePart part:inputMessage.getParts()){
603 if(part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
604 style = SOAPStyle.RPC;
605 else
606 style = SOAPStyle.DOCUMENT;
607 }
609 //check the outputMessage parts
610 if(outputMessage != null){
611 for(MessagePart part:outputMessage.getParts()){
612 if(part.getDescriptorKind() == SchemaKinds.XSD_TYPE)
613 style = SOAPStyle.RPC;
614 else
615 style = SOAPStyle.DOCUMENT;
616 }
617 }
618 info.modelPort.setStyle(style);
619 }
621 /* (non-Javadoc)
622 * @see WSDLModelerBase#processSOAPOperation()
623 */
624 protected Operation processSOAPOperation() {
625 Operation operation =
626 new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
628 setDocumentationIfPresent(
629 operation,
630 info.portTypeOperation.getDocumentation());
632 if (info.portTypeOperation.getStyle()
633 != OperationStyle.REQUEST_RESPONSE
634 && info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
635 if (options.isExtensionMode()) {
636 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
637 return null;
638 } else {
639 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName(),
640 info.port.resolveBinding(document).resolvePortType(document).getName()));
641 }
642 }
644 SOAPStyle soapStyle = info.soapBinding.getStyle();
646 // find out the SOAP operation extension, if any
647 SOAPOperation soapOperation =
648 (SOAPOperation) getExtensionOfType(info.bindingOperation,
649 SOAPOperation.class);
651 if (soapOperation != null) {
652 if (soapOperation.getStyle() != null) {
653 soapStyle = soapOperation.getStyle();
654 }
655 if (soapOperation.getSOAPAction() != null) {
656 operation.setSOAPAction(soapOperation.getSOAPAction());
657 }
658 }
660 operation.setStyle(soapStyle);
662 String uniqueOperationName =
663 getUniqueName(info.portTypeOperation, info.hasOverloadedOperations);
664 if (info.hasOverloadedOperations) {
665 operation.setUniqueName(uniqueOperationName);
666 }
668 info.operation = operation;
669 info.uniqueOperationName = uniqueOperationName;
671 //attachment
672 SOAPBody soapRequestBody = getSOAPRequestBody();
673 if (soapRequestBody == null) {
674 // the WSDL document is invalid
675 error(info.bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
676 }
678 if (soapStyle == SOAPStyle.RPC) {
679 if (soapRequestBody.isEncoded()) {
680 if(options.isExtensionMode()){
681 warning(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
682 processNonSOAPOperation();
683 }else{
684 error(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
685 }
686 }
687 return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
688 }
689 // document style
690 return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
691 }
693 protected Operation processLiteralSOAPOperation(StyleAndUse styleAndUse) {
694 //returns false if the operation name is not acceptable
695 if (!applyOperationNameCustomization())
696 return null;
698 boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
699 Message inputMessage = getInputMessage();
700 Request request = new Request(inputMessage, errReceiver);
701 request.setErrorReceiver(errReceiver);
702 info.operation.setUse(SOAPUse.LITERAL);
703 info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
704 SOAPBody soapRequestBody = getSOAPRequestBody();
705 if ((StyleAndUse.DOC_LITERAL == styleAndUse) && (soapRequestBody.getNamespace() != null)) {
706 warning(soapRequestBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
707 }
710 Response response;
712 SOAPBody soapResponseBody = null;
713 Message outputMessage = null;
714 if (isRequestResponse) {
715 soapResponseBody = getSOAPResponseBody();
716 if (isOperationDocumentLiteral(styleAndUse) && (soapResponseBody.getNamespace() != null)) {
717 warning(soapResponseBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
718 }
719 outputMessage = getOutputMessage();
720 response = new Response(outputMessage, errReceiver);
721 }else{
722 response = new Response(null, errReceiver);
723 }
725 //ignore operation if there are more than one root part
726 if (!validateMimeParts(getMimeParts(info.bindingOperation.getInput())) ||
727 !validateMimeParts(getMimeParts(info.bindingOperation.getOutput())))
728 return null;
731 if (!validateBodyParts(info.bindingOperation)) {
732 // BP 1.1
733 // R2204 A document-literal binding in a DESCRIPTION MUST refer, in each of its soapbind:body element(s),
734 // only to wsdl:part element(s) that have been defined using the element attribute.
736 // R2203 An rpc-literal binding in a DESCRIPTION MUST refer, in its soapbind:body element(s),
737 // only to wsdNl:part element(s) that have been defined using the type attribute.
738 if (isOperationDocumentLiteral(styleAndUse))
739 if (options.isExtensionMode())
740 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_TYPE_MESSAGE_PART(info.portTypeOperation.getName()));
741 else
742 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_DOCLITOPERATION(info.portTypeOperation.getName()));
743 else if (isOperationRpcLiteral(styleAndUse)) {
744 if (options.isExtensionMode())
745 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_ELEMENT_MESSAGE_PART(info.portTypeOperation.getName()));
746 else
747 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_RPCLITOPERATION(info.portTypeOperation.getName()));
748 }
749 return null;
750 }
752 // Process parameterOrder and get the parameterList
753 List<MessagePart> parameterList = getParameterOrder();
755 //binding is invalid in the wsdl, ignore the operation.
756 if (!setMessagePartsBinding(styleAndUse))
757 return null;
759 List<Parameter> params = null;
760 boolean unwrappable = isUnwrappable();
761 info.operation.setWrapped(unwrappable);
762 if (isOperationDocumentLiteral(styleAndUse)) {
763 params = getDoclitParameters(request, response, parameterList);
764 } else if (isOperationRpcLiteral(styleAndUse)) {
765 String operationName = info.bindingOperation.getName();
766 Block reqBlock = null;
767 if (inputMessage != null) {
768 QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
769 RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
770 rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
771 reqBlock = new Block(name, rpcStruct, inputMessage);
772 request.addBodyBlock(reqBlock);
773 }
775 Block resBlock = null;
776 if (isRequestResponse && outputMessage != null) {
777 QName name = new QName(getResponseNamespaceURI(soapResponseBody), operationName + "Response");
778 RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
779 rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
780 resBlock = new Block(name, rpcStruct, outputMessage);
781 response.addBodyBlock(resBlock);
782 }
783 params = getRpcLitParameters(request, response, reqBlock, resBlock, parameterList);
784 }
787 if (!validateParameterName(params)) {
788 return null;
789 }
791 // create a definitive list of parameters to match what we'd like to get
792 // in the java interface (which is generated much later), parameterOrder
793 List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
794 for (Parameter param : params) {
795 if (param.isReturn()) {
796 info.operation.setProperty(WSDL_RESULT_PARAMETER, param);
797 response.addParameter(param);
798 continue;
799 }
800 if (param.isIN()) {
801 request.addParameter(param);
802 } else if (param.isOUT()) {
803 response.addParameter(param);
804 } else if (param.isINOUT()) {
805 request.addParameter(param);
806 response.addParameter(param);
807 }
808 definitiveParameterList.add(param);
809 }
811 info.operation.setRequest(request);
813 if (isRequestResponse) {
814 info.operation.setResponse(response);
815 }
817 Iterator<Block> bb = request.getBodyBlocks();
818 QName body;
819 Operation thatOp;
820 if (bb.hasNext()) {
821 body = bb.next().getName();
822 thatOp = uniqueBodyBlocks.get(body);
823 } else {
824 //there is no body block
825 body = VOID_BODYBLOCK;
826 thatOp = uniqueBodyBlocks.get(VOID_BODYBLOCK);
827 }
829 if(thatOp != null){
830 if(options.isExtensionMode()){
831 warning(info.port, ModelerMessages.WSDLMODELER_NON_UNIQUE_BODY_WARNING(info.port.getName(), info.operation.getName(), thatOp.getName(), body));
832 }else{
833 error(info.port, ModelerMessages.WSDLMODELER_NON_UNIQUE_BODY_ERROR(info.port.getName(), info.operation.getName(), thatOp.getName(), body));
834 }
835 }else{
836 uniqueBodyBlocks.put(body, info.operation);
837 }
839 //Add additional headers
840 if (options.additionalHeaders) {
841 List<Parameter> additionalHeaders = new ArrayList<Parameter>();
842 if (inputMessage != null) {
843 for (MessagePart part : getAdditionHeaderParts(info.bindingOperation, inputMessage, true)) {
844 QName name = part.getDescriptor();
845 JAXBType jaxbType = getJAXBType(part);
846 Block block = new Block(name, jaxbType, part);
847 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
848 additionalHeaders.add(param);
849 request.addHeaderBlock(block);
850 request.addParameter(param);
851 definitiveParameterList.add(param);
852 }
853 }
855 if (isRequestResponse && outputMessage != null) {
856 List<Parameter> outParams = new ArrayList<Parameter>();
857 for (MessagePart part : getAdditionHeaderParts(info.bindingOperation,outputMessage, false)) {
858 QName name = part.getDescriptor();
859 JAXBType jaxbType = getJAXBType(part);
860 Block block = new Block(name, jaxbType, part);
861 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
862 param.setMode(Mode.OUT);
863 outParams.add(param);
864 response.addHeaderBlock(block);
865 response.addParameter(param);
866 }
867 for (Parameter outParam : outParams) {
868 for (Parameter inParam : additionalHeaders) {
869 if (inParam.getName().equals(outParam.getName()) &&
870 inParam.getBlock().getName().equals(outParam.getBlock().getName())) {
871 //it is INOUT
872 inParam.setMode(Mode.INOUT);
873 outParam.setMode(Mode.INOUT);
874 break;
875 }
876 }
877 if (outParam.isOUT()) {
878 definitiveParameterList.add(outParam);
879 }
880 }
881 }
882 }
884 // faults with duplicate names
885 Set duplicateNames = getDuplicateFaultNames();
887 // handle soap:fault
888 handleLiteralSOAPFault(response, duplicateNames);
889 info.operation.setProperty(
890 WSDL_PARAMETER_ORDER,
891 definitiveParameterList);
893 //set Async property
894 Binding binding = info.port.resolveBinding(document);
895 PortType portType = binding.resolvePortType(document);
896 if (isAsync(portType, info.portTypeOperation)) {
897 addAsyncOperations(info.operation, styleAndUse);
898 }
900 return info.operation;
901 }
904 private boolean validateParameterName(List<Parameter> params) {
905 if (options.isExtensionMode())
906 return true;
908 Message msg = getInputMessage();
909 for (Parameter param : params) {
910 if (param.isOUT())
911 continue;
912 if (param.getCustomName() != null) {
913 if (Names.isJavaReservedWord(param.getCustomName())) {
914 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
915 return false;
916 }
917 return true;
918 }
919 //process doclit wrapper style
920 if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
921 if (Names.isJavaReservedWord(param.getName())) {
922 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
923 return false;
924 }
925 } else {
926 //non-wrapper style and rpclit
927 if (Names.isJavaReservedWord(param.getName())) {
928 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
929 return false;
930 }
931 }
932 }
934 boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
935 if (isRequestResponse) {
936 msg = getOutputMessage();
937 for (Parameter param : params) {
938 if (param.isIN())
939 continue;
940 if (param.getCustomName() != null) {
941 if (Names.isJavaReservedWord(param.getCustomName())) {
942 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
943 return false;
944 }
945 return true;
946 }
947 //process doclit wrapper style
948 if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
949 if (param.isReturn())
950 continue;
951 if (!param.getName().equals("return") && Names.isJavaReservedWord(param.getName())) {
952 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
953 return false;
954 }
955 } else {
956 if (param.isReturn())
957 continue;
959 //non-wrapper style and rpclit
960 if (Names.isJavaReservedWord(param.getName())) {
961 error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
962 return false;
963 }
964 }
965 }
966 }
968 return true;
969 }
971 private boolean enableMimeContent() {
972 //first we look at binding operation
973 JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.bindingOperation, JAXWSBinding.class);
974 Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
975 if (mimeContentMapping != null)
976 return mimeContentMapping;
978 //then in wsdl:binding
979 Binding binding = info.port.resolveBinding(info.document);
980 jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding, JAXWSBinding.class);
981 mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
982 if (mimeContentMapping != null)
983 return mimeContentMapping;
985 //at last look in wsdl:definitions
986 jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.document.getDefinitions(), JAXWSBinding.class);
987 mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
988 if (mimeContentMapping != null)
989 return mimeContentMapping;
990 return false;
991 }
993 private boolean applyOperationNameCustomization() {
994 JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.portTypeOperation, JAXWSBinding.class);
995 String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization.getMethodName() != null) ? jaxwsCustomization.getMethodName().getName() : null) : null;
996 if (operationName != null) {
997 if (Names.isJavaReservedWord(operationName)) {
998 if (options.isExtensionMode())
999 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
1000 else
1001 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
1002 return false;
1003 }
1005 info.operation.setCustomizedName(operationName);
1006 }
1008 if (Names.isJavaReservedWord(info.operation.getJavaMethodName())) {
1009 if (options.isExtensionMode())
1010 warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
1011 else
1012 error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
1013 return false;
1014 }
1015 return true;
1016 }
1018 protected String getAsyncOperationName(Operation operation) {
1019 String name = operation.getCustomizedName();
1020 if (name == null)
1021 name = operation.getUniqueName();
1022 return name;
1023 }
1025 /**
1026 * @param styleAndUse
1027 */
1028 private void addAsyncOperations(Operation syncOperation, StyleAndUse styleAndUse) {
1029 Operation operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.POLLING);
1030 if (operation != null)
1031 info.modelPort.addOperation(operation);
1033 operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.CALLBACK);
1034 if (operation != null)
1035 info.modelPort.addOperation(operation);
1036 }
1038 private Operation createAsyncOperation(Operation syncOperation, StyleAndUse styleAndUse, AsyncOperationType asyncType) {
1039 boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
1040 if (!isRequestResponse)
1041 return null;
1043 //create async operations
1044 AsyncOperation operation = new AsyncOperation(info.operation, info.bindingOperation);
1046 //creation the async operation name: operationName+Async or customized name
1047 //operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
1048 if (asyncType.equals(AsyncOperationType.CALLBACK))
1049 operation.setUniqueName(info.operation.getUniqueName() + "_async_callback");
1050 else if (asyncType.equals(AsyncOperationType.POLLING))
1051 operation.setUniqueName(info.operation.getUniqueName() + "_async_polling");
1053 setDocumentationIfPresent(
1054 operation,
1055 info.portTypeOperation.getDocumentation());
1057 operation.setAsyncType(asyncType);
1058 operation.setSOAPAction(info.operation.getSOAPAction());
1059 boolean unwrappable = info.operation.isWrapped();
1060 operation.setWrapped(unwrappable);
1061 SOAPBody soapRequestBody = getSOAPRequestBody();
1063 Message inputMessage = getInputMessage();
1064 Request request = new Request(inputMessage, errReceiver);
1066 SOAPBody soapResponseBody = getSOAPResponseBody();
1067 Message outputMessage = getOutputMessage();
1068 Response response = new Response(outputMessage, errReceiver);
1070 // Process parameterOrder and get the parameterList
1071 java.util.List<String> parameterList = getAsynParameterOrder();
1073 List<Parameter> inParameters = null;
1074 if (isOperationDocumentLiteral(styleAndUse)) {
1075 inParameters = getRequestParameters(request, parameterList);
1076 // outParameters = getResponseParameters(response);
1077 // re-create parameterList with unwrapped parameters
1078 if (unwrappable) {
1079 List<String> unwrappedParameterList = new ArrayList<String>();
1080 if (inputMessage != null) {
1081 Iterator<MessagePart> parts = inputMessage.parts();
1082 if (parts.hasNext()) {
1083 MessagePart part = parts.next();
1084 JAXBType jaxbType = getJAXBType(part);
1085 List<JAXBProperty> memberList = jaxbType.getWrapperChildren();
1086 Iterator<JAXBProperty> props = memberList.iterator();
1087 while (props.hasNext()) {
1088 JAXBProperty prop = props.next();
1089 unwrappedParameterList.add(prop.getElementName().getLocalPart());
1090 }
1091 }
1092 }
1094 parameterList.clear();
1095 parameterList.addAll(unwrappedParameterList);
1096 }
1097 } else if (isOperationRpcLiteral(styleAndUse)) {
1098 String operationName = info.bindingOperation.getName();
1099 Block reqBlock = null;
1100 if (inputMessage != null) {
1101 QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
1102 RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
1103 rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
1104 reqBlock = new Block(name, rpcStruct, inputMessage);
1105 request.addBodyBlock(reqBlock);
1106 }
1107 inParameters = createRpcLitRequestParameters(request, parameterList, reqBlock);
1108 }
1110 // add response blocks, we dont need to create respnse parameters, just blocks will be fine, lets
1111 // copy them from sync optraions
1112 //copy the response blocks from the sync operation
1113 Iterator<Block> blocks = info.operation.getResponse().getBodyBlocks();
1115 while (blocks.hasNext()) {
1116 response.addBodyBlock(blocks.next());
1117 }
1119 blocks = info.operation.getResponse().getHeaderBlocks();
1120 while (blocks.hasNext()) {
1121 response.addHeaderBlock(blocks.next());
1122 }
1124 blocks = info.operation.getResponse().getAttachmentBlocks();
1125 while (blocks.hasNext()) {
1126 response.addAttachmentBlock(blocks.next());
1127 }
1129 List<MessagePart> outputParts = outputMessage.getParts();
1131 // handle headers
1132 int numOfOutMsgParts = outputParts.size();
1134 if (numOfOutMsgParts == 1) {
1135 MessagePart part = outputParts.get(0);
1136 if (isOperationDocumentLiteral(styleAndUse)) {
1137 JAXBType type = getJAXBType(part);
1138 operation.setResponseBean(type);
1139 } else if (isOperationRpcLiteral(styleAndUse)) {
1140 String operationName = info.bindingOperation.getName();
1141 Block resBlock = info.operation.getResponse().getBodyBlocksMap().get(new QName(getResponseNamespaceURI(soapResponseBody),
1142 operationName + "Response"));
1144 RpcLitStructure resBean = (RpcLitStructure) resBlock.getType();
1145 List<RpcLitMember> members = resBean.getRpcLitMembers();
1146 operation.setResponseBean(members.get(0));
1147 }
1148 } else {
1149 //create response bean
1150 String nspace = "";
1151 QName responseBeanName = new QName(nspace, getAsyncOperationName(info.operation) + "Response");
1152 JAXBType responseBeanType = jaxbModelBuilder.getJAXBType(responseBeanName);
1153 if (responseBeanType == null) {
1154 error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation.getName()));
1155 }
1156 operation.setResponseBean(responseBeanType);
1157 }
1159 QName respBeanName = new QName(soapResponseBody.getNamespace(), getAsyncOperationName(info.operation) + "Response");
1160 Block block = new Block(respBeanName, operation.getResponseBeanType(), outputMessage);
1161 JavaType respJavaType = operation.getResponseBeanJavaType();
1162 JAXBType respType = new JAXBType(respBeanName, respJavaType);
1163 Parameter respParam = ModelerUtils.createParameter(info.operation.getName() + "Response", respType, block);
1164 respParam.setParameterIndex(-1);
1165 response.addParameter(respParam);
1166 operation.setProperty(WSDL_RESULT_PARAMETER, respParam.getName());
1169 List<String> definitiveParameterList = new ArrayList<String>();
1170 int parameterOrderPosition = 0;
1171 for (String name : parameterList) {
1172 Parameter inParameter = ModelerUtils.getParameter(name, inParameters);
1173 if (inParameter == null) {
1174 if (options.isExtensionMode())
1175 warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
1176 else
1177 error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_ERROR_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
1178 return null;
1179 }
1180 request.addParameter(inParameter);
1181 inParameter.setParameterIndex(parameterOrderPosition);
1182 definitiveParameterList.add(name);
1183 parameterOrderPosition++;
1184 }
1186 operation.setResponse(response);
1188 // add callback handlerb Parameter to request
1189 if (operation.getAsyncType().equals(AsyncOperationType.CALLBACK)) {
1190 JavaType cbJavaType = operation.getCallBackType();
1191 JAXBType callbackType = new JAXBType(respBeanName, cbJavaType);
1192 Parameter cbParam = ModelerUtils.createParameter("asyncHandler", callbackType, block);
1193 request.addParameter(cbParam);
1194 }
1196 operation.setRequest(request);
1198 return operation;
1199 }
1201 protected boolean isAsync(com.sun.tools.internal.ws.wsdl.document.PortType portType, com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation) {
1202 //First look into wsdl:operation
1203 JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(wsdlOperation, JAXWSBinding.class);
1204 Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1206 if (isAsync != null)
1207 return isAsync;
1209 // then into wsdl:portType
1210 QName portTypeName = new QName(portType.getDefining().getTargetNamespaceURI(), portType.getName());
1211 jaxwsCustomization = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
1212 isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1213 if (isAsync != null)
1214 return isAsync;
1216 //then wsdl:definitions
1217 jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
1218 isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
1219 if (isAsync != null)
1220 return isAsync;
1221 return false;
1222 }
1224 protected void handleLiteralSOAPHeaders(Request request, Response response, Iterator headerParts, Set duplicateNames, List<String> definitiveParameterList, boolean processRequest) {
1225 QName headerName;
1226 Block headerBlock;
1227 JAXBType jaxbType;
1228 int parameterOrderPosition = definitiveParameterList.size();
1229 while (headerParts.hasNext()) {
1230 MessagePart part = (MessagePart) headerParts.next();
1231 headerName = part.getDescriptor();
1232 jaxbType = getJAXBType(part);
1233 headerBlock = new Block(headerName, jaxbType, part);
1234 TWSDLExtensible ext;
1235 if (processRequest) {
1236 ext = info.bindingOperation.getInput();
1237 } else {
1238 ext = info.bindingOperation.getOutput();
1239 }
1240 Message headerMessage = getHeaderMessage(part, ext);
1242 if (processRequest) {
1243 request.addHeaderBlock(headerBlock);
1244 } else {
1245 response.addHeaderBlock(headerBlock);
1246 }
1248 Parameter parameter = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1249 parameter.setParameterIndex(parameterOrderPosition);
1250 setCustomizedParameterName(info.bindingOperation, headerMessage, part, parameter, false);
1251 if (processRequest && definitiveParameterList != null) {
1252 request.addParameter(parameter);
1253 definitiveParameterList.add(parameter.getName());
1254 } else {
1255 if (definitiveParameterList != null) {
1256 for (Iterator iterInParams = definitiveParameterList.iterator(); iterInParams.hasNext();) {
1257 String inParamName =
1258 (String) iterInParams.next();
1259 if (inParamName.equals(parameter.getName())) {
1260 Parameter inParam = request.getParameterByName(inParamName);
1261 parameter.setLinkedParameter(inParam);
1262 inParam.setLinkedParameter(parameter);
1263 //its in/out parameter, input and output parameter have the same order position.
1264 parameter.setParameterIndex(inParam.getParameterIndex());
1265 }
1266 }
1267 if (!definitiveParameterList.contains(parameter.getName())) {
1268 definitiveParameterList.add(parameter.getName());
1269 }
1270 }
1271 response.addParameter(parameter);
1272 }
1273 parameterOrderPosition++;
1274 }
1276 }
1278 protected void handleLiteralSOAPFault(Response response, Set duplicateNames) {
1279 for (BindingFault bindingFault : info.bindingOperation.faults()) {
1280 com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
1281 for (com.sun.tools.internal.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
1282 if (aFault.getName().equals(bindingFault.getName())) {
1283 if (portTypeFault != null) {
1284 // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
1285 error(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(), info.bindingOperation.getName()));
1286 }
1287 portTypeFault = aFault;
1288 }
1289 }
1291 // The WSDL document is invalid, the wsdl:fault in abstract operation is does not have any binding
1292 if (portTypeFault == null) {
1293 error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(bindingFault.getName(), info.bindingOperation.getName()));
1295 }
1296 }
1297 for ( com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault : info.portTypeOperation.faults()) {
1299 BindingFault bindingFault = null ;
1300 for(BindingFault bFault: info.bindingOperation.faults()) {
1301 if (bFault.getName().equals(portTypeFault.getName())) {
1302 bindingFault = bFault;
1303 }
1304 }
1306 if(bindingFault == null) {
1307 warning(portTypeFault,ModelerMessages.WSDLMODELER_INVALID_PORT_TYPE_FAULT_NOT_FOUND(portTypeFault.getName(),info.portTypeOperation.getName()));
1308 }
1309 // wsdl:fault message name is used to create the java exception name later on
1310 String faultName = getFaultClassName(portTypeFault);
1311 Fault fault = new Fault(faultName, portTypeFault);
1312 fault.setWsdlFaultName(portTypeFault.getName());
1313 setDocumentationIfPresent(fault, portTypeFault.getDocumentation());
1314 String faultNamespaceURI = null;
1315 if (bindingFault != null) {
1316 //get the soapbind:fault from wsdl:fault in the binding
1317 SOAPFault soapFault = (SOAPFault) getExtensionOfType(bindingFault, SOAPFault.class);
1319 // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
1320 if (soapFault == null) {
1321 if (options.isExtensionMode()) {
1322 warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1323 soapFault = new SOAPFault(new LocatorImpl());
1324 } else {
1325 error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
1326 }
1327 }
1329 //the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
1330 if (!soapFault.isLiteral()) {
1331 if (options.isExtensionMode())
1332 warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
1333 else
1334 error(soapFault, ModelerMessages.WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
1335 continue;
1336 }
1338 // the soapFault name must be present
1339 if (soapFault.getName() == null) {
1340 warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(bindingFault.getName(), info.bindingOperation.getName()));
1341 } else if (!soapFault.getName().equals(bindingFault.getName())) {
1342 warning(soapFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(soapFault.getName(), bindingFault.getName(), info.bindingOperation.getName()));
1343 } else if (soapFault.getNamespace() != null) {
1344 warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
1345 }
1347 faultNamespaceURI = soapFault.getNamespace();
1348 }
1349 if (faultNamespaceURI == null) {
1350 faultNamespaceURI = portTypeFault.getMessage().getNamespaceURI();
1351 }
1353 com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault.resolveMessage(info.document);
1354 Iterator iter2 = faultMessage.parts();
1355 if (!iter2.hasNext()) {
1356 // the WSDL document is invalid
1357 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(portTypeFault.getName(), faultMessage.getName()));
1358 }
1359 MessagePart faultPart = (MessagePart) iter2.next();
1360 QName faultQName = faultPart.getDescriptor();
1362 // Don't include fault messages with non-unique soap:fault names
1363 if (duplicateNames.contains(faultQName)) {
1364 warning(faultPart, ModelerMessages.WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(portTypeFault.getName(), info.portTypeOperation.getName(), faultPart.getName()));
1365 continue;
1366 }
1368 if (iter2.hasNext()) {
1369 // the WSDL document is invalid
1370 error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(portTypeFault.getName(), faultMessage.getName()));
1371 }
1373 if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1374 error(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
1375 }
1377 JAXBType jaxbType = getJAXBType(faultPart);
1379 fault.setElementName(faultPart.getDescriptor());
1380 fault.setJavaMemberName(Names.getExceptionClassMemberName());
1382 Block faultBlock = new Block(faultQName, jaxbType, faultPart);
1383 fault.setBlock(faultBlock);
1384 //createParentFault(fault);
1385 //createSubfaults(fault);
1386 if (!response.getFaultBlocksMap().containsKey(faultBlock.getName()))
1387 response.addFaultBlock(faultBlock);
1388 info.operation.addFault(fault);
1389 }
1390 }
1392 private String getFaultClassName(com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault) {
1393 JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeFault, JAXWSBinding.class);
1394 if (jaxwsBinding != null) {
1395 CustomName className = jaxwsBinding.getClassName();
1396 if (className != null) {
1397 return makePackageQualified(className.getName());
1398 }
1399 }
1400 return makePackageQualified(BindingHelper.mangleNameToClassName(portTypeFault.getMessage().getLocalPart()));
1401 }
1403 protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
1404 SOAPBody inBody = getSOAPRequestBody();
1405 Message inMessage = getInputMessage();
1406 if (!setMessagePartsBinding(inBody, inMessage, styleAndUse, true))
1407 return false;
1409 if (isRequestResponse()) {
1410 SOAPBody outBody = getSOAPResponseBody();
1411 Message outMessage = getOutputMessage();
1412 if (!setMessagePartsBinding(outBody, outMessage, styleAndUse, false))
1413 return false;
1414 }
1415 return true;
1416 }
1418 //returns false if the wsdl is invalid and operation should be ignored
1419 protected boolean setMessagePartsBinding(SOAPBody body, Message message, StyleAndUse styleAndUse, boolean isInput) {
1420 List<MessagePart> parts = new ArrayList<MessagePart>();
1422 //get Mime parts
1423 List<MessagePart> mimeParts;
1424 List<MessagePart> headerParts;
1425 List<MessagePart> bodyParts = getBodyParts(body, message);
1427 if (isInput) {
1428 headerParts = getHeaderPartsFromMessage(message, isInput);
1429 mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
1430 } else {
1431 headerParts = getHeaderPartsFromMessage(message, isInput);
1432 mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
1433 }
1435 //As of now WSDL MIME binding is not supported, so throw the exception when such binding is encounterd
1436 // if(mimeParts.size() > 0){
1437 // fail("wsdlmodeler.unsupportedBinding.mime", new Object[]{});
1438 // }
1440 //if soap:body parts attribute not there, then all unbounded message parts will
1441 // belong to the soap body
1442 if (bodyParts == null) {
1443 bodyParts = new ArrayList<MessagePart>();
1444 for (Iterator<MessagePart> iter = message.parts(); iter.hasNext();) {
1445 MessagePart mPart = iter.next();
1446 //Its a safe assumption that the parts in the message not belonging to header or mime will
1447 // belong to the body?
1448 if (mimeParts.contains(mPart) || headerParts.contains(mPart) || boundToFault(mPart.getName())) {
1449 //throw error that a part cant be bound multiple times, not ignoring operation, if there
1450 //is conflict it will fail latter
1451 if (options.isExtensionMode())
1452 warning(mPart, ModelerMessages.WSDLMODELER_WARNING_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1453 else
1454 error(mPart, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
1455 }
1456 bodyParts.add(mPart);
1457 }
1458 }
1460 //now build the final parts list with header, mime parts and body parts
1461 for (Iterator iter = message.parts(); iter.hasNext();) {
1462 MessagePart mPart = (MessagePart) iter.next();
1463 if (mimeParts.contains(mPart)) {
1464 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
1465 parts.add(mPart);
1466 } else if (headerParts.contains(mPart)) {
1467 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1468 parts.add(mPart);
1469 } else if (bodyParts.contains(mPart)) {
1470 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1471 parts.add(mPart);
1472 } else {
1473 mPart.setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
1474 }
1475 }
1477 if (isOperationDocumentLiteral(styleAndUse) && bodyParts.size() > 1) {
1478 if (options.isExtensionMode())
1479 warning(message, ModelerMessages.WSDLMODELER_WARNING_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
1480 else
1481 error(message, ModelerMessages.WSDLMODELER_INVALID_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
1482 return false;
1483 }
1484 return true;
1485 }
1487 private boolean boundToFault(String partName) {
1488 for (BindingFault bindingFault : info.bindingOperation.faults()) {
1489 if (partName.equals(bindingFault.getName()))
1490 return true;
1491 }
1492 return false;
1493 }
1495 //get MessagePart(s) referenced by parts attribute of soap:body element
1496 private List<MessagePart> getBodyParts(SOAPBody body, Message message) {
1497 String bodyParts = body.getParts();
1498 if (bodyParts != null) {
1499 List<MessagePart> partsList = new ArrayList<MessagePart>();
1500 StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
1501 while (in.hasMoreTokens()) {
1502 String part = in.nextToken();
1503 MessagePart mPart = message.getPart(part);
1504 if (null == mPart) {
1505 error(message, ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(part, message.getName()));
1506 }
1507 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
1508 partsList.add(mPart);
1509 }
1510 return partsList;
1511 }
1512 return null;
1513 }
1515 List<MessagePart> getAdditionHeaderParts(BindingOperation bindingOperation,Message message, boolean isInput){
1516 List<MessagePart> headerParts = new ArrayList<MessagePart>();
1517 List<MessagePart> parts = message.getParts();
1518 List<MessagePart> headers = getHeaderParts(bindingOperation, isInput);
1520 for(MessagePart part: headers){
1521 if(parts.contains(part))
1522 continue;
1523 headerParts.add(part);
1524 }
1525 return headerParts;
1526 }
1528 private List<MessagePart> getHeaderPartsFromMessage(Message message, boolean isInput) {
1529 List<MessagePart> headerParts = new ArrayList<MessagePart>();
1530 Iterator<MessagePart> parts = message.parts();
1531 List<MessagePart> headers = getHeaderParts(info.bindingOperation, isInput);
1532 while (parts.hasNext()) {
1533 MessagePart part = parts.next();
1534 if (headers.contains(part)) {
1535 headerParts.add(part);
1536 }
1537 }
1538 return headerParts;
1539 }
1541 private Message getHeaderMessage(MessagePart part, TWSDLExtensible ext) {
1542 Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1543 while (headers.hasNext()) {
1544 SOAPHeader header = headers.next();
1545 if (!header.isLiteral())
1546 continue;
1547 com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(), document);
1548 if (headerMessage == null)
1549 continue;
1551 MessagePart headerPart = headerMessage.getPart(header.getPart());
1552 if (headerPart == part)
1553 return headerMessage;
1554 }
1555 return null;
1556 }
1558 private List<MessagePart> getHeaderParts(BindingOperation bindingOperation, boolean isInput) {
1559 TWSDLExtensible ext;
1560 if (isInput) {
1561 ext = bindingOperation.getInput();
1562 } else {
1563 ext = bindingOperation.getOutput();
1564 }
1566 List<MessagePart> parts = new ArrayList<MessagePart>();
1567 Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
1568 while (headers.hasNext()) {
1569 SOAPHeader header = headers.next();
1570 if (!header.isLiteral()) {
1571 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_LITERAL(header.getPart(), bindingOperation.getName()));
1572 }
1574 if (header.getNamespace() != null) {
1575 warning(header, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:header", bindingOperation.getName()));
1576 }
1577 com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(),document);
1578 if (headerMessage == null) {
1579 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_CANT_RESOLVE_MESSAGE(header.getMessage(), bindingOperation.getName()));
1580 }
1582 MessagePart part = headerMessage.getPart(header.getPart());
1583 if (part == null) {
1584 error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_FOUND(header.getPart(), bindingOperation.getName()));
1585 }
1586 if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
1587 error(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
1588 }
1589 part.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
1590 parts.add(part);
1591 }
1592 return parts;
1593 }
1595 private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
1596 return StyleAndUse.DOC_LITERAL == styleAndUse;
1597 }
1599 private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
1600 return StyleAndUse.RPC_LITERAL == styleAndUse;
1601 }
1603 /**
1604 * @param part
1605 * @return Returns a JAXBType object
1606 */
1607 private JAXBType getJAXBType(MessagePart part) {
1608 JAXBType type;
1609 QName name = part.getDescriptor();
1610 if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
1611 type = jaxbModelBuilder.getJAXBType(name);
1612 if(type == null){
1613 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1614 }
1615 } else {
1616 S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
1617 TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
1618 if (typeAnno == null) {
1619 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
1620 }
1621 JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno));
1622 type = new JAXBType(new QName("", part.getName()), javaType);
1623 }
1624 return type;
1625 }
1627 private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
1628 if (parameterList.size() == 0)
1629 return new ArrayList<Parameter>();
1630 List<Parameter> params = new ArrayList<Parameter>();
1631 Message inMsg = getInputMessage();
1632 Message outMsg = getOutputMessage();
1633 boolean unwrappable = isUnwrappable();
1634 List<Parameter> outParams = null;
1635 int pIndex = 0;
1636 for (MessagePart part : parameterList) {
1637 QName reqBodyName = part.getDescriptor();
1638 JAXBType jaxbType = getJAXBType(part);
1639 Block block = new Block(reqBodyName, jaxbType, part);
1640 if (unwrappable) {
1641 //So build body and header blocks and set to request and response
1642 JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
1643 block = new Block(reqBodyName, jaxbStructType, part);
1644 if (ModelerUtils.isBoundToSOAPBody(part)) {
1645 if (part.isIN()) {
1646 req.addBodyBlock(block);
1647 } else if (part.isOUT()) {
1648 res.addBodyBlock(block);
1649 } else if (part.isINOUT()) {
1650 req.addBodyBlock(block);
1651 res.addBodyBlock(block);
1652 }
1653 } else if (ModelerUtils.isUnbound(part)) {
1654 if (part.isIN())
1655 req.addUnboundBlock(block);
1656 else if (part.isOUT())
1657 res.addUnboundBlock(block);
1658 else if (part.isINOUT()) {
1659 req.addUnboundBlock(block);
1660 res.addUnboundBlock(block);
1661 }
1663 }
1664 if (part.isIN() || part.isINOUT()) {
1665 params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1666 int index = 0;
1667 Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
1668 for (Parameter param : params) {
1669 param.setParameterIndex(index++);
1670 param.setMode(mode);
1671 setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
1672 }
1673 } else if (part.isOUT()) {
1674 outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
1675 for (Parameter param : outParams) {
1676 param.setMode(Mode.OUT);
1677 setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
1678 }
1679 }
1680 } else {
1681 if (ModelerUtils.isBoundToSOAPBody(part)) {
1682 if (part.isIN()) {
1683 req.addBodyBlock(block);
1684 } else if (part.isOUT()) {
1685 res.addBodyBlock(block);
1686 } else if (part.isINOUT()) {
1687 req.addBodyBlock(block);
1688 res.addBodyBlock(block);
1689 }
1690 } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1691 if (part.isIN()) {
1692 req.addHeaderBlock(block);
1693 } else if (part.isOUT()) {
1694 res.addHeaderBlock(block);
1695 } else if (part.isINOUT()) {
1696 req.addHeaderBlock(block);
1697 res.addHeaderBlock(block);
1698 }
1699 } else if (ModelerUtils.isBoundToMimeContent(part)) {
1700 List<MIMEContent> mimeContents;
1702 if (part.isIN()) {
1703 mimeContents = getMimeContents(info.bindingOperation.getInput(),
1704 getInputMessage(), part.getName());
1705 jaxbType = getAttachmentType(mimeContents, part);
1706 block = new Block(jaxbType.getName(), jaxbType, part);
1707 req.addAttachmentBlock(block);
1708 } else if (part.isOUT()) {
1709 mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1710 getOutputMessage(), part.getName());
1711 jaxbType = getAttachmentType(mimeContents, part);
1712 block = new Block(jaxbType.getName(), jaxbType, part);
1713 res.addAttachmentBlock(block);
1714 } else if (part.isINOUT()) {
1715 mimeContents = getMimeContents(info.bindingOperation.getInput(),
1716 getInputMessage(), part.getName());
1717 jaxbType = getAttachmentType(mimeContents, part);
1718 block = new Block(jaxbType.getName(), jaxbType, part);
1719 req.addAttachmentBlock(block);
1720 res.addAttachmentBlock(block);
1722 mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1723 getOutputMessage(), part.getName());
1724 JAXBType outJaxbType = getAttachmentType(mimeContents, part);
1726 String inType = jaxbType.getJavaType().getType().getName();
1727 String outType = outJaxbType.getJavaType().getType().getName();
1729 TypeAndAnnotation inTa = jaxbType.getJavaType().getType().getTypeAnn();
1730 TypeAndAnnotation outTa = outJaxbType.getJavaType().getType().getTypeAnn();
1731 if ((((inTa != null) && (outTa != null) && inTa.equals(outTa))) && !inType.equals(outType)) {
1732 String javaType = "javax.activation.DataHandler";
1734 //S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
1735 //JCodeModel cm = jaxbModel.generateCode(null, errReceiver);
1736 JType jt = options.getCodeModel().ref(javaType);
1737 JAXBTypeAndAnnotation jaxbTa = jaxbType.getJavaType().getType();
1738 jaxbTa.setType(jt);
1739 }
1740 }
1741 } else if (ModelerUtils.isUnbound(part)) {
1742 if (part.isIN()) {
1743 req.addUnboundBlock(block);
1744 } else if (part.isOUT()) {
1745 res.addUnboundBlock(block);
1746 } else if (part.isINOUT()) {
1747 req.addUnboundBlock(block);
1748 res.addUnboundBlock(block);
1749 }
1750 }
1751 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
1752 param.setMode(part.getMode());
1753 if (part.isReturn()) {
1754 param.setParameterIndex(-1);
1755 } else {
1756 param.setParameterIndex(pIndex++);
1757 }
1759 if (part.isIN())
1760 setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, false);
1761 else if (outMsg != null)
1762 setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, false);
1764 params.add(param);
1765 }
1766 }
1767 if (unwrappable && (outParams != null)) {
1768 int index = params.size();
1769 for (Parameter param : outParams) {
1770 if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
1771 param.setParameterIndex(-1);
1772 } else {
1773 Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
1774 if ((inParam != null) && inParam.isIN()) {
1775 QName inElementName = inParam.getType().getName();
1776 QName outElementName = param.getType().getName();
1777 String inJavaType = inParam.getTypeName();
1778 String outJavaType = param.getTypeName();
1779 TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
1780 TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
1781 QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
1782 QName outRawTypeName = ModelerUtils.getRawTypeName(param);
1783 if (inElementName.getLocalPart().equals(outElementName.getLocalPart()) &&
1784 inJavaType.equals(outJavaType) &&
1785 (inTa == null || outTa == null || inTa.equals(outTa)) &&
1786 (inRawTypeName == null || outRawTypeName == null || inRawTypeName.equals(outRawTypeName))) {
1787 inParam.setMode(Mode.INOUT);
1788 continue;
1789 }
1790 }
1791 if (outParams.size() == 1) {
1792 param.setParameterIndex(-1);
1793 } else {
1794 param.setParameterIndex(index++);
1795 }
1796 }
1797 params.add(param);
1798 }
1799 }
1800 return params;
1801 }
1803 private List<Parameter> getRpcLitParameters(Request req, Response res, Block reqBlock, Block resBlock, List<MessagePart> paramList) {
1804 List<Parameter> params = new ArrayList<Parameter>();
1805 Message inMsg = getInputMessage();
1806 Message outMsg = getOutputMessage();
1807 S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType()).getJaxbModel().getS2JJAXBModel();
1808 List<Parameter> inParams = ModelerUtils.createRpcLitParameters(inMsg, reqBlock, jaxbModel, errReceiver);
1809 List<Parameter> outParams = null;
1810 if (outMsg != null)
1811 outParams = ModelerUtils.createRpcLitParameters(outMsg, resBlock, jaxbModel, errReceiver);
1813 //create parameters for header and mime parts
1814 int index = 0;
1815 for (MessagePart part : paramList) {
1816 Parameter param = null;
1817 if (ModelerUtils.isBoundToSOAPBody(part)) {
1818 if (part.isIN()) {
1819 param = ModelerUtils.getParameter(part.getName(), inParams);
1820 } else if (outParams != null) {
1821 param = ModelerUtils.getParameter(part.getName(), outParams);
1822 }
1823 } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1824 QName headerName = part.getDescriptor();
1825 JAXBType jaxbType = getJAXBType(part);
1826 Block headerBlock = new Block(headerName, jaxbType, part);
1827 param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
1828 if (part.isIN()) {
1829 req.addHeaderBlock(headerBlock);
1830 } else if (part.isOUT()) {
1831 res.addHeaderBlock(headerBlock);
1832 } else if (part.isINOUT()) {
1833 req.addHeaderBlock(headerBlock);
1834 res.addHeaderBlock(headerBlock);
1835 }
1836 } else if (ModelerUtils.isBoundToMimeContent(part)) {
1837 List<MIMEContent> mimeContents;
1838 if (part.isIN() || part.isINOUT())
1839 mimeContents = getMimeContents(info.bindingOperation.getInput(),
1840 getInputMessage(), part.getName());
1841 else
1842 mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1843 getOutputMessage(), part.getName());
1845 JAXBType type = getAttachmentType(mimeContents, part);
1846 //create Parameters in request or response
1847 //Block mimeBlock = new Block(new QName(part.getName()), type);
1848 Block mimeBlock = new Block(type.getName(), type, part);
1849 param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
1850 if (part.isIN()) {
1851 req.addAttachmentBlock(mimeBlock);
1852 } else if (part.isOUT()) {
1853 res.addAttachmentBlock(mimeBlock);
1854 } else if (part.isINOUT()) {
1855 mimeContents = getMimeContents(info.bindingOperation.getOutput(),
1856 getOutputMessage(), part.getName());
1857 JAXBType outJaxbType = getAttachmentType(mimeContents, part);
1859 String inType = type.getJavaType().getType().getName();
1860 String outType = outJaxbType.getJavaType().getType().getName();
1861 if (!inType.equals(outType)) {
1862 String javaType = "javax.activation.DataHandler";
1863 JType jt = options.getCodeModel().ref(javaType);
1864 JAXBTypeAndAnnotation jaxbTa = type.getJavaType().getType();
1865 jaxbTa.setType(jt);
1866 }
1867 req.addAttachmentBlock(mimeBlock);
1868 res.addAttachmentBlock(mimeBlock);
1869 }
1870 } else if (ModelerUtils.isUnbound(part)) {
1871 QName name = part.getDescriptor();
1872 JAXBType type = getJAXBType(part);
1873 Block unboundBlock = new Block(name, type, part);
1874 if (part.isIN()) {
1875 req.addUnboundBlock(unboundBlock);
1876 } else if (part.isOUT()) {
1877 res.addUnboundBlock(unboundBlock);
1878 } else if (part.isINOUT()) {
1879 req.addUnboundBlock(unboundBlock);
1880 res.addUnboundBlock(unboundBlock);
1881 }
1882 param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
1883 }
1884 if (param != null) {
1885 if (part.isReturn()) {
1886 param.setParameterIndex(-1);
1887 } else {
1888 param.setParameterIndex(index++);
1889 }
1890 param.setMode(part.getMode());
1891 params.add(param);
1892 }
1893 }
1894 for (Parameter param : params) {
1895 if (param.isIN())
1896 setCustomizedParameterName(info.portTypeOperation, inMsg, inMsg.getPart(param.getName()), param, false);
1897 else if (outMsg != null)
1898 setCustomizedParameterName(info.portTypeOperation, outMsg, outMsg.getPart(param.getName()), param, false);
1899 }
1900 return params;
1901 }
1903 private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
1904 Message inputMessage = getInputMessage();
1905 //there is no input message, return zero parameters
1906 if (inputMessage != null && !inputMessage.parts().hasNext())
1907 return new ArrayList<Parameter>();
1909 List<Parameter> inParameters = null;
1910 QName reqBodyName;
1911 Block reqBlock;
1912 JAXBType jaxbReqType;
1913 boolean unwrappable = isUnwrappable();
1914 boolean doneSOAPBody = false;
1915 //setup request parameters
1916 for (String inParamName : parameterList) {
1917 MessagePart part = inputMessage.getPart(inParamName);
1918 if (part == null)
1919 continue;
1920 reqBodyName = part.getDescriptor();
1921 jaxbReqType = getJAXBType(part);
1922 if (unwrappable) {
1923 //So build body and header blocks and set to request and response
1924 JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
1925 reqBlock = new Block(reqBodyName, jaxbRequestType, part);
1926 if (ModelerUtils.isBoundToSOAPBody(part)) {
1927 request.addBodyBlock(reqBlock);
1928 } else if (ModelerUtils.isUnbound(part)) {
1929 request.addUnboundBlock(reqBlock);
1930 }
1931 inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
1932 for (Parameter param : inParameters) {
1933 setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
1934 }
1935 } else {
1936 reqBlock = new Block(reqBodyName, jaxbReqType, part);
1937 if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
1938 doneSOAPBody = true;
1939 request.addBodyBlock(reqBlock);
1940 } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
1941 request.addHeaderBlock(reqBlock);
1942 } else if (ModelerUtils.isBoundToMimeContent(part)) {
1943 List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
1944 getInputMessage(), part.getName());
1945 jaxbReqType = getAttachmentType(mimeContents, part);
1946 //reqBlock = new Block(new QName(part.getName()), jaxbReqType);
1947 reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
1948 request.addAttachmentBlock(reqBlock);
1949 } else if (ModelerUtils.isUnbound(part)) {
1950 request.addUnboundBlock(reqBlock);
1951 }
1952 if (inParameters == null)
1953 inParameters = new ArrayList<Parameter>();
1954 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
1955 setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
1956 inParameters.add(param);
1957 }
1958 }
1959 return inParameters;
1960 }
1962 /**
1963 * @param part
1964 * @param param
1965 * @param wrapperStyle TODO
1966 */
1967 private void setCustomizedParameterName(TWSDLExtensible extension, Message msg, MessagePart part, Parameter param, boolean wrapperStyle) {
1968 JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(extension, JAXWSBinding.class);
1969 if (jaxwsBinding == null)
1970 return;
1971 String paramName = part.getName();
1972 QName elementName = part.getDescriptor();
1973 if (wrapperStyle)
1974 elementName = param.getType().getName();
1975 String customName = jaxwsBinding.getParameterName(msg.getName(), paramName, elementName, wrapperStyle);
1976 if (customName != null && !customName.equals("")) {
1977 param.setCustomName(customName);
1978 }
1979 }
1981 protected boolean isConflictingPortClassName(String name) {
1982 return false;
1983 }
1985 protected boolean isUnwrappable() {
1986 if (!getWrapperStyleCustomization())
1987 return false;
1989 com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
1990 com.sun.tools.internal.ws.wsdl.document.Message outputMessage = getOutputMessage();
1992 // Wrapper style if the operation's input and output messages each contain
1993 // only a single part
1994 if ((inputMessage != null && inputMessage.numParts() != 1)
1995 || (outputMessage != null && outputMessage.numParts() != 1)) {
1996 return false;
1997 }
1999 MessagePart inputPart = inputMessage != null
2000 ? inputMessage.parts().next() : null;
2001 MessagePart outputPart = outputMessage != null
2002 ? outputMessage.parts().next() : null;
2003 String operationName = info.portTypeOperation.getName();
2005 // Wrapper style if the input message part refers to a global element declaration whose localname
2006 // is equal to the operation name
2007 // Wrapper style if the output message part refers to a global element declaration
2008 if ((inputPart != null && !inputPart.getDescriptor().getLocalPart().equals(operationName)) ||
2009 (outputPart != null && outputPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT))
2010 return false;
2012 //check to see if either input or output message part not bound to soapbing:body
2013 //in that case the operation is not wrapper style
2014 if (((inputPart != null) && (inputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)) ||
2015 ((outputPart != null) && (outputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)))
2016 return false;
2018 // Wrapper style if the elements referred to by the input and output message parts
2019 // (henceforth referred to as wrapper elements) are both complex types defined
2020 // using the xsd:sequence compositor
2021 // Wrapper style if the wrapper elements only contain child elements, they must not
2022 // contain other structures such as xsd:choice, substitution groups1 or attributes
2023 //These checkins are done by jaxb, we just check if jaxb has wrapper children. If there
2024 // are then its wrapper style
2025 //if(inputPart != null && outputPart != null){
2026 if (inputPart != null) {
2027 boolean inputWrappable = false;
2028 JAXBType inputType = getJAXBType(inputPart);
2029 if (inputType != null) {
2030 inputWrappable = inputType.isUnwrappable();
2031 }
2032 //if there are no output part (oneway), the operation can still be wrapper style
2033 if (outputPart == null) {
2034 return inputWrappable;
2035 }
2036 JAXBType outputType = getJAXBType(outputPart);
2037 if ((inputType != null) && (outputType != null))
2038 return inputType.isUnwrappable() && outputType.isUnwrappable();
2039 }
2041 return false;
2042 }
2044 private boolean getWrapperStyleCustomization() {
2045 //first we look into wsdl:portType/wsdl:operation
2046 com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
2047 JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeOperation, JAXWSBinding.class);
2048 if (jaxwsBinding != null) {
2049 Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2050 if (isWrappable != null)
2051 return isWrappable;
2052 }
2054 //then into wsdl:portType
2055 PortType portType = info.port.resolveBinding(document).resolvePortType(document);
2056 jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2057 if (jaxwsBinding != null) {
2058 Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2059 if (isWrappable != null)
2060 return isWrappable;
2061 }
2063 //then wsdl:definitions
2064 jaxwsBinding = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2065 if (jaxwsBinding != null) {
2066 Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
2067 if (isWrappable != null)
2068 return isWrappable;
2069 }
2070 return true;
2071 }
2073 /* (non-Javadoc)
2074 * @see WSDLModelerBase#isSingleInOutPart(Set, MessagePart)
2075 */
2076 protected boolean isSingleInOutPart(Set inputParameterNames,
2077 MessagePart outputPart) {
2078 // As of now, we dont have support for in/out in doc-lit. So return false.
2079 SOAPOperation soapOperation =
2080 (SOAPOperation) getExtensionOfType(info.bindingOperation,
2081 SOAPOperation.class);
2082 if ((soapOperation != null) && (soapOperation.isDocument() || info.soapBinding.isDocument())) {
2083 Iterator iter = getInputMessage().parts();
2084 while (iter.hasNext()) {
2085 MessagePart part = (MessagePart) iter.next();
2086 if (outputPart.getName().equals(part.getName()) && outputPart.getDescriptor().equals(part.getDescriptor()))
2087 return true;
2088 }
2089 } else if (soapOperation != null && soapOperation.isRPC() || info.soapBinding.isRPC()) {
2090 com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
2091 if (inputParameterNames.contains(outputPart.getName())) {
2092 if (inputMessage.getPart(outputPart.getName()).getDescriptor().equals(outputPart.getDescriptor())) {
2093 return true;
2094 }
2095 }
2096 }
2097 return false;
2098 }
2100 private List<Parameter> createRpcLitRequestParameters(Request request, List<String> parameterList, Block block) {
2101 Message message = getInputMessage();
2102 S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType()).getJaxbModel().getS2JJAXBModel();
2103 List<Parameter> parameters = ModelerUtils.createRpcLitParameters(message, block, jaxbModel, errReceiver);
2105 //create parameters for header and mime parts
2106 for (String paramName : parameterList) {
2107 MessagePart part = message.getPart(paramName);
2108 if (part == null)
2109 continue;
2110 if (ModelerUtils.isBoundToSOAPHeader(part)) {
2111 if (parameters == null)
2112 parameters = new ArrayList<Parameter>();
2113 QName headerName = part.getDescriptor();
2114 JAXBType jaxbType = getJAXBType(part);
2115 Block headerBlock = new Block(headerName, jaxbType, part);
2116 request.addHeaderBlock(headerBlock);
2117 Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
2118 if (param != null) {
2119 parameters.add(param);
2120 }
2121 } else if (ModelerUtils.isBoundToMimeContent(part)) {
2122 if (parameters == null)
2123 parameters = new ArrayList<Parameter>();
2124 List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
2125 getInputMessage(), paramName);
2127 JAXBType type = getAttachmentType(mimeContents, part);
2128 //create Parameters in request or response
2129 //Block mimeBlock = new Block(new QName(part.getName()), type);
2130 Block mimeBlock = new Block(type.getName(), type, part);
2131 request.addAttachmentBlock(mimeBlock);
2132 Parameter param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
2133 if (param != null) {
2134 parameters.add(param);
2135 }
2136 } else if (ModelerUtils.isUnbound(part)) {
2137 if (parameters == null)
2138 parameters = new ArrayList<Parameter>();
2139 QName name = part.getDescriptor();
2140 JAXBType type = getJAXBType(part);
2141 Block unboundBlock = new Block(name, type, part);
2142 request.addUnboundBlock(unboundBlock);
2143 Parameter param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
2144 if (param != null) {
2145 parameters.add(param);
2146 }
2147 }
2148 }
2149 for (Parameter param : parameters) {
2150 setCustomizedParameterName(info.portTypeOperation, message, message.getPart(param.getName()), param, false);
2151 }
2152 return parameters;
2153 }
2155 private String getJavaTypeForMimeType(String mimeType) {
2156 if (mimeType.equals("image/jpeg") || mimeType.equals("image/gif")) {
2157 return "java.awt.Image";
2158 } else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) {
2159 return "javax.xml.transform.Source";
2160 }
2161 return "javax.activation.DataHandler";
2162 }
2164 private JAXBType getAttachmentType(List<MIMEContent> mimeContents, MessagePart part) {
2165 if (!enableMimeContent()) {
2166 return getJAXBType(part);
2167 }
2168 String javaType;
2169 List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
2170 if (mimeTypes.size() > 1) {
2171 javaType = "javax.activation.DataHandler";
2172 } else {
2173 javaType = getJavaTypeForMimeType(mimeTypes.get(0));
2174 }
2176 S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
2177 JType jt = options.getCodeModel().ref(javaType);
2178 QName desc = part.getDescriptor();
2179 TypeAndAnnotation typeAnno = null;
2181 if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
2182 typeAnno = jaxbModel.getJavaType(desc);
2183 desc = new QName("", part.getName());
2184 } else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
2185 typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
2186 if(typeAnno == null){
2187 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part.getDescriptor(), part.getName()));
2188 }
2189 for (Iterator mimeTypeIter = mimeTypes.iterator(); mimeTypeIter.hasNext();) {
2190 String mimeType = (String) mimeTypeIter.next();
2191 if ((!mimeType.equals("text/xml") &&
2192 !mimeType.equals("application/xml"))) {
2193 //According to AP 1.0,
2194 //RZZZZ: In a DESCRIPTION, if a wsdl:part element refers to a
2195 //global element declaration (via the element attribute of the wsdl:part
2196 //element) then the value of the type attribute of a mime:content element
2197 //that binds that part MUST be a content type suitable for carrying an
2198 //XML serialization.
2199 //should we throw warning?
2200 //type = MimeHelper.javaType.DATA_HANDLER_JAVATYPE;
2201 warning(part, ModelerMessages.MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(part.getName(), mimeType));
2202 }
2203 }
2204 }
2205 if (typeAnno == null) {
2206 error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part.getName()));
2207 }
2208 return new JAXBType(desc, new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno, jt)),
2209 null, getJAXBModelBuilder().getJAXBModel());
2210 }
2212 protected void buildJAXBModel(WSDLDocument wsdlDocument) {
2213 JAXBModelBuilder jaxbModelBuilder = new JAXBModelBuilder(options, classNameCollector, forest, errReceiver);
2214 //set the java package where wsdl artifacts will be generated
2215 //if user provided package name using -p switch (or package property on wsimport ant task)
2216 //ignore the package customization in the wsdl and schema bidnings
2217 //formce the -p option only in the first pass
2218 if (explicitDefaultPackage != null) {
2219 jaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(options.defaultPackage);
2220 } else {
2221 options.defaultPackage = getJavaPackage();
2222 }
2224 //create pseudo schema for async operations(if any) response bean
2225 List<InputSource> schemas = PseudoSchemaBuilder.build(this, options, errReceiver);
2226 for (InputSource schema : schemas) {
2227 jaxbModelBuilder.getJAXBSchemaCompiler().parseSchema(schema);
2228 }
2229 jaxbModelBuilder.bind();
2230 this.jaxbModelBuilder = jaxbModelBuilder;
2231 }
2233 protected String getJavaPackage() {
2234 String jaxwsPackage = null;
2235 JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
2236 if (jaxwsCustomization != null && jaxwsCustomization.getJaxwsPackage() != null) {
2237 jaxwsPackage = jaxwsCustomization.getJaxwsPackage().getName();
2238 }
2239 if (jaxwsPackage != null) {
2240 return jaxwsPackage;
2241 }
2242 String wsdlUri = document.getDefinitions().getTargetNamespaceURI();
2243 return XJC.getDefaultPackageName(wsdlUri);
2245 }
2247 protected void createJavaInterfaceForProviderPort(Port port) {
2248 String interfaceName = "javax.xml.ws.Provider";
2249 JavaInterface intf = new JavaInterface(interfaceName);
2250 port.setJavaInterface(intf);
2251 }
2253 protected void createJavaInterfaceForPort(Port port, boolean isProvider) {
2254 if (isProvider) {
2255 createJavaInterfaceForProviderPort(port);
2256 return;
2257 }
2258 String interfaceName = getJavaNameOfSEI(port);
2260 if (isConflictingPortClassName(interfaceName)) {
2261 interfaceName += "_PortType";
2262 }
2264 JavaInterface intf = new JavaInterface(interfaceName);
2265 for (Operation operation : port.getOperations()) {
2266 createJavaMethodForOperation(
2267 port,
2268 operation,
2269 intf);
2271 for (JavaParameter jParam : operation.getJavaMethod().getParametersList()) {
2272 Parameter param = jParam.getParameter();
2273 if (param.getCustomName() != null)
2274 jParam.setName(param.getCustomName());
2275 }
2276 }
2278 port.setJavaInterface(intf);
2279 }
2281 protected String getServiceInterfaceName(QName serviceQName, com.sun.tools.internal.ws.wsdl.document.Service wsdlService) {
2282 String serviceName = wsdlService.getName();
2283 JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(wsdlService, JAXWSBinding.class);
2284 if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2285 CustomName name = jaxwsCust.getClassName();
2286 if (name != null && !name.getName().equals(""))
2287 return makePackageQualified(name.getName());
2288 }
2289 return makePackageQualified(BindingHelper.mangleNameToClassName(serviceName));
2290 }
2292 protected String getJavaNameOfSEI(Port port) {
2293 QName portTypeName =
2294 (QName) port.getProperty(
2295 ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
2296 PortType pt = (PortType) document.find(Kinds.PORT_TYPE, portTypeName);
2297 //populate the portType map here. We should get rid of all these properties
2298 // lets not do it as it may break NB
2299 //TODO: clean all these stuff part of NB RFE
2300 port.portTypes.put(portTypeName, pt);
2301 JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt, JAXWSBinding.class);
2302 if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
2303 CustomName name = jaxwsCust.getClassName();
2304 if (name != null && !name.getName().equals("")) {
2305 return makePackageQualified(name.getName());
2306 }
2307 }
2309 String interfaceName;
2310 if (portTypeName != null) {
2311 // got portType information from WSDL, use it to name the interface
2312 interfaceName =
2313 makePackageQualified(BindingHelper.mangleNameToClassName(portTypeName.getLocalPart()));
2314 } else {
2315 // somehow we only got the port name, so we use that
2316 interfaceName =
2317 makePackageQualified(BindingHelper.mangleNameToClassName(port.getName().getLocalPart()));
2318 }
2319 return interfaceName;
2320 }
2322 private void createJavaMethodForAsyncOperation(Port port, Operation operation,
2323 JavaInterface intf) {
2324 String candidateName = getJavaNameForOperation(operation);
2325 JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
2326 Request request = operation.getRequest();
2327 Iterator requestBodyBlocks = request.getBodyBlocks();
2328 Block requestBlock =
2329 (requestBodyBlocks.hasNext()
2330 ? request.getBodyBlocks().next()
2331 : null);
2333 Response response = operation.getResponse();
2334 Iterator responseBodyBlocks = null;
2335 Block responseBlock;
2336 if (response != null) {
2337 responseBodyBlocks = response.getBodyBlocks();
2338 responseBlock =
2339 responseBodyBlocks.hasNext()
2340 ? response.getBodyBlocks().next()
2341 : null;
2342 }
2344 // build a signature of the form "opName%arg1type%arg2type%...%argntype so that we
2345 // detect overloading conflicts in the generated java interface/classes
2346 String signature = candidateName;
2347 for (Iterator iter = request.getParameters(); iter.hasNext();) {
2348 Parameter parameter = (Parameter) iter.next();
2350 if (parameter.getJavaParameter() != null) {
2351 error(operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION(operation.getName().getLocalPart()));
2352 }
2354 JavaType parameterType = parameter.getType().getJavaType();
2355 JavaParameter javaParameter =
2356 new JavaParameter(
2357 BindingHelper.mangleNameToVariableName(parameter.getName()),
2358 parameterType,
2359 parameter,
2360 parameter.getLinkedParameter() != null);
2361 if (javaParameter.isHolder()) {
2362 javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
2363 }
2364 method.addParameter(javaParameter);
2365 parameter.setJavaParameter(javaParameter);
2367 signature += "%" + parameterType.getName();
2368 }
2370 if (response != null) {
2371 String resultParameterName =
2372 (String) operation.getProperty(WSDL_RESULT_PARAMETER);
2373 Parameter resultParameter =
2374 response.getParameterByName(resultParameterName);
2375 JavaType returnType = resultParameter.getType().getJavaType();
2376 method.setReturnType(returnType);
2378 }
2379 operation.setJavaMethod(method);
2380 intf.addMethod(method);
2381 }
2383 /* (non-Javadoc)
2384 * @see WSDLModelerBase#createJavaMethodForOperation(WSDLPort, WSDLOperation, JavaInterface, Set, Set)
2385 */
2386 protected void createJavaMethodForOperation(Port port, Operation operation, JavaInterface intf) {
2387 if ((operation instanceof AsyncOperation)) {
2388 createJavaMethodForAsyncOperation(port, operation, intf);
2389 return;
2390 }
2391 String candidateName = getJavaNameForOperation(operation);
2392 JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
2393 Request request = operation.getRequest();
2394 Parameter returnParam = (Parameter) operation.getProperty(WSDL_RESULT_PARAMETER);
2395 if (returnParam != null) {
2396 JavaType parameterType = returnParam.getType().getJavaType();
2397 method.setReturnType(parameterType);
2398 } else {
2399 method.setReturnType(JavaSimpleTypeCreator.VOID_JAVATYPE);
2400 }
2401 List<Parameter> parameterOrder = (List<Parameter>) operation.getProperty(WSDL_PARAMETER_ORDER);
2402 for (Parameter param : parameterOrder) {
2403 JavaType parameterType = param.getType().getJavaType();
2404 String name = (param.getCustomName() != null) ? param.getCustomName() : param.getName();
2405 name = BindingHelper.mangleNameToVariableName(name);
2406 //if its a java keyword after name mangling, then we simply put underscore as there is no
2407 //need to ask user to customize the parameter name if its java keyword
2408 if(Names.isJavaReservedWord(name)){
2409 name = "_"+name;
2410 }
2411 JavaParameter javaParameter =
2412 new JavaParameter(
2413 name,
2414 parameterType,
2415 param,
2416 param.isINOUT() || param.isOUT());
2417 if (javaParameter.isHolder()) {
2418 javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
2419 }
2420 method.addParameter(javaParameter);
2421 param.setJavaParameter(javaParameter);
2422 }
2423 operation.setJavaMethod(method);
2424 intf.addMethod(method);
2426 String opName = BindingHelper.mangleNameToVariableName(operation.getName().getLocalPart());
2427 for (Iterator iter = operation.getFaults();
2428 iter != null && iter.hasNext();
2429 ) {
2430 Fault fault = (Fault) iter.next();
2431 createJavaExceptionFromLiteralType(fault, port, opName);
2432 }
2433 JavaException javaException;
2434 Fault fault;
2435 for (Iterator iter = operation.getFaults(); iter.hasNext();) {
2436 fault = (Fault) iter.next();
2437 javaException = fault.getJavaException();
2438 method.addException(javaException.getName());
2439 }
2441 }
2443 protected boolean createJavaExceptionFromLiteralType(Fault fault, com.sun.tools.internal.ws.processor.model.Port port, String operationName) {
2444 JAXBType faultType = (JAXBType) fault.getBlock().getType();
2446 String exceptionName = fault.getName();
2448 // use fault namespace attribute
2449 JAXBStructuredType jaxbStruct = new JAXBStructuredType(new QName(
2450 fault.getBlock().getName().getNamespaceURI(),
2451 fault.getName()));
2453 QName memberName = fault.getElementName();
2454 JAXBElementMember jaxbMember =
2455 new JAXBElementMember(memberName, faultType);
2456 //jaxbMember.setNillable(faultType.isNillable());
2458 String javaMemberName = getLiteralJavaMemberName(fault);
2459 JavaStructureMember javaMember = new JavaStructureMember(
2460 javaMemberName,
2461 faultType.getJavaType(),
2462 jaxbMember);
2463 jaxbMember.setJavaStructureMember(javaMember);
2464 javaMember.setReadMethod(Names.getJavaMemberReadMethod(javaMember));
2465 javaMember.setInherited(false);
2466 jaxbMember.setJavaStructureMember(javaMember);
2467 jaxbStruct.add(jaxbMember);
2469 if (isConflictingExceptionClassName(exceptionName)) {
2470 exceptionName += "_Exception";
2471 }
2473 JavaException existingJavaException = _javaExceptions.get(exceptionName);
2474 if (existingJavaException != null) {
2475 if (existingJavaException.getName().equals(exceptionName)) {
2476 if (((JAXBType) existingJavaException.getOwner()).getName().equals(jaxbStruct.getName())
2477 || ModelerUtils.isEquivalentLiteralStructures(jaxbStruct, (JAXBStructuredType) existingJavaException.getOwner())) {
2478 // we have mapped this fault already
2479 if (faultType instanceof JAXBStructuredType) {
2480 fault.getBlock().setType((JAXBType) existingJavaException.getOwner());
2481 }
2482 fault.setJavaException(existingJavaException);
2483 return false;
2484 }
2485 }
2486 }
2488 JavaException javaException = new JavaException(exceptionName, false, jaxbStruct);
2489 javaException.add(javaMember);
2490 jaxbStruct.setJavaType(javaException);
2492 _javaExceptions.put(javaException.getName(), javaException);
2494 fault.setJavaException(javaException);
2495 return true;
2496 }
2498 protected boolean isRequestResponse() {
2499 return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
2500 }
2502 protected java.util.List<String> getAsynParameterOrder() {
2503 //for async operation ignore the parameterOrder
2504 java.util.List<String> parameterList = new ArrayList<String>();
2505 Message inputMessage = getInputMessage();
2506 List<MessagePart> inputParts = inputMessage.getParts();
2507 for (MessagePart part : inputParts) {
2508 parameterList.add(part.getName());
2509 }
2510 return parameterList;
2511 }
2514 protected List<MessagePart> getParameterOrder() {
2515 List<MessagePart> params = new ArrayList<MessagePart>();
2516 String parameterOrder = info.portTypeOperation.getParameterOrder();
2517 java.util.List<String> parameterList = new ArrayList<String>();
2518 boolean parameterOrderPresent = false;
2519 if ((parameterOrder != null) && !(parameterOrder.trim().equals(""))) {
2520 parameterList = XmlUtil.parseTokenList(parameterOrder);
2521 parameterOrderPresent = true;
2522 } else {
2523 parameterList = new ArrayList<String>();
2524 }
2525 Message inputMessage = getInputMessage();
2526 Message outputMessage = getOutputMessage();
2527 List<MessagePart> outputParts = null;
2528 List<MessagePart> inputParts = inputMessage.getParts();
2529 //reset the mode and ret flag, as MEssagePArts aer shared across ports
2530 for (MessagePart part : inputParts) {
2531 part.setMode(Mode.IN);
2532 part.setReturn(false);
2533 }
2534 if (isRequestResponse()) {
2535 outputParts = outputMessage.getParts();
2536 for (MessagePart part : outputParts) {
2537 part.setMode(Mode.OUT);
2538 part.setReturn(false);
2539 }
2540 }
2542 if (parameterOrderPresent) {
2543 boolean validParameterOrder = true;
2544 Iterator<String> paramOrders = parameterList.iterator();
2545 // If any part in the parameterOrder is not present in the request or
2546 // response message, we completely ignore the parameterOrder hint
2547 while (paramOrders.hasNext()) {
2548 String param = paramOrders.next();
2549 boolean partFound = false;
2550 for (MessagePart part : inputParts) {
2551 if (param.equals(part.getName())) {
2552 partFound = true;
2553 break;
2554 }
2555 }
2556 // if not found, check in output parts
2557 if (!partFound) {
2558 for (MessagePart part : outputParts) {
2559 if (param.equals(part.getName())) {
2560 partFound = true;
2561 break;
2562 }
2563 }
2564 }
2565 if (!partFound) {
2566 warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETERORDER_PARAMETER(param, info.operation.getName().getLocalPart()));
2567 validParameterOrder = false;
2568 }
2569 }
2571 List<MessagePart> inputUnlistedParts = new ArrayList<MessagePart>();
2572 List<MessagePart> outputUnlistedParts = new ArrayList<MessagePart>();
2574 //gather input Parts
2575 if (validParameterOrder) {
2576 for (String param : parameterList) {
2577 MessagePart part = inputMessage.getPart(param);
2578 if (part != null) {
2579 params.add(part);
2580 continue;
2581 }
2582 if (isRequestResponse()) {
2583 MessagePart outPart = outputMessage.getPart(param);
2584 if (outPart != null) {
2585 params.add(outPart);
2586 }
2587 }
2588 }
2590 for (MessagePart part : inputParts) {
2591 if (!parameterList.contains(part.getName())) {
2592 inputUnlistedParts.add(part);
2593 }
2594 }
2596 if (isRequestResponse()) {
2597 // at most one output part should be unlisted
2598 for (MessagePart part : outputParts) {
2599 if (!parameterList.contains(part.getName())) {
2600 MessagePart inPart = inputMessage.getPart(part.getName());
2601 //dont add inout as unlisted part
2602 if ((inPart != null) && inPart.getDescriptor().equals(part.getDescriptor())) {
2603 inPart.setMode(Mode.INOUT);
2604 } else {
2605 outputUnlistedParts.add(part);
2606 }
2607 } else {
2608 //param list may contain it, check if its INOUT
2609 MessagePart inPart = inputMessage.getPart(part.getName());
2610 //dont add inout as unlisted part
2611 if ((inPart != null) && inPart.getDescriptor().equals(part.getDescriptor())) {
2612 inPart.setMode(Mode.INOUT);
2613 } else if (!params.contains(part)) {
2614 params.add(part);
2615 }
2616 }
2617 }
2618 if (outputUnlistedParts.size() == 1) {
2619 MessagePart resultPart = outputUnlistedParts.get(0);
2620 resultPart.setReturn(true);
2621 params.add(resultPart);
2622 outputUnlistedParts.clear();
2623 }
2624 }
2626 //add the input and output unlisted parts
2627 for (MessagePart part : inputUnlistedParts) {
2628 params.add(part);
2629 }
2631 for (MessagePart part : outputUnlistedParts) {
2632 params.add(part);
2633 }
2634 return params;
2636 }
2637 //parameterOrder attribute is not valid, we ignore it
2638 warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETER_ORDER_INVALID_PARAMETER_ORDER(info.operation.getName().getLocalPart()));
2639 parameterOrderPresent = false;
2640 parameterList.clear();
2641 }
2643 List<MessagePart> outParts = new ArrayList<MessagePart>();
2645 //construct input parameter list with the same order as in input message
2646 for (MessagePart part : inputParts) {
2647 params.add(part);
2648 }
2650 if (isRequestResponse()) {
2651 for (MessagePart part : outputParts) {
2652 MessagePart inPart = inputMessage.getPart(part.getName());
2653 if (inPart != null && part.getDescriptorKind() == inPart.getDescriptorKind() &&
2654 part.getDescriptor().equals(inPart.getDescriptor())) {
2655 inPart.setMode(Mode.INOUT);
2656 continue;
2657 }
2658 outParts.add(part);
2659 }
2661 //append the out parts to the parameterList
2662 for (MessagePart part : outParts) {
2663 if (outParts.size() == 1)
2664 part.setReturn(true);
2665 params.add(part);
2666 }
2667 }
2668 return params;
2669 }
2671 /**
2672 * @param port
2673 * @param suffix
2674 * @return the Java ClassName for a port
2675 */
2676 protected String getClassName(Port port, String suffix) {
2677 String prefix = BindingHelper.mangleNameToClassName((port.getName().getLocalPart()));
2678 return options.defaultPackage + "." + prefix + suffix;
2679 }
2681 protected boolean isConflictingServiceClassName(String name) {
2682 return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name) || conflictsWithExceptionClass(name);
2683 }
2685 private boolean conflictsWithSEIClass(String name) {
2686 Set<String> seiNames = classNameCollector.getSeiClassNames();
2687 return seiNames != null && seiNames.contains(name);
2688 }
2690 private boolean conflictsWithJAXBClass(String name) {
2691 Set<String> jaxbNames = classNameCollector.getJaxbGeneratedClassNames();
2692 return jaxbNames != null && jaxbNames.contains(name);
2693 }
2695 private boolean conflictsWithExceptionClass(String name) {
2696 Set<String> exceptionNames = classNameCollector.getExceptionClassNames();
2697 return exceptionNames != null && exceptionNames.contains(name);
2698 }
2700 protected boolean isConflictingExceptionClassName(String name) {
2701 return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name);
2702 }
2704 protected JAXBModelBuilder getJAXBModelBuilder() {
2705 return jaxbModelBuilder;
2706 }
2708 protected boolean validateWSDLBindingStyle(Binding binding) {
2709 SOAPBinding soapBinding =
2710 (SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
2712 //dont process the binding
2713 if (soapBinding == null)
2714 soapBinding =
2715 (SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
2716 if (soapBinding == null)
2717 return false;
2719 //if soapbind:binding has no style attribute, the default is DOCUMENT
2720 if (soapBinding.getStyle() == null)
2721 soapBinding.setStyle(SOAPStyle.DOCUMENT);
2723 SOAPStyle opStyle = soapBinding.getStyle();
2724 for (Iterator iter = binding.operations(); iter.hasNext();) {
2725 BindingOperation bindingOperation =
2726 (BindingOperation) iter.next();
2727 SOAPOperation soapOperation =
2728 (SOAPOperation) getExtensionOfType(bindingOperation,
2729 SOAPOperation.class);
2730 if (soapOperation != null) {
2731 SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation.getStyle() : soapBinding.getStyle();
2732 //dont check for the first operation
2733 if (!currOpStyle.equals(opStyle))
2734 return false;
2735 }
2736 }
2737 return true;
2738 }
2740 /**
2741 * @param port
2742 */
2743 private void applyWrapperStyleCustomization(Port port, PortType portType) {
2744 JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
2745 Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding.isEnableWrapperStyle() : null;
2746 if (wrapperStyle != null) {
2747 port.setWrapped(wrapperStyle);
2748 }
2749 }
2751 protected static void setDocumentationIfPresent(
2752 ModelObject obj,
2753 Documentation documentation) {
2754 if (documentation != null && documentation.getContent() != null) {
2755 obj.setJavaDoc(documentation.getContent());
2756 }
2757 }
2759 protected String getJavaNameForOperation(Operation operation) {
2760 String name = operation.getJavaMethodName();
2761 if (Names.isJavaReservedWord(name)) {
2762 name = "_" + name;
2763 }
2764 return name;
2765 }
2767 private void reportError(Entity entity,
2768 String formattedMsg, Exception nestedException ) {
2769 Locator locator = (entity == null)?null:entity.getLocator();
2771 SAXParseException e = new SAXParseException2( formattedMsg,
2772 locator,
2773 nestedException );
2774 errReceiver.error(e);
2775 }
2777 }