1 19 20 package org.netbeans.modules.xml.wsdl.validator.visitor; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Properties ; 28 import java.util.Set ; 29 import java.util.Vector ; 30 import org.netbeans.modules.xml.schema.model.Annotation; 31 import org.netbeans.modules.xml.schema.model.Schema; 32 import org.netbeans.modules.xml.schema.model.SchemaComponent; 33 import org.netbeans.modules.xml.schema.model.SchemaModel; 34 import org.netbeans.modules.xml.wsdl.model.Binding; 35 import org.netbeans.modules.xml.wsdl.model.BindingFault; 36 import org.netbeans.modules.xml.wsdl.model.BindingInput; 37 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 38 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 39 import org.netbeans.modules.xml.wsdl.model.Definitions; 40 import org.netbeans.modules.xml.wsdl.model.Documentation; 41 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 42 import org.netbeans.modules.xml.wsdl.model.Fault; 43 import org.netbeans.modules.xml.wsdl.model.Import; 44 import org.netbeans.modules.xml.wsdl.model.Input; 45 import org.netbeans.modules.xml.wsdl.model.Message; 46 import org.netbeans.modules.xml.wsdl.model.NotificationOperation; 47 import org.netbeans.modules.xml.wsdl.model.OneWayOperation; 48 import org.netbeans.modules.xml.wsdl.model.Operation; 49 import org.netbeans.modules.xml.wsdl.model.Output; 50 import org.netbeans.modules.xml.wsdl.model.Part; 51 import org.netbeans.modules.xml.wsdl.model.Port; 52 import org.netbeans.modules.xml.wsdl.model.PortType; 53 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 54 import org.netbeans.modules.xml.wsdl.model.Service; 55 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation; 56 import org.netbeans.modules.xml.wsdl.model.Types; 57 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 58 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 59 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema; 60 import org.netbeans.modules.xml.wsdl.model.impl.WSDLAttribute; 61 import org.netbeans.modules.xml.wsdl.model.spi.GenericExtensibilityElement.StringAttribute; 62 import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor; 63 import org.netbeans.modules.xml.wsdl.validator.visitor.schema.SchemaSemanticsVisitor; 64 import org.netbeans.modules.xml.xam.Model; 65 import org.netbeans.modules.xml.xam.Reference; 66 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 67 import org.netbeans.modules.xml.xam.spi.Validation; 68 import org.netbeans.modules.xml.xam.spi.Validator; 69 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 70 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 71 import org.openide.util.NbBundle; 72 73 74 75 83 public class WSDLSemanticsVisitor implements WSDLVisitor { 84 85 private ValidateSupport mValidateSupport = null; 86 87 private static ValidateConfiguration mValConfig; 88 89 90 public static final String VAL_FAULT_NOT_ALLOWED_IN_OPERATION = "VAL_FAULT_NOT_ALLOWED_IN_OPERATION"; 92 94 public static final String FIX_FAULT_NOT_ALLOWED_IN_OPERATION = "FIX_FAULT_NOT_ALLOWED_IN_OPERATION"; 96 97 public static final String VAL_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT = 98 "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT"; 99 100 101 public static final String VAL_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT = 102 "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT"; 103 104 105 public static final String VAL_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT = 106 "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT"; 107 108 109 public static final String FIX_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT = 110 "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT"; 111 112 113 public static final String FIX_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT = 114 "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT"; 115 116 117 public static final String FIX_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT = 118 "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT"; 119 120 121 public static final String VAL_SCHEMA_DEFINED_NOT_FOUND = "VAL_SCHEMA_DEFINED_NOT_FOUND"; 122 123 124 public static final String FIX_SCHEMA_DEFINED_NOT_FOUND = "FIX_SCHEMA_DEFINED_NOT_FOUND"; 125 126 127 public static final String VAL_NO_SCHEMA_DEFINED = "VAL_NO_SCHEMA_DEFINED"; 128 129 130 public static final String FIX_NO_SCHEMA_DEFINED = "FIX_NO_SCHEMA_DEFINED"; 131 132 133 public static final String VAL_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL = "VAL_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL"; 134 135 136 public static final String FIX_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL = "FIX_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL"; 137 138 139 public static final String VAL_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED = "VAL_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED"; 140 141 142 public static final String FIX_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED = "FIX_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED"; 143 144 145 public static final String VAL_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "VAL_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART"; 146 147 148 public static final String FIX_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "FIX_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART"; 149 150 151 public static final String VAL_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "VAL_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART"; 152 153 154 public static final String FIX_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "FIX_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART"; 155 156 157 158 public static final String VAL_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "VAL_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID"; 159 160 161 public static final String FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID"; 162 163 164 public static final String VAL_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "VAL_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID"; 165 166 167 public static final String FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID"; 168 169 170 public static final String VAL_MISSING_PORTTYPE_IN_BINDING = "VAL_MISSING_PORTTYPE_IN_BINDING"; 171 public static final String FIX_MISSING_PORTTYPE_IN_BINDING = "FIX_MISSING_PORTTYPE_IN_BINDING"; 172 173 174 public static final String VAL_MISSING_BINDING_IN_SERVICE_PORT = "VAL_MISSING_BINDING_IN_SERVICE_PORT"; 175 public static final String FIX_MISSING_BINDING_IN_SERVICE_PORT = "FIX_MISSING_BINDING_IN_SERVICE_PORT"; 176 177 178 public static final String VAL_MISSING_IMPORTED_DOCUMENT = "VAL_MISSING_IMPORTED_DOCUMENT"; 179 public static final String FIX_MISSING_IMPORTED_DOCUMENT = "FIX_MISSING_IMPORTED_DOCUMENT"; 180 181 182 public static final String VAL_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE = "VAL_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE"; 183 public static final String FIX_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE = "FIX_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE"; 184 185 186 public static final String VAL_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE = "VAL_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE"; 187 public static final String FIX_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE = "FIX_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE"; 188 189 190 191 public static final String VAL_DUPLICATE_OPRATION_FAULT_NAME = "VAL_DUPLICATE_OPRATION_FAULT_NAME"; 192 public static final String FIX_DUPLICATE_OPRATION_FAULT_NAME = "FIX_DUPLICATE_OPRATION_FAULT_NAME"; 193 194 195 public static final String VAL_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE"; 196 public static final String FIX_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE"; 197 198 private static final String VAL_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE = "VAL_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE"; 199 200 private static final String FIX_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE = "FIX_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE"; 201 202 private static final String VAL_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "VAL_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST"; 203 204 private static final String FIX_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "FIX_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST"; 205 206 private static final String VAL_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "VAL_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST"; 207 208 private static final String FIX_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "FIX_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST"; 209 210 public static final String VAL_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE"; 211 public static final String FIX_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE"; 212 213 public static final String VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE"; 214 public static final String FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE"; 215 216 public static final String VAL_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE"; 217 public static final String FIX_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE"; 218 219 public static final String VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE"; 220 public static final String FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE"; 221 222 public static final String VAL_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE"; 223 public static final String FIX_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE"; 224 225 public static final String VAL_MULTIPLE_TYPES_IN_DEFINITION = "VAL_MULTIPLE_TYPES_IN_DEFINITION"; 226 public static final String FIX_MULTIPLE_TYPES_IN_DEFINITION = "FIX_MULTIPLE_TYPES_IN_DEFINITION"; 227 228 public static final String VAL_PARMETER_ORDER_CHECK_PART_EXISTENCE = "VAL_PARMETER_ORDER_CHECK_PART_EXISTENCE"; 229 public static final String FIX_PARMETER_ORDER_CHECK_PART_EXISTENCE = "FIX_PARMETER_ORDER_CHECK_PART_EXISTENCE"; 230 231 public static final String VAL_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING = "VAL_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING"; 232 public static final String FIX_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING = "FIX_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING"; 233 234 public List <ResultItem> mResultItems; 235 private Validation mValidation; 236 private List <Model> mValidatedModels; 237 private Validator mValidator; 238 239 240 public WSDLSemanticsVisitor(Validator validator, Validation validation, List <Model> validatedModels) { 241 242 Properties defaults = new Properties (); 243 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_REQUIRED, "true"); 244 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_QNAME, "true"); 245 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_NCNAME, "false"); 246 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_BOOLEAN, "true"); 247 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ELEM_MIN, "true"); 248 defaults.setProperty(ValidateConfiguration.WSDL_SYNTAX_ELEM_REQUIRED, "true"); 249 250 synchronized (this.getClass()) { 251 mValConfig = new ValidateConfiguration(defaults); 252 mResultItems = new Vector <ResultItem>(); 253 } 254 255 mValidator = validator; 256 mValidation = validation; 257 mValidatedModels = validatedModels; 258 259 getValidateSupport().setValidator(mValidator); 260 getValidateSupport().setResultItems(mResultItems); 261 } 262 263 public List <ResultItem> getResultItems() { 264 return mResultItems; 265 } 266 267 270 public ValidateSupport getValidateSupport() { 271 if (null == mValidateSupport) { 272 mValidateSupport = new ValidateSupport(mValConfig); 273 } 274 return mValidateSupport; 275 } 276 277 public Validation getValidation() { 278 return mValidation; 279 } 280 281 public void setValidation(Validation validation) { 282 this.mValidation = validation; 283 } 284 285 286 287 288 289 294 public void visit(Definitions w) { 295 if (w.getTargetNamespace() == null || w.getTargetNamespace().trim().length() == 0) { 296 getValidateSupport().fireToDo(Validator.ResultType.WARNING, w, NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE), 297 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE)); 298 299 } 300 301 List <Types> result = w.getChildren(Types.class); 302 if(result != null && result.size() > 1) { 303 getValidateSupport().fireToDo(Validator.ResultType.ERROR, w, NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MULTIPLE_TYPES_IN_DEFINITION), 305 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MULTIPLE_TYPES_IN_DEFINITION)); 306 307 308 } 309 310 visitChildren(w); 311 } 312 313 317 public void visit(Message w) { 318 if(w.getParts().size() == 0 ) { 320 getValidateSupport().fireToDo( 321 Validator.ResultType.WARNING, w, 322 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED, w.getName()), 323 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED, w.getName())); 324 } 325 326 visitChildren(w); 327 } 329 330 334 public void visit(final Part p) { 335 if(p.getElement() == null && p.getType() == null) { 337 getValidateSupport().fireToDo 338 (Validator.ResultType.ERROR, p, 339 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART, p.getName()), 340 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART)); 341 } 342 343 if(p.getElement() != null && p.getType() != null) { 345 getValidateSupport().fireToDo 346 (Validator.ResultType.ERROR, p, 347 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART, p.getName()), 348 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART)); 349 } 350 351 if(p.getElement() != null && p.getElement().get() == null) { 354 getValidateSupport().fireToDo 355 (Validator.ResultType.ERROR, p, 356 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID, p.getName(), p.getAttribute(new StringAttribute(Part.ELEMENT_PROPERTY))), NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID)); 358 } 359 360 if(p.getType() != null && p.getType().get() == null) { 363 getValidateSupport().fireToDo 364 (Validator.ResultType.ERROR, p, 365 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID, p.getName(), p.getAttribute(new StringAttribute(Part.TYPE_PROPERTY))), NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID)); 367 } 368 369 visitChildren(p); 370 } 373 374 379 public void visit(PortType portType) { 380 385 ArrayList <String > inputNames = new ArrayList <String >(); 388 ArrayList <String > outputNames = new ArrayList <String >(); 389 Collection operations = portType.getOperations(); 390 Iterator it = operations.iterator(); 391 while(it.hasNext()) { 392 Operation operation = (Operation) it.next(); 393 Input input = operation.getInput(); 394 if(input != null) { 395 String inputName = input.getName(); 396 if(inputName != null) { 397 if(!inputNames.contains(inputName)) { 398 inputNames.add(inputName); 399 } else { 400 getValidateSupport().fireToDo 402 (Validator.ResultType.ERROR, input, 403 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE, inputName, portType.getName()), 404 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE)); 405 } 406 } 407 } 408 409 Output output = operation.getOutput(); 410 if(output != null) { 411 String outputName = output.getName(); 412 if(outputName != null) { 413 if(!outputNames.contains(outputName)) { 414 outputNames.add(outputName); 415 } else { 416 getValidateSupport().fireToDo 418 (Validator.ResultType.ERROR, output, 419 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE, outputName, portType.getName()), 420 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE)); 421 } 422 } 423 } 424 } 425 426 visitChildren(portType); 427 } 429 430 435 public void visit(NotificationOperation operation) { 436 if (operation.getFaults() != null && operation.getFaults().size() > 0) { 439 getValidateSupport().fireToDo 440 (Validator.ResultType.WARNING, operation, 441 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName()), 442 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName())); 443 } 444 445 446 visitChildren(operation); 447 } 449 450 public void visit(RequestResponseOperation operation) { 451 if ((operation.getInput() == null || operation.getOutput() == null) 454 && (operation.getFaults() != null && operation.getFaults().size() > 0)) { 455 getValidateSupport().fireToDo 456 (Validator.ResultType.WARNING, operation, 457 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName()), 458 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName())); 459 } 460 461 validateFaultNames(operation); 465 466 validateParameterOrder(operation); 467 468 visitChildren(operation); 469 } 471 472 473 474 479 public void visit(SolicitResponseOperation operation) { 480 if ((operation.getInput() == null || operation.getOutput() == null) 483 && (operation.getFaults() != null && operation.getFaults().size() > 0)) { 484 getValidateSupport().fireToDo 485 (Validator.ResultType.WARNING, operation, 486 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName()), 487 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName())); 488 } 489 490 validateFaultNames(operation); 494 495 validateParameterOrder(operation); 496 497 visitChildren(operation); 498 } 500 501 506 public void visit(OneWayOperation operation) { 507 if (operation.getFaults() != null && operation.getFaults().size() > 0) { 510 getValidateSupport().fireToDo 511 (Validator.ResultType.WARNING, operation, 512 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName()), 513 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_FAULT_NOT_ALLOWED_IN_OPERATION, operation.getName())); 514 } 515 516 visitChildren(operation); 517 } 519 520 521 522 527 public void visit(Input input) { 528 NamedComponentReference<Message> msgRef = input.getMessage(); 529 Message message = null; 530 if(msgRef != null) { 531 message = msgRef.get(); 532 533 } 534 535 String messageName = input.getAttribute(new StringAttribute(Input.MESSAGE_PROPERTY)); 536 537 if (messageName != null && message == null) { 538 Operation operation = (Operation) input.getParent(); 540 getValidateSupport().fireToDo 541 (Validator.ResultType.ERROR, input, 542 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT, 543 messageName, operation.getName()), 544 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT, 545 messageName, operation.getName())); 546 547 } 548 549 visitChildren(input); 550 } 552 553 558 public void visit(Output output) { 559 NamedComponentReference<Message> msgRef = output.getMessage(); 560 Message message = null; 561 if(msgRef != null) { 562 message = msgRef.get(); 563 564 } 565 566 String messageName = output.getAttribute(new StringAttribute(Output.MESSAGE_PROPERTY)); 567 568 if (messageName != null && message == null) { 569 Operation operation = (Operation) output.getParent(); 571 getValidateSupport().fireToDo 572 (Validator.ResultType.ERROR, output, 573 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT, 574 messageName, operation.getName()), 575 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT, 576 messageName, operation.getName())); 577 578 } 579 580 visitChildren(output); 581 } 583 584 589 public void visit(Fault fault) { 590 591 592 NamedComponentReference<Message> msgRef = fault.getMessage(); 593 Message message = null; 594 if(msgRef != null) { 595 message = msgRef.get(); 596 597 } 598 599 String messageName = fault.getAttribute(new StringAttribute(Fault.MESSAGE_PROPERTY)); 600 601 if (messageName != null && message == null) { 602 Operation operation = (Operation) fault.getParent(); 604 getValidateSupport().fireToDo 605 (Validator.ResultType.ERROR, fault, 606 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT, 607 messageName, fault.getName(), operation.getName()), 608 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT, 609 fault.getName(), operation.getName())); 610 611 } 612 613 visitChildren(fault); 614 } 616 617 622 public void visit(Service service) { 623 visitChildren(service); 624 } 625 626 631 public void visit(Port port) { 632 NamedComponentReference<Binding> bindingRef = port.getBinding(); 634 Binding binding = null; 635 if(bindingRef != null) { 636 binding = bindingRef.get(); 637 638 } 639 640 if(binding == null) { 641 getValidateSupport().fireToDo 642 (Validator.ResultType.ERROR, port, 643 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MISSING_BINDING_IN_SERVICE_PORT, 644 port.getName(), port.getAttribute(new StringAttribute(Port.BINDING_PROPERTY))), 645 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MISSING_BINDING_IN_SERVICE_PORT) 646 ); 647 } 648 649 visitChildren(port); 650 } 652 653 654 655 660 public void visit(Import wsdlImport) { 661 662 List <WSDLModel> importedDocuments = wsdlImport.getModel().findWSDLModel(wsdlImport.getNamespace()); 664 665 666 if(importedDocuments == null || importedDocuments.isEmpty()) { 667 Collection xsdImports = wsdlImport.getModel().findSchemas(wsdlImport.getNamespace()); 669 if (xsdImports == null || xsdImports.size() == 0) { 670 getValidateSupport().fireToDo 671 (Validator.ResultType.ERROR, wsdlImport, 672 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MISSING_IMPORTED_DOCUMENT, 673 wsdlImport.getNamespace(), 674 wsdlImport.getLocation()), 675 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MISSING_IMPORTED_DOCUMENT) 676 ); 677 } 678 } 679 visitChildren(wsdlImport); 680 681 for (WSDLModel imp : importedDocuments) { 682 mValidation.validate(imp, ValidationType.COMPLETE); 683 } 684 } 686 687 690 public void visit(Binding binding) { 691 NamedComponentReference<PortType> ptRef = binding.getType(); 692 PortType portType = null; 693 if(ptRef != null) { 694 695 portType = ptRef.get(); 696 } 697 698 String type = binding.getAttribute(new StringAttribute(Binding.TYPE_PROPERTY)); 700 701 if(type != null && portType == null) { 702 getValidateSupport().fireToDo 703 (Validator.ResultType.ERROR, binding, 704 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_MISSING_PORTTYPE_IN_BINDING, 705 binding.getName(), 706 type), 707 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_MISSING_PORTTYPE_IN_BINDING) 708 ); 709 } 710 711 visitChildren(binding); 712 } 714 715 718 public void visit(BindingOperation bindingOp) { 719 724 Binding binding = (Binding) bindingOp.getParent(); 728 NamedComponentReference<PortType> ptRef = binding.getType(); 729 PortType portType = null; 730 if(ptRef != null) { 731 portType = ptRef.get(); 732 } 733 734 String portTypeName = null; 735 if(portType != null) { 736 portTypeName = portType.getName(); 737 } 738 739 String bindingName = binding.getName(); 740 String operationName = bindingOp.getName(); 741 if(portType != null && operationName != null) { 742 Collection <Operation> operations = portType.getOperations(); 743 Reference<Operation> matchingOpRef = bindingOp.getOperation(); 744 Operation matchingOp = null; 745 if(matchingOpRef != null) { 746 matchingOp = matchingOpRef.get(); 747 } 748 749 750 if(matchingOp == null){ 752 getValidateSupport().fireToDo 753 (Validator.ResultType.ERROR, bindingOp, 754 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE, operationName, binding.getName(), portType.getName()), 755 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE, portType.getName())); 756 } else{ 757 BindingInput bindingInput = bindingOp.getBindingInput(); 759 boolean bindingOpHasInput = bindingInput != null; 760 Input portTypeInput = matchingOp.getInput(); 761 boolean portTypeOpHasInput = portTypeInput != null; 762 BindingOutput bindingOutput = bindingOp.getBindingOutput(); 763 boolean bindingOpHasOutput = bindingOutput != null; 764 Output portTypeOutput = matchingOp.getOutput(); 765 boolean portTypeOpHasOutput = portTypeOutput != null; 766 Collection <BindingFault> bindingFaults = bindingOp.getBindingFaults(); 767 Collection <Fault> matchingFaults = matchingOp.getFaults(); 768 769 if(bindingOpHasInput != portTypeOpHasInput){ 770 getValidateSupport().fireToDo 772 (Validator.ResultType.ERROR, bindingOp, 773 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE, operationName, bindingName, portTypeName), 774 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE, operationName)); 775 }else{ 776 if(bindingOpHasInput){ 777 if(!inputNamesMatch(bindingInput, portTypeInput, operationName)){ 778 getValidateSupport().fireToDo 779 (Validator.ResultType.WARNING, bindingInput, 780 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE, operationName, bindingName, portTypeName), 781 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_MATCH_INPUT_NAME_IN_PORT_TYPE, operationName)); 782 } 783 } 784 } 785 786 if(bindingOpHasOutput != portTypeOpHasOutput){ 787 getValidateSupport().fireToDo 789 (Validator.ResultType.ERROR, bindingOp, 790 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE, operationName, bindingName, portTypeName), 791 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE, operationName)); 792 }else{ 793 if(bindingOpHasOutput){ 794 if(!outputNamesMatch(bindingOutput, portTypeOutput, operationName)){ 795 getValidateSupport().fireToDo 796 (Validator.ResultType.WARNING, bindingOutput, 797 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE, operationName, bindingName, portTypeName), 798 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_NAME_IN_PORT_TYPE, operationName)); 799 } 800 } 801 } 802 if(!faultsMatch(bindingFaults, matchingFaults)){ 803 getValidateSupport().fireToDo 805 (Validator.ResultType.ERROR, bindingOp, 806 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE, operationName, bindingName, portTypeName), 807 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE, operationName)); 808 } 809 } 810 } else { 811 } 814 visitChildren(bindingOp); 816 } 818 819 private boolean inputNamesMatch(BindingInput bindingInput, Input portTypeInput, String operationName){ 820 String bindingInputName = bindingInput.getAttribute(WSDLAttribute.NAME); 821 String portTypeInputName = portTypeInput.getAttribute(WSDLAttribute.NAME); 822 if(bindingInputName != null){ 823 return bindingInputName.equals(portTypeInputName); 824 } else { 825 return portTypeInputName == null; 826 } 827 828 } 829 830 private boolean outputNamesMatch(BindingOutput bindingOutput, Output portTypeOutput, String operationName){ 831 String bindingOutputName = bindingOutput.getName(); 832 String portTypeOutputName = portTypeOutput.getAttribute(WSDLAttribute.NAME); 833 834 if(bindingOutputName != null){ 835 return bindingOutputName.equals(portTypeOutput.getName()); 836 } else { 837 return portTypeOutputName == null; 838 } 839 840 } 841 842 private boolean faultsMatch(Collection <BindingFault> bindingFaults, Collection <Fault> portTypeFaults){ 843 if(bindingFaults.size() != portTypeFaults.size()) return false; 844 if(portTypeFaults.size() == 0) return true; 845 846 Set <String > portTypeFaultNames = new HashSet <String >(); 847 for(Fault portTypeFault : portTypeFaults){ 848 portTypeFaultNames.add(portTypeFault.getName()); 849 } 850 for(BindingFault bindingFault : bindingFaults){ 851 if(!portTypeFaultNames.contains(bindingFault.getName())) 852 return false; 853 } 854 return true; 855 } 856 857 860 public void visit(BindingInput bindingIn) { 861 visitChildren(bindingIn); 862 } 863 864 867 public void visit(BindingOutput bindingOut) { 868 visitChildren(bindingOut); 869 } 870 871 874 public void visit(BindingFault bindingFault) { 875 visitChildren(bindingFault); 876 } 877 878 881 public void visit(Documentation doc) { 882 } 883 884 887 public void visit(Types types) { 888 visitChildren(types); 889 } 890 891 894 public void visit(ExtensibilityElement ext) { 895 if (ext instanceof WSDLSchema) { 896 901 SchemaModel model = ((WSDLSchema)ext).getSchemaModel(); 902 if (model != null && model.getSchema() != null) { 903 String targetNamespace = model.getSchema().getTargetNamespace(); 904 if (targetNamespace == null || targetNamespace.length() == 0) { 905 Schema schema = model.getSchema(); 906 Collection <SchemaComponent> allTopLevelElements = schema.getChildren(); 907 for (SchemaComponent sc : allTopLevelElements) { 908 if (!(sc instanceof Annotation || 909 sc instanceof org.netbeans.modules.xml.schema.model.Import)) { 910 getValidateSupport().fireToDo 911 (Validator.ResultType.ERROR, ext, 912 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST), 913 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST)); 914 break; 915 } 916 } 917 } 918 919 SchemaSemanticsVisitor v = new SchemaSemanticsVisitor(ext.getModel(), mValidator, mValidation, mValidatedModels); 920 model.getSchema().accept(v); 921 922 List <ResultItem> r = v.getResultItems(); 923 if(r != null) { 924 mResultItems.addAll(r); 925 } 926 } 927 928 } 929 } 930 931 private void visitChildren(WSDLComponent w) { 932 Collection coll = w.getChildren(); 933 if (coll != null) { 934 Iterator iter = coll.iterator(); 935 while (iter.hasNext()) { 936 WSDLComponent component = (WSDLComponent) iter.next(); 937 component.accept(this); 938 } 939 } 940 } 941 942 private void validateFaultNames(Operation operation) { 943 ArrayList <String > faultNames = new ArrayList <String >(); 947 948 Collection faults = operation.getFaults(); 949 Iterator it = faults.iterator(); 950 while(it.hasNext()) { 951 Fault fault = (Fault) it.next(); 952 String faultName = fault.getName(); 953 if(faultName != null) { 954 if(!faultNames.contains(faultName)) { 955 faultNames.add(faultName); 956 } else { 957 getValidateSupport().fireToDo 959 (Validator.ResultType.ERROR, operation, 960 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_DUPLICATE_OPRATION_FAULT_NAME, faultName, operation.getName()), 961 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_DUPLICATE_OPRATION_FAULT_NAME)); 962 } 963 } 964 } 965 } 966 967 968 private void validateParameterOrder(Operation operation) { 969 List <String > parts = operation.getParameterOrder(); 970 if(parts!= null) { 971 972 Iterator <String > it = parts.iterator(); 973 while(it.hasNext()) { 974 String partName = it.next(); 975 validateParameterOrderPart(operation, partName); 976 } 977 } 978 979 validateParameterOrderInOutput(operation); 980 } 981 982 private void validateParameterOrderPart(Operation operation, String partName) { 983 Input input = operation.getInput(); 984 Output output = operation.getOutput(); 985 if(input != null && output != null) { 986 boolean foundPart = false; 987 988 NamedComponentReference<Message> inputMessage = input.getMessage(); 990 NamedComponentReference<Message> outputMessage = output.getMessage(); 991 992 if(inputMessage != null && inputMessage.get() != null) { 993 Message inMessage = inputMessage.get(); 994 Collection <Part> parts = inMessage.getParts(); 995 Part part = findMatchingPart(parts, partName); 996 if(part != null) { 997 foundPart = true; 998 } 999 } 1000 1001 if(!foundPart && outputMessage != null && outputMessage.get() != null) { 1002 Message outMessage = outputMessage.get(); 1003 Collection <Part> parts = outMessage.getParts(); 1004 Part part = findMatchingPart(parts, partName); 1005 if(part != null) { 1006 foundPart = true; 1007 } 1008 } 1009 1010 if(!foundPart) { 1011 getValidateSupport().fireToDo(Validator.ResultType.ERROR, operation, 1012 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_PARMETER_ORDER_CHECK_PART_EXISTENCE, partName, operation.getName()), 1013 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_PARMETER_ORDER_CHECK_PART_EXISTENCE)); 1014 } 1015 } 1016 } 1017 1018 private void validateParameterOrderInOutput(Operation operation) { 1019 Output output = operation.getOutput(); 1020 if(output != null) { 1021 NamedComponentReference<Message> outputMessage = output.getMessage(); 1022 1023 if(outputMessage != null && outputMessage.get() != null) { 1024 Message outMessage = outputMessage.get(); 1025 Collection <Part> outputParts = outMessage.getParts(); 1026 List <String > parts = operation.getParameterOrder(); 1027 if(outputParts != null && parts!= null) { 1028 int matchedOutputPartsCount = 0; 1029 Iterator <Part> it = outputParts.iterator(); 1030 while(it.hasNext()) { 1031 Part p = it.next(); 1032 1033 if(p.getName() != null) { 1034 boolean result = parts.contains(p.getName()); 1035 if(result) { 1036 matchedOutputPartsCount++; 1037 } 1038 } 1039 } 1040 1043 if(matchedOutputPartsCount < (outputParts.size() -1)) { 1044 getValidateSupport().fireToDo(Validator.ResultType.ERROR, operation, 1045 NbBundle.getMessage(WSDLSemanticsVisitor.class, VAL_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING, operation.getName()), 1046 NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_PARMETER_ORDER_CHECK_AT_MOST_ONE_OUTPUT_MESSAGE_PART_MISSING)); 1047 1048 } 1049 } 1050 } 1051 1052 } 1053 } 1054 1055 private Part findMatchingPart(Collection <Part> parts, String partName) { 1056 Part part = null; 1057 if(partName != null && parts != null) { 1058 Iterator <Part> it = parts.iterator(); 1059 while(it.hasNext()) { 1060 Part p = it.next(); 1061 if(partName.equals(p.getName())) { 1062 part = p; 1063 break; 1064 } 1065 } 1066 } 1067 1068 return part; 1069 } 1070} 1071 | Popular Tags |