KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > validator > visitor > WSDLSemanticsVisitor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.validator.visitor;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Properties JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.Vector JavaDoc;
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 /**
76  * Visits the model nodes and validates them.
77  *
78  * @author sbyn
79  * TODO: add validation for extensibility elements like bpws: property, propertyAlias
80  * in a generic way. someone can register a validator for these and validate them
81  * @version $Revision: 1.12 $
82  */

83 public class WSDLSemanticsVisitor implements WSDLVisitor {
84     
85     private ValidateSupport mValidateSupport = null;
86     /** Validate configuration singleton. */
87     private static ValidateConfiguration mValConfig;
88     
89     /** Fault can not be thrown by one-way or notification type operation */
90     public static final String JavaDoc VAL_FAULT_NOT_ALLOWED_IN_OPERATION = "VAL_FAULT_NOT_ALLOWED_IN_OPERATION"; // Not I18N
91

92     /** Fix 'Fault can not be thrown by one-way or notification type operation'
93      * by removing faults */

94     public static final String JavaDoc FIX_FAULT_NOT_ALLOWED_IN_OPERATION = "FIX_FAULT_NOT_ALLOWED_IN_OPERATION"; // Not I18N
95

96     /** Message not found for operation input */
97     public static final String JavaDoc VAL_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT =
98             "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT";
99     
100     /** Message not found for operation output */
101     public static final String JavaDoc VAL_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT =
102             "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT";
103     
104     /** Message not found for operation fault */
105     public static final String JavaDoc VAL_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT =
106             "VAL_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT";
107     
108     /** Fix for message not found for operation input */
109     public static final String JavaDoc FIX_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT =
110             "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_INPUT";
111     
112     /** Fix for Message not found for operation output */
113     public static final String JavaDoc FIX_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT =
114             "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_OUTPUT";
115     
116     /** Fix for Message not found for operation fault */
117     public static final String JavaDoc FIX_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT =
118             "FIX_MESSAGE_NOT_FOUND_IN_OPERATION_FAULT";
119     
120     /** Schema in part not found */
121     public static final String JavaDoc VAL_SCHEMA_DEFINED_NOT_FOUND = "VAL_SCHEMA_DEFINED_NOT_FOUND";
122     
123     /** Fix for Schema in part not found */
124     public static final String JavaDoc FIX_SCHEMA_DEFINED_NOT_FOUND = "FIX_SCHEMA_DEFINED_NOT_FOUND";
125     
126     /** Schema is not defined in part */
127     public static final String JavaDoc VAL_NO_SCHEMA_DEFINED = "VAL_NO_SCHEMA_DEFINED";
128     
129     /** Fix for Schema is not defined in part */
130     public static final String JavaDoc FIX_NO_SCHEMA_DEFINED = "FIX_NO_SCHEMA_DEFINED";
131     
132     /** partnerLinkType portType does not exist in wsdl file */
133     public static final String JavaDoc VAL_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL = "VAL_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL";
134     
135     /** Fix for partnerLinkType portType does not exist in wsdl file */
136     public static final String JavaDoc FIX_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL = "FIX_NO_PARTNERLINKTYPE_PORTTYPE_DEFINED_IN_WSDL";
137     
138     /**Message has zero parts so it is valid as per wsdl schema but we need a warning*/
139     public static final String JavaDoc VAL_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED = "VAL_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED";
140     
141     /**Message has zero parts so it is valid as per wsdl schema but we need a warning*/
142     public static final String JavaDoc FIX_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED = "FIX_WARNING_WSDL_MESSAGE_DOES_NOT_HAVE_ANY_PARTS_DEFINED";
143     
144     /** part does not have element or type attribute */
145     public static final String JavaDoc VAL_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "VAL_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART";
146     
147     /** part does not have element or type attribute */
148     public static final String JavaDoc FIX_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "FIX_NO_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART";
149     
150     /** part has both element and type attribute */
151     public static final String JavaDoc VAL_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "VAL_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART";
152     
153     /** part has both element and type attribute */
154      public static final String JavaDoc FIX_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART = "FIX_BOTH_ELEMENT_OR_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART";
155     
156     
157     /**part has element attribute but the referenced element object can not be located*/
158     public static final String JavaDoc VAL_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "VAL_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID";
159     
160     /**part has element attribute but the referenced element object can not be located*/
161     public static final String JavaDoc FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID";
162     
163     /**part has type attribute but the referenced type object can not be located*/
164     public static final String JavaDoc VAL_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "VAL_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID";
165     
166     /**part has element attribute but the referenced type object can not be located*/
167     public static final String JavaDoc FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID = "FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID";
168     
169     /**Binding has wrong or missing PortType */
170     public static final String JavaDoc VAL_MISSING_PORTTYPE_IN_BINDING = "VAL_MISSING_PORTTYPE_IN_BINDING";
171     public static final String JavaDoc FIX_MISSING_PORTTYPE_IN_BINDING = "FIX_MISSING_PORTTYPE_IN_BINDING";
172     
173     /**Service Port has wrong or missing Binding */
174     public static final String JavaDoc VAL_MISSING_BINDING_IN_SERVICE_PORT = "VAL_MISSING_BINDING_IN_SERVICE_PORT";
175     public static final String JavaDoc FIX_MISSING_BINDING_IN_SERVICE_PORT = "FIX_MISSING_BINDING_IN_SERVICE_PORT";
176     
177     /**Import does not have imported document object */
178     public static final String JavaDoc VAL_MISSING_IMPORTED_DOCUMENT = "VAL_MISSING_IMPORTED_DOCUMENT";
179     public static final String JavaDoc FIX_MISSING_IMPORTED_DOCUMENT = "FIX_MISSING_IMPORTED_DOCUMENT";
180     
181     /** PortType operation input name should be unique across all operation inputs in a port type*/
182     public static final String JavaDoc VAL_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE = "VAL_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE";
183     public static final String JavaDoc FIX_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE = "FIX_DUPLICATE_OPRATION_INPUT_NAME_IN_PORTTYPE";
184     
185     /** PortType operation output name should be unique across all operation outputs in a port type*/
186     public static final String JavaDoc VAL_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE = "VAL_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE";
187     public static final String JavaDoc FIX_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE = "FIX_DUPLICATE_OPRATION_OUTPUT_NAME_IN_PORTTYPE";
188     
189     
190     /** operation falut name should be unique across all operation faults*/
191     public static final String JavaDoc VAL_DUPLICATE_OPRATION_FAULT_NAME = "VAL_DUPLICATE_OPRATION_FAULT_NAME";
192     public static final String JavaDoc FIX_DUPLICATE_OPRATION_FAULT_NAME = "FIX_DUPLICATE_OPRATION_FAULT_NAME";
193     
194     /** binding operation name does not match name of portType operations*/
195     public static final String JavaDoc VAL_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE";
196     public static final String JavaDoc FIX_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_EXIST_IN_PORT_TYPE";
197     
198     private static final String JavaDoc VAL_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE = "VAL_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE";
199     
200     private static final String JavaDoc FIX_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE = "FIX_ERROR_WSDL_DEFINITIONS_NO_TARGETNAMESPACE";
201     
202     private static final String JavaDoc VAL_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "VAL_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST";
203     
204     private static final String JavaDoc FIX_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "FIX_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST";
205     
206     private static final String JavaDoc VAL_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "VAL_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST";
207     
208     private static final String JavaDoc FIX_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST = "FIX_IMPORT_SCHEMA_TARGETNAMESPACE_DOES_NOT_EXIST";
209     
210     public static final String JavaDoc VAL_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE";
211     public static final String JavaDoc FIX_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_INPUT_IN_PORT_TYPE";
212     
213     public static final String JavaDoc VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE";
214     public static final String JavaDoc FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_OUTPUT_IN_PORT_TYPE";
215     
216      public static final String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc VAL_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE = "VAL_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE";
223     public static final String JavaDoc FIX_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE = "FIX_OPERATION_DOES_NOT_MATCH_FAULTS_IN_PORT_TYPE";
224     
225     public static final String JavaDoc VAL_MULTIPLE_TYPES_IN_DEFINITION = "VAL_MULTIPLE_TYPES_IN_DEFINITION";
226     public static final String JavaDoc FIX_MULTIPLE_TYPES_IN_DEFINITION = "FIX_MULTIPLE_TYPES_IN_DEFINITION";
227    
228     public static final String JavaDoc VAL_PARMETER_ORDER_CHECK_PART_EXISTENCE = "VAL_PARMETER_ORDER_CHECK_PART_EXISTENCE";
229     public static final String JavaDoc FIX_PARMETER_ORDER_CHECK_PART_EXISTENCE = "FIX_PARMETER_ORDER_CHECK_PART_EXISTENCE";
230    
231     public static final String JavaDoc 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 JavaDoc 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 JavaDoc<ResultItem> mResultItems;
235     private Validation mValidation;
236     private List JavaDoc<Model> mValidatedModels;
237     private Validator mValidator;
238     
239     /** Creates a new instance of WSDLSchemaVisitor */
240     public WSDLSemanticsVisitor(Validator validator, Validation validation, List JavaDoc<Model> validatedModels) {
241         
242         Properties JavaDoc defaults = new Properties JavaDoc();
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 JavaDoc<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 JavaDoc<ResultItem> getResultItems() {
264         return mResultItems;
265     }
266     
267     /** Gets the validate visitor support.
268      * @return Visitor support.
269      */

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     /**
290      * Visits a WSDL definitions.
291      * @param w a WSDL definitions element
292      * @return <code>true</code> if auto-traversal is to continue.
293      */

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 JavaDoc<Types> result = w.getChildren(Types.class);
302         if(result != null && result.size() > 1) {
303             //multiple types are not valid
304
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     /** Visits a wsdl:message element.
314      * @param w a wsdl:message element
315      * @return <tt>true</tt> if traversal is to continue.
316      */

317     public void visit(Message w) {
318         //if Message does not have any part defined, show user a warning.
319
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         //return true;d
328
}
329     
330     /** Visits a part element.
331      * @param p a part element
332      * @return <tt>true</tt> if traversal is to continue.
333      */

334     public void visit(final Part p) {
335         //if both element and type attribute are missing then part is invalid
336
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 both element and type attribute are specified then part is invalid
344
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 element attribute is specified and xsd element object can not be resolved
352
//then its an error.
353
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))), //NOTI18N
357
NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_ELEMENT_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID));
358         }
359         
360         //if type attribute is specified and xsd type object can not be resolved
361
//then its an error.
362
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))), //NOTI18N
366
NbBundle.getMessage(WSDLSemanticsVisitor.class, FIX_TYPE_ATTRIBUTE_DEFINED_IN_MESSAGE_PART_IS_NOT_VALID));
367         }
368         
369         visitChildren(p);
370         // Validate that the part refers to a message existing
371
//return true;
372
}
373     
374     /**
375      * Visits a portType element.
376      * @param portType a portType element
377      * @return <tt>true</tt> if auto-traversal is to continue.
378      */

