src/share/jaxws_classes/com/sun/tools/internal/ws/processor/modeler/wsdl/WSDLModelerBase.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
30 import com.sun.tools.internal.ws.processor.generator.Names; 30 import com.sun.tools.internal.ws.processor.generator.Names;
31 import com.sun.tools.internal.ws.processor.model.Fault; 31 import com.sun.tools.internal.ws.processor.model.Fault;
32 import com.sun.tools.internal.ws.processor.model.Operation; 32 import com.sun.tools.internal.ws.processor.model.Operation;
33 import com.sun.tools.internal.ws.processor.model.Port; 33 import com.sun.tools.internal.ws.processor.model.Port;
34 import com.sun.tools.internal.ws.processor.model.java.JavaException; 34 import com.sun.tools.internal.ws.processor.model.java.JavaException;
35 import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
36 import com.sun.tools.internal.ws.processor.modeler.Modeler; 35 import com.sun.tools.internal.ws.processor.modeler.Modeler;
37 import com.sun.tools.internal.ws.resources.ModelerMessages; 36 import com.sun.tools.internal.ws.resources.ModelerMessages;
38 import com.sun.tools.internal.ws.wscompile.AbortException; 37 import com.sun.tools.internal.ws.wscompile.AbortException;
39 import com.sun.tools.internal.ws.wscompile.ErrorReceiver; 38 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
40 import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter; 39 import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter;
47 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds; 46 import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
48 import com.sun.tools.internal.ws.wsdl.document.soap.*; 47 import com.sun.tools.internal.ws.wsdl.document.soap.*;
49 import com.sun.tools.internal.ws.wsdl.framework.Entity; 48 import com.sun.tools.internal.ws.wsdl.framework.Entity;
50 import com.sun.tools.internal.ws.wsdl.framework.GloballyKnown; 49 import com.sun.tools.internal.ws.wsdl.framework.GloballyKnown;
51 import com.sun.tools.internal.ws.wsdl.framework.NoSuchEntityException; 50 import com.sun.tools.internal.ws.wsdl.framework.NoSuchEntityException;
52 import com.sun.tools.internal.ws.wsdl.parser.DOMForest;
53 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser; 51 import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
54 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder; 52 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
55 import com.sun.xml.internal.ws.spi.db.BindingContext;
56 import com.sun.xml.internal.ws.spi.db.BindingHelper; 53 import com.sun.xml.internal.ws.spi.db.BindingHelper;
57 54
58 import org.xml.sax.helpers.LocatorImpl; 55 import org.xml.sax.helpers.LocatorImpl;
59 56
60 import javax.xml.namespace.QName; 57 import javax.xml.namespace.QName;
82 * 79 *
83 * @param port 80 * @param port
84 * @param wsdlPort 81 * @param wsdlPort
85 */ 82 */
86 protected void applyPortMethodCustomization(Port port, com.sun.tools.internal.ws.wsdl.document.Port wsdlPort) { 83 protected void applyPortMethodCustomization(Port port, com.sun.tools.internal.ws.wsdl.document.Port wsdlPort) {
87 if(isProvider(wsdlPort)) 84 if (isProvider(wsdlPort)) {
88 return; 85 return;
86 }
89 JAXWSBinding jaxwsBinding = (JAXWSBinding)getExtensionOfType(wsdlPort, JAXWSBinding.class); 87 JAXWSBinding jaxwsBinding = (JAXWSBinding)getExtensionOfType(wsdlPort, JAXWSBinding.class);
90 88
91 String portMethodName = (jaxwsBinding != null)?((jaxwsBinding.getMethodName() != null)?jaxwsBinding.getMethodName().getName():null):null; 89 String portMethodName = (jaxwsBinding != null)?((jaxwsBinding.getMethodName() != null)?jaxwsBinding.getMethodName().getName():null):null;
92 if(portMethodName != null){ 90 if(portMethodName != null){
93 port.setPortGetter(portMethodName); 91 port.setPortGetter(portMethodName);
106 return isProvider; 104 return isProvider;
107 } 105 }
108 106
109 JAXWSBinding jaxwsGlobalCustomization = (JAXWSBinding)getExtensionOfType(document.getDefinitions(), JAXWSBinding.class); 107 JAXWSBinding jaxwsGlobalCustomization = (JAXWSBinding)getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
110 isProvider = (jaxwsGlobalCustomization != null)?jaxwsGlobalCustomization.isProvider():null; 108 isProvider = (jaxwsGlobalCustomization != null)?jaxwsGlobalCustomization.isProvider():null;
111 if(isProvider != null) 109 if (isProvider != null) {
112 return isProvider; 110 return isProvider;
111 }
113 return false; 112 return false;
114 } 113 }
115 114
116 protected SOAPBody getSOAPRequestBody() { 115 protected SOAPBody getSOAPRequestBody() {
117 SOAPBody requestBody = 116 SOAPBody requestBody =
155 } 154 }
156 return responseBody; 155 return responseBody;
157 } 156 }
158 157
159 protected com.sun.tools.internal.ws.wsdl.document.Message getOutputMessage() { 158 protected com.sun.tools.internal.ws.wsdl.document.Message getOutputMessage() {
160 if (info.portTypeOperation.getOutput() == null) 159 if (info.portTypeOperation.getOutput() == null) {
161 return null; 160 return null;
161 }
162 return info.portTypeOperation.getOutput().resolveMessage(info.document); 162 return info.portTypeOperation.getOutput().resolveMessage(info.document);
163 } 163 }
164 164
165 protected com.sun.tools.internal.ws.wsdl.document.Message getInputMessage() { 165 protected com.sun.tools.internal.ws.wsdl.document.Message getInputMessage() {
166 return info.portTypeOperation.getInput().resolveMessage(info.document); 166 return info.portTypeOperation.getInput().resolveMessage(info.document);
178 ArrayList<MessagePart> partsList = new ArrayList<MessagePart>(); 178 ArrayList<MessagePart> partsList = new ArrayList<MessagePart>();
179 List<MessagePart> parts = new ArrayList<MessagePart>(); 179 List<MessagePart> parts = new ArrayList<MessagePart>();
180 180
181 //get Mime parts 181 //get Mime parts
182 List mimeParts; 182 List mimeParts;
183 if(isInput) 183 if (isInput) {
184 mimeParts = getMimeContentParts(message, info.bindingOperation.getInput()); 184 mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
185 else 185 } else {
186 mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput()); 186 mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
187 }
187 188
188 if (bodyParts != null) { 189 if (bodyParts != null) {
189 StringTokenizer in = new StringTokenizer(bodyParts.trim(), " "); 190 StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
190 while (in.hasMoreTokens()) { 191 while (in.hasMoreTokens()) {
191 String part = in.nextToken(); 192 String part = in.nextToken();
196 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING); 197 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
197 partsList.add(mPart); 198 partsList.add(mPart);
198 } 199 }
199 } else { 200 } else {
200 for (MessagePart mPart : message.getParts()) { 201 for (MessagePart mPart : message.getParts()) {
201 if (!mimeParts.contains(mPart)) 202 if (!mimeParts.contains(mPart)) {
202 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING); 203 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
204 }
203 partsList.add(mPart); 205 partsList.add(mPart);
204 } 206 }
205 } 207 }
206 208
207 for (MessagePart mPart : message.getParts()) { 209 for (MessagePart mPart : message.getParts()) {
208 if(mimeParts.contains(mPart)) { 210 if (mimeParts.contains(mPart)) {
209 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING); 211 mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
210 parts.add(mPart); 212 parts.add(mPart);
211 }else if(partsList.contains(mPart)) { 213 } else if(partsList.contains(mPart)) {
212 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING); 214 mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
213 parts.add(mPart); 215 parts.add(mPart);
214 } 216 }
215 } 217 }
216 218
224 protected List<MessagePart> getMimeContentParts(Message message, TWSDLExtensible ext) { 226 protected List<MessagePart> getMimeContentParts(Message message, TWSDLExtensible ext) {
225 ArrayList<MessagePart> mimeContentParts = new ArrayList<MessagePart>(); 227 ArrayList<MessagePart> mimeContentParts = new ArrayList<MessagePart>();
226 228
227 for (MIMEPart mimePart : getMimeParts(ext)) { 229 for (MIMEPart mimePart : getMimeParts(ext)) {
228 MessagePart part = getMimeContentPart(message, mimePart); 230 MessagePart part = getMimeContentPart(message, mimePart);
229 if (part != null) 231 if (part != null) {
230 mimeContentParts.add(part); 232 mimeContentParts.add(part);
233 }
231 } 234 }
232 return mimeContentParts; 235 return mimeContentParts;
233 } 236 }
234 237
235 /** 238 /**
248 gotRootPart = true; 251 gotRootPart = true;
249 } else if (obj instanceof MIMEContent) { 252 } else if (obj instanceof MIMEContent) {
250 mimeContents.add((MIMEContent) obj); 253 mimeContents.add((MIMEContent) obj);
251 } 254 }
252 } 255 }
253 if(!validateMimeContentPartNames(mimeContents)) 256 if (!validateMimeContentPartNames(mimeContents)) {
254 return false; 257 return false;
258 }
255 if(mPart.getName() != null) { 259 if(mPart.getName() != null) {
256 warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_NAME_NOT_ALLOWED(info.portTypeOperation.getName())); 260 warning(mPart, ModelerMessages.MIMEMODELER_INVALID_MIME_PART_NAME_NOT_ALLOWED(info.portTypeOperation.getName()));
257 } 261 }
258 } 262 }
259 return true; 263 return true;
279 List<String> mimeTypes = new ArrayList<String>(); 283 List<String> mimeTypes = new ArrayList<String>();
280 //validateMimeContentPartNames(mimeContents.iterator()); 284 //validateMimeContentPartNames(mimeContents.iterator());
281 // String mimeType = null; 285 // String mimeType = null;
282 for(MIMEContent mimeContent:mimeContents){ 286 for(MIMEContent mimeContent:mimeContents){
283 String mimeType = getMimeContentType(mimeContent); 287 String mimeType = getMimeContentType(mimeContent);
284 if(!mimeTypes.contains(mimeType)) 288 if (!mimeTypes.contains(mimeType)) {
285 mimeTypes.add(mimeType); 289 mimeTypes.add(mimeType);
290 }
286 } 291 }
287 return mimeTypes; 292 return mimeTypes;
288 } 293 }
289 294
290 private boolean validateMimeContentPartNames(List<MIMEContent> mimeContents) { 295 private boolean validateMimeContentPartNames(List<MIMEContent> mimeContents) {
430 * @param part 435 * @param part
431 * @return true if part is the Root part 436 * @return true if part is the Root part
432 */ 437 */
433 private boolean isRootPart(MIMEPart part) { 438 private boolean isRootPart(MIMEPart part) {
434 for (TWSDLExtension twsdlExtension : part.extensions()) { 439 for (TWSDLExtension twsdlExtension : part.extensions()) {
435 if (twsdlExtension instanceof SOAPBody) 440 if (twsdlExtension instanceof SOAPBody) {
436 return true; 441 return true;
442 }
437 } 443 }
438 return false; 444 return false;
439 } 445 }
440 446
441 protected Set getDuplicateFaultNames() { 447 protected Set getDuplicateFaultNames() {
504 protected boolean validateBodyParts(BindingOperation operation) { 510 protected boolean validateBodyParts(BindingOperation operation) {
505 boolean isRequestResponse = 511 boolean isRequestResponse =
506 info.portTypeOperation.getStyle() 512 info.portTypeOperation.getStyle()
507 == OperationStyle.REQUEST_RESPONSE; 513 == OperationStyle.REQUEST_RESPONSE;
508 List<MessagePart> inputParts = getMessageParts(getSOAPRequestBody(), getInputMessage(), true); 514 List<MessagePart> inputParts = getMessageParts(getSOAPRequestBody(), getInputMessage(), true);
509 if(!validateStyleAndPart(operation, inputParts)) 515 if (!validateStyleAndPart(operation, inputParts)) {
510 return false; 516 return false;
517 }
511 518
512 if(isRequestResponse){ 519 if(isRequestResponse){
513 List<MessagePart> outputParts = getMessageParts(getSOAPResponseBody(), getOutputMessage(), false); 520 List<MessagePart> outputParts = getMessageParts(getSOAPResponseBody(), getOutputMessage(), false);
514 if(!validateStyleAndPart(operation, outputParts)) 521 if (!validateStyleAndPart(operation, outputParts)) {
515 return false; 522 return false;
523 }
516 } 524 }
517 return true; 525 return true;
518 } 526 }
519 527
520 /** 528 /**
524 private boolean validateStyleAndPart(BindingOperation operation, List<MessagePart> parts) { 532 private boolean validateStyleAndPart(BindingOperation operation, List<MessagePart> parts) {
525 SOAPOperation soapOperation = 533 SOAPOperation soapOperation =
526 (SOAPOperation) getExtensionOfType(operation, SOAPOperation.class); 534 (SOAPOperation) getExtensionOfType(operation, SOAPOperation.class);
527 for (MessagePart part : parts) { 535 for (MessagePart part : parts) {
528 if (part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING) { 536 if (part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING) {
529 if (!isStyleAndPartMatch(soapOperation, part)) 537 if (!isStyleAndPartMatch(soapOperation, part)) {
530 return false; 538 return false;
539 }
531 } 540 }
532 } 541 }
533 return true; 542 return true;
534 } 543 }
535 544
536 protected String getLiteralJavaMemberName(Fault fault) { 545 protected String getLiteralJavaMemberName(Fault fault) {
537 String javaMemberName; 546 String javaMemberName;
538 547
539 QName memberName = fault.getElementName(); 548 QName memberName = fault.getElementName();
540 javaMemberName = fault.getJavaMemberName(); 549 javaMemberName = fault.getJavaMemberName();
541 if (javaMemberName == null) 550 if (javaMemberName == null) {
542 javaMemberName = memberName.getLocalPart(); 551 javaMemberName = memberName.getLocalPart();
552 }
543 return javaMemberName; 553 return javaMemberName;
544 } 554 }
545 555
546 /** 556 /**
547 * @param ext 557 * @param ext
551 */ 561 */
552 protected List<MIMEContent> getMimeContents(TWSDLExtensible ext, Message message, String name) { 562 protected List<MIMEContent> getMimeContents(TWSDLExtensible ext, Message message, String name) {
553 for (MIMEPart mimePart : getMimeParts(ext)) { 563 for (MIMEPart mimePart : getMimeParts(ext)) {
554 List<MIMEContent> mimeContents = getMimeContents(mimePart); 564 List<MIMEContent> mimeContents = getMimeContents(mimePart);
555 for (MIMEContent mimeContent : mimeContents) { 565 for (MIMEContent mimeContent : mimeContents) {
556 if (mimeContent.getPart().equals(name)) 566 if (mimeContent.getPart().equals(name)) {
557 return mimeContents; 567 return mimeContents;
568 }
558 } 569 }
559 } 570 }
560 return null; 571 return null;
561 } 572 }
562 573
603 } 614 }
604 615
605 protected TWSDLExtension getAnyExtensionOfType( 616 protected TWSDLExtension getAnyExtensionOfType(
606 TWSDLExtensible extensible, 617 TWSDLExtensible extensible,
607 Class type) { 618 Class type) {
608 if(extensible == null) 619 if (extensible == null) {
609 return null; 620 return null;
621 }
610 for (TWSDLExtension extension:extensible.extensions()) { 622 for (TWSDLExtension extension:extensible.extensions()) {
611 if(extension.getClass().equals(type)) { 623 if(extension.getClass().equals(type)) {
612 return extension; 624 return extension;
613 }else if (extension.getClass().equals(MIMEMultipartRelated.class) && 625 }else if (extension.getClass().equals(MIMEMultipartRelated.class) &&
614 (type.equals(SOAPBody.class) || type.equals(MIMEContent.class) 626 (type.equals(SOAPBody.class) || type.equals(MIMEContent.class)
615 || type.equals(MIMEPart.class))) { 627 || type.equals(MIMEPart.class))) {
616 for (MIMEPart part : ((MIMEMultipartRelated)extension).getParts()) { 628 for (MIMEPart part : ((MIMEMultipartRelated)extension).getParts()) {
617 //bug fix: 5024001 629 //bug fix: 5024001
618 TWSDLExtension extn = getExtensionOfType(part, type); 630 TWSDLExtension extn = getExtensionOfType(part, type);
619 if (extn != null) 631 if (extn != null) {
620 return extn; 632 return extn;
633 }
621 } 634 }
622 } 635 }
623 } 636 }
624 637
625 return null; 638 return null;
658 } 671 }
659 672
660 protected String getUniqueClassName(String className) { 673 protected String getUniqueClassName(String className) {
661 int cnt = 2; 674 int cnt = 2;
662 String uniqueName = className; 675 String uniqueName = className;
663 while (reqResNames.contains(uniqueName.toLowerCase())) { 676 while (reqResNames.contains(uniqueName.toLowerCase(Locale.ENGLISH))) {
664 uniqueName = className + cnt; 677 uniqueName = className + cnt;
665 cnt++; 678 cnt++;
666 } 679 }
667 reqResNames.add(uniqueName.toLowerCase()); 680 reqResNames.add(uniqueName.toLowerCase(Locale.ENGLISH));
668 return uniqueName; 681 return uniqueName;
669 } 682 }
670 683
671 protected boolean isConflictingClassName(String name) { 684 protected boolean isConflictingClassName(String name) {
672 if (_conflictingClassNames == null) { 685 if (_conflictingClassNames == null) {
698 711
699 int numPasses = 0; 712 int numPasses = 0;
700 713
701 protected void warning(Entity entity, String message){ 714 protected void warning(Entity entity, String message){
702 //avoid duplicate warning for the second pass 715 //avoid duplicate warning for the second pass
703 if(numPasses > 1) 716 if (numPasses > 1) {
704 return; 717 return;
705 if(entity == null) 718 }
719 if (entity == null) {
706 errReceiver.warning(null, message); 720 errReceiver.warning(null, message);
707 else 721 } else {
708 errReceiver.warning(entity.getLocator(), message); 722 errReceiver.warning(entity.getLocator(), message);
723 }
709 } 724 }
710 725
711 protected void error(Entity entity, String message){ 726 protected void error(Entity entity, String message){
712 if(entity == null) 727 if (entity == null) {
713 errReceiver.error(null, message); 728 errReceiver.error(null, message);
714 else 729 } else {
715 errReceiver.error(entity.getLocator(), message); 730 errReceiver.error(entity.getLocator(), message);
731 }
716 throw new AbortException(); 732 throw new AbortException();
717 } 733 }
718 734
719 protected static final String OPERATION_HAS_VOID_RETURN_TYPE = 735 protected static final String OPERATION_HAS_VOID_RETURN_TYPE =
720 "com.sun.xml.internal.ws.processor.modeler.wsdl.operationHasVoidReturnType"; 736 "com.sun.xml.internal.ws.processor.modeler.wsdl.operationHasVoidReturnType";
730 746
731 private Set _conflictingClassNames; 747 private Set _conflictingClassNames;
732 protected Map<String,JavaException> _javaExceptions; 748 protected Map<String,JavaException> _javaExceptions;
733 protected Map _faultTypeToStructureMap; 749 protected Map _faultTypeToStructureMap;
734 protected Map<QName, Port> _bindingNameToPortMap; 750 protected Map<QName, Port> _bindingNameToPortMap;
735 protected boolean useWSIBasicProfile = true;
736 751
737 private final Set<String> reqResNames = new HashSet<String>(); 752 private final Set<String> reqResNames = new HashSet<String>();
738 753
739 public class ProcessSOAPOperationInfo { 754 public static class ProcessSOAPOperationInfo {
740 755
741 public ProcessSOAPOperationInfo( 756 public ProcessSOAPOperationInfo(
742 Port modelPort, 757 Port modelPort,
743 com.sun.tools.internal.ws.wsdl.document.Port port, 758 com.sun.tools.internal.ws.wsdl.document.Port port,
744 com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation, 759 com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation,
766 public boolean hasOverloadedOperations; 781 public boolean hasOverloadedOperations;
767 public Map headers; 782 public Map headers;
768 783
769 // additional data 784 // additional data
770 public Operation operation; 785 public Operation operation;
771 public String uniqueOperationName; 786 }
772 }
773
774 public static class WSDLExceptionInfo {
775 public String exceptionType;
776 public QName wsdlMessage;
777 public String wsdlMessagePartName;
778 public HashMap constructorOrder; // mapping of element name to
779 // constructor order (of type Integer)
780 }
781
782 787
783 protected WSDLParser parser; 788 protected WSDLParser parser;
784 protected WSDLDocument document; 789 protected WSDLDocument document;
785 protected static final LocatorImpl NULL_LOCATOR = new LocatorImpl(); 790 protected static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
786 } 791 }

mercurial