379     public void visit(PortType portType) {
380         //wsdl 1.1 spec validation:
381
//2.4.5 Names of Elements within an Operation:
382
//The name attribute of the input and output elements provides a unique name
383
//among all input and output elements within the enclosing port type
384

385         //(a)validate if all operation input name are unique
386
//(b)validate if all operation output name are unique
387
ArrayList JavaDoc<String JavaDoc> inputNames = new ArrayList JavaDoc<String JavaDoc>();
388         ArrayList JavaDoc<String JavaDoc> outputNames = new ArrayList JavaDoc<String JavaDoc>();
389         Collection JavaDoc operations = portType.getOperations();
390         Iterator JavaDoc it = operations.iterator();
391         while(it.hasNext()) {
392             Operation operation = (Operation) it.next();
393             Input input = operation.getInput();
394             if(input != null) {
395                 String JavaDoc inputName = input.getName();
396                 if(inputName != null) {
397                     if(!inputNames.contains(inputName)) {
398                         inputNames.add(inputName);
399                     } else {
400                         //found duplicate input name in this portType operations
401
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 JavaDoc outputName = output.getName();
412                 if(outputName != null) {
413                     if(!outputNames.contains(outputName)) {
414                         outputNames.add(outputName);
415                     } else {
416                         //found duplicate output name in this portType operations
417
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         //return true;
428
}
429     
430     /**
431      * Visits a portType operation element.
432      * @param operation a portType operation element
433      * @return <tt>true</tt> if auto-traversal is to continue.
434      */

435     public void visit(NotificationOperation operation) {
436         // if the opertion is an one-way operation or a notification operation,
437
// then there should be no faults
438
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         //return true;
448
}
449     
450     public void visit(RequestResponseOperation operation) {
451         // if the opertion is an one-way operation or a notification operation,
452
// then there should be no faults
453
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         //wsdl spec:
462
//2.4.5 Names of Elements within an Operation:
463
//The name of the fault element is unique within the set of faults defined for the operation
464
validateFaultNames(operation);
465         
466         validateParameterOrder(operation);
467         
468         visitChildren(operation);
469         // return true;
470
}
471     
472     
473     
474     /**
475      * Visits a portType operation element.
476      * @param operation a portType operation element
477      * @return <tt>true</tt> if auto-traversal is to continue.
478      */

479     public void visit(SolicitResponseOperation operation) {
480         // if the opertion is an one-way operation or a notification operation,
481
// then there should be no faults
482
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         //wsdl spec:
491
//2.4.5 Names of Elements within an Operation:
492
//The name of the fault element is unique within the set of faults defined for the operation
493
validateFaultNames(operation);
494         
495         validateParameterOrder(operation);
496         
497         visitChildren(operation);
498         // return true;
499
}
500     
501     /**
502      * Visits a portType operation element.
503      * @param operation a portType operation element
504      * @return <tt>true</tt> if auto-traversal is to continue.
505      */

506     public void visit(OneWayOperation operation) {
507         // if the opertion is an one-way operation or a notification operation,
508
// then there should be no faults
509
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         //return true;
518
}
519     
520     
521     
522     /**
523      * Visits an operation input element.
524      * @param input an operation input element
525      * @return <tt>true</tt> if auto-traversal is to continue.
526      */

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 JavaDoc messageName = input.getAttribute(new StringAttribute(Input.MESSAGE_PROPERTY));
536         
537         if (messageName != null && message == null) {
538             // throw validation error
539
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         // return true;
551
}
552     
553     /**
554      * Visits an operation output element.
555      * @param output an operation output element
556      * @return <tt>true</tt> if auto-traversal is to continue.
557      */

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 JavaDoc messageName = output.getAttribute(new StringAttribute(Output.MESSAGE_PROPERTY));
567         
568         if (messageName != null && message == null) {
569             // throw validation error
570
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         // return true;
582
}
583     
584     /**
585      * Visits an operation fault element.
586      * @param fault an operation fault element
587      * @return <tt>true</tt> if auto-traversal is to continue.
588      */

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 JavaDoc messageName = fault.getAttribute(new StringAttribute(Fault.MESSAGE_PROPERTY));
600         
601         if (messageName != null && message == null) {
602             // throw validation error
603
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         //return true;
615
}
616     
617     /**
618      * Visits a service element.
619      * @param service a service element
620      * @return <tt>true</tt> if auto-traversal is to continue.
621      */

622     public void visit(Service service) {
623         visitChildren(service);
624     }
625     
626     /**
627      * Visits a service port element.
628      * @param port a service port element
629      * @return <tt>true</tt> if auto-traversal is to continue.
630      */

631     public void visit(Port port) {
632         //verify if binding exists
633
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         // return true;
651
}
652     
653     
654     
655     /**
656      * Visits an import element.
657      * @param wsdlImport an import element
658      * @return <tt>true</tt> if auto-traversal is to continue.
659      */

660     public void visit(Import wsdlImport) {
661         
662         //verify if imported document is available
663
List JavaDoc<WSDLModel> importedDocuments = wsdlImport.getModel().findWSDLModel(wsdlImport.getNamespace());
664         
665         
666         if(importedDocuments == null || importedDocuments.isEmpty()) {
667             // it can be a xsd import
668
Collection JavaDoc 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         // return true;
685
}
686     
687     /**
688      * @see WSDLVisitor#visit(Binding)
689      */

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         //now make sure portType is available
699
String JavaDoc 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         //return true;
713
}
714     
715     /**
716      * @see WSDLVisitor#visit(BindingOperation)
717      */

718     public void visit(BindingOperation bindingOp) {
719         //wsdl spec:
720
//section 2.5 Bindings:
721
//An operation element within a binding specifies binding information for the
722
//operation with the same name within the binding's portType
723

724         //validate if binding operation name is same as porttype operation name
725
//XMLNode parent = bindingOp.getParent();
726
//if(parent instanceof Binding) {
727
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 JavaDoc portTypeName = null;
735         if(portType != null) {
736             portTypeName = portType.getName();
737         }
738         
739         String JavaDoc bindingName = binding.getName();
740         String JavaDoc operationName = bindingOp.getName();
741         if(portType != null && operationName != null) {
742             Collection JavaDoc<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 no matching operation is found then it is an error
751
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                 //check if the signatures match
758
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 JavaDoc<BindingFault> bindingFaults = bindingOp.getBindingFaults();
767                 Collection JavaDoc<Fault> matchingFaults = matchingOp.getFaults();
768                 
769                 if(bindingOpHasInput != portTypeOpHasInput){
770                     //Input in portType operation does not match input in binding operation
771
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                     //Output in portType operation does not match output in binding operation
788
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                     //Faults do not match
804
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             //binding operation's parent should be binding
812
//taken care by schema validation
813
}
814         //}
815
visitChildren(bindingOp);
816         // return true;
817
}
818     
819     private boolean inputNamesMatch(BindingInput bindingInput, Input portTypeInput, String JavaDoc operationName){
820         String JavaDoc bindingInputName = bindingInput.getAttribute(WSDLAttribute.NAME);
821         String JavaDoc 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 JavaDoc operationName){
831         String JavaDoc bindingOutputName = bindingOutput.getName();
832         String JavaDoc 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 JavaDoc<BindingFault> bindingFaults, Collection JavaDoc<Fault> portTypeFaults){
843         if(bindingFaults.size() != portTypeFaults.size()) return false;
844         if(portTypeFaults.size() == 0) return true;
845         
846         Set JavaDoc<String JavaDoc> portTypeFaultNames = new HashSet JavaDoc<String JavaDoc>();
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     /**
858      * @see WSDLVisitor#visit(BindingInput)
859      */

860     public void visit(BindingInput bindingIn) {
861         visitChildren(bindingIn);
862     }
863     
864     /**
865      * @see WSDLVisitor#visit(BindingOutput)
866      */

867     public void visit(BindingOutput bindingOut) {
868         visitChildren(bindingOut);
869     }
870     
871     /**
872      * @see WSDLVisitor#visit(BindingFault)
873      */

874     public void visit(BindingFault bindingFault) {
875         visitChildren(bindingFault);
876     }
877     
878     /**
879      * @see DocumentationVisitor#visit(Documentation)
880      */

881     public void visit(Documentation doc) {
882     }
883     
884     /**
885      * @see WSDLVisitor#visit(Types)
886      */

887     public void visit(Types types) {
888         visitChildren(types);
889     }
890     
891     /**
892      * @see WSDLVisitor#visit(ExtensibilityElement)
893      */

894     public void visit(ExtensibilityElement ext) {
895         if (ext instanceof WSDLSchema) {
896           /* R2105 All xsd:schema elements contained in a wsdl:types element of a
897            * DESCRIPTION MUST have a targetNamespace attribute with a valid and non-null
898            * value, UNLESS the xsd:schema element has xsd:import and/or xsd:annotation as
899            * its only child element(s).
900            */

901             SchemaModel model = ((WSDLSchema)ext).getSchemaModel();
902             if (model != null && model.getSchema() != null) {
903                 String JavaDoc targetNamespace = model.getSchema().getTargetNamespace();
904                 if (targetNamespace == null || targetNamespace.length() == 0) {
905                     Schema schema = model.getSchema();
906                     Collection JavaDoc<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 JavaDoc<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 JavaDoc coll = w.getChildren();
933         if (coll != null) {
934             Iterator JavaDoc 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         //wsdl spec:
944
//2.4.5 Names of Elements within an Operation:
945
//The name of the fault element is unique within the set of faults defined for the operation
946
ArrayList JavaDoc<String JavaDoc> faultNames = new ArrayList JavaDoc<String JavaDoc>();
947         
948         Collection JavaDoc faults = operation.getFaults();
949         Iterator JavaDoc it = faults.iterator();
950         while(it.hasNext()) {
951             Fault fault = (Fault) it.next();
952             String JavaDoc faultName = fault.getName();
953             if(faultName != null) {
954                 if(!faultNames.contains(faultName)) {
955                     faultNames.add(faultName);
956                 } else {
957                     //found duplicate output name in this portType operations
958
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 JavaDoc<String JavaDoc> parts = operation.getParameterOrder();
970         if(parts!= null) {
971             
972             Iterator JavaDoc<String JavaDoc> it = parts.iterator();
973             while(it.hasNext()) {
974                 String JavaDoc partName = it.next();
975                 validateParameterOrderPart(operation, partName);
976             }
977         }
978         
979         validateParameterOrderInOutput(operation);
980     }
981     
982     private void validateParameterOrderPart(Operation operation, String JavaDoc partName) {
983         Input input = operation.getInput();
984         Output output = operation.getOutput();
985         if(input != null && output != null) {
986             boolean foundPart = false;
987             
988             //check either input or output has this part
989
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 JavaDoc<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 JavaDoc<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 JavaDoc<Part> outputParts = outMessage.getParts();
1026                List JavaDoc<String JavaDoc> parts = operation.getParameterOrder();
1027                if(outputParts != null && parts!= null) {
1028                    int matchedOutputPartsCount = 0;
1029                    Iterator JavaDoc<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                    // basic profile R2305 A wsdl:operation element child of a wsdl:portType element in a DESCRIPTION
1041
//MUST be constructed so that the parameterOrder attribute, if present, omits at most 1 wsdl:part from the output message.
1042

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 JavaDoc<Part> parts, String JavaDoc partName) {
1056        Part part = null;
1057        if(partName != null && parts != null) {
1058            Iterator JavaDoc<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