KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.wsdl.validator.visitor;
20
21 import java.util.Collection JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23 import javax.xml.namespace.QName JavaDoc;
24 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
25 import org.netbeans.modules.xml.xam.Component;
26 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
27 import org.netbeans.modules.xml.xam.spi.Validator;
28 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
29 import org.openide.util.NbBundle;
30
31
32 /**
33  * Supports validation of BPEL/WSDL documents.
34  *
35  * @author edwong
36  * @version $Revision: 1.4 $
37  */

38 public class ValidateSupport {
39
40     
41     /** Validate Configuration */
42     private ValidateConfiguration mValConfig;
43     
44     /** Missing required attribute */
45     public static final String JavaDoc VAL_MISSING_ATTRIB = "VAL_MISSING_ATTRIB"; // Not I18N
46

47     /** Please define required attribute */
48     public static final String JavaDoc FIX_MISSING_ATTRIB = "FIX_MISSING_ATTRIB"; // Not I18N
49

50     /** Not NCName attribute */
51     public static final String JavaDoc VAL_NOT_NCNAME_ATTRIB = "VAL_NOT_NCNAME_ATTRIB"; // Not I18N
52

53     /** Please make attribute comply to NCName */
54     public static final String JavaDoc FIX_NOT_NCNAME_ATTRIB = "FIX_NOT_NCNAME_ATTRIB"; // Not I18N
55

56     /** Not QName attribute */
57     public static final String JavaDoc VAL_NOT_QNAME_ATTRIB = "VAL_NOT_QNAME_ATTRIB"; // Not I18N
58

59     /** Please make attribute comply to QName */
60     public static final String JavaDoc FIX_NOT_QNAME_ATTRIB = "FIX_NOT_QNAME_ATTRIB"; // Not I18N
61

62     /** Prefix in QName is null */
63     public static final String JavaDoc VAL_PREFIX_NULL_QNAME_ATTRIB =
64         "VAL_PREFIX_NULL_QNAME_ATTRIB"; // Not I18N
65

66     /** Please define a prefix in the QName */
67     public static final String JavaDoc FIX_PREFIX_NULL_QNAME_ATTRIB =
68         "FIX_PREFIX_NULL_QNAME_ATTRIB"; // Not I18N
69

70     /** Prefix not defined */
71     public static final String JavaDoc VAL_PREFIX_NOT_DEFINED = "VAL_PREFIX_NOT_DEFINED"; // Not I18N
72

73     /** Please associate prefix */
74     public static final String JavaDoc FIX_PREFIX_NOT_DEFINED = "FIX_PREFIX_NOT_DEFINED"; // Not I18N
75

76     /** Not boolean attribute */
77     public static final String JavaDoc VAL_NOT_BOOLEAN_ATTRIB = "VAL_NOT_BOOLEAN_ATTRIB"; // Not I18N
78

79     /** Please make attribute boolean */
80     public static final String JavaDoc FIX_NOT_BOOLEAN_ATTRIB = "FIX_NOT_BOOLEAN_ATTRIB"; // Not I18N
81

82     /** Not enumerated attribute */
83     public static final String JavaDoc VAL_NOT_ENUM_ATTRIB = "VAL_NOT_ENUM_ATTRIB"; // Not I18N
84

85     /** Please choose one of enumerated values */
86     public static final String JavaDoc FIX_NOT_ENUM_ATTRIB = "FIX_NOT_ENUM_ATTRIB"; // Not I18N
87

88     /** Minimum sub-elements not met */
89     public static final String JavaDoc VAL_MIN_ELEM_NOT_MET = "VAL_MIN_ELEM_NOT_MET"; // Not I18N
90

91     /** Please add more sub-elements */
92     public static final String JavaDoc FIX_MIN_ELEM_NOT_MET = "FIX_MIN_ELEM_NOT_MET"; // Not I18N
93

94     /** Missing required sub-element */
95     public static final String JavaDoc VAL_MISSING_ELEM = "VAL_MISSING_ELEM"; // Not I18N
96

97     /** Please define sub-element */
98     public static final String JavaDoc FIX_MISSING_ELEM = "FIX_MISSING_ELEM"; // Not I18N
99

100     /** Matching WSDL document not found */
101     public static final String JavaDoc VAL_MATCHING_WSDL_NOT_FOUND = "VAL_MATCHING_WSDL_NOT_FOUND"; // Not I18N
102

103     /** Please import matching WSDL document */
104     public static final String JavaDoc FIX_MATCHING_WSDL_NOT_FOUND = "FIX_MATCHING_WSDL_NOT_FOUND"; // Not I18N
105

106     /**Trying to compensate an invalid scope **/
107     public static final String JavaDoc VAL_COMPENSATE_WITH_AN_INVALID_SCOPE =
108         "VAL_COMPENSATE_WITH_AN_INVALID_SCOPE"; //Not I18N
109

110     /** Fix compensate with an invalid scope **/
111     public static final String JavaDoc FIX_COMPENSATE_WITH_AN_INVALID_SCOPE =
112         "FIX_COMPENSATE_WITH_AN_INVALID_SCOPE"; //Not I18N
113

114     /** message type in container key*/
115     public static final String JavaDoc VAL_MESSAGETYPE_IN_CONTAINER = "VAL_MESSAGETYPE_IN_CONTAINER"; //Not I18N
116
/**message type in container fix*/
117     public static final String JavaDoc FIX_MESSAGETYPE_IN_CONTAINER = "FIX_MESSAGETYPE_IN_CONTAINER"; //Not I18N
118

119     /**catch type in container key*/
120     public static final String JavaDoc VAL_UNKNOWN_CONTAINER_IN_CATCH = "VAL_UNKNOWN_CONTAINER_IN_CATCH"; //Not I18N
121
/**catch type in container fix*/
122     public static final String JavaDoc FIX_UNKNOWN_CONTAINER_IN_CATCH = "FIX_UNKNOWN_CONTAINER_IN_CATCH"; //Not I18N
123
/**empty container key*/
124     public static final String JavaDoc VAL_EMPTY_CONTAINER_IN_CATCH = "VAL_EMPTY_CONTAINER_IN_CATCH"; //Not I18N
125
/**sequence*/
126     public static final String JavaDoc SEQUENCE_TITLE_NAME = "SEQUENCE_TITLE_NAME"; //Not I18N
127
/** missing connection */
128     public static final String JavaDoc VAL_MISSING_CONNECTIONS = "VAL_MISSING_CONNECTIONS"; //Not I18N
129
/**fix missing connection */
130     public static final String JavaDoc FIX_MISSING_CONNECTIONS = "FIX_MISSING_CONNECTIONS"; //Not I18N
131

132     /** correct correlation set */
133     public static final String JavaDoc VAL_SEMANTICALLY_CORRECT_CORRELATION_SET =
134         "VAL_SEMANTICALLY_CORRECT_CORRELATION_SET"; //Not I18N
135
/** correct correlation set fix */
136     public static final String JavaDoc FIX_SEMANTICALLY_CORRECT_CORRELATION_SET =
137         "FIX_SEMANTICALLY_CORRECT_CORRELATION_SET"; //Not I18N
138
/** empty fault name */
139     public static final String JavaDoc VAL_FAULT_NAME_CANNOT_BE_EMPTY = "VAL_FAULT_NAME_CANNOT_BE_EMPTY"; //Not I18N
140
/**empty fault name fix */
141     public static final String JavaDoc FIX_FAULT_NAME_CANNOT_BE_EMPTY = "FIX_FAULT_NAME_CANNOT_BE_EMPTY"; //Not I18N
142
/** unknown operation */
143     public static final String JavaDoc VAL_UNKNOWN_OPERATION = "VAL_UNKNOWN_OPERATION"; //Not I18N
144
/** unknown operation fix */
145     public static final String JavaDoc FIX_UNKNOWN_OPERATION = "FIX_UNKNOWN_OPERATION"; //Not I18N
146
/** unknown port type */
147     public static final String JavaDoc VAL_UNKNOWN_PORT_TYPE = "VAL_UNKNOWN_PORT_TYPE"; //Not I18N
148
/** unknown port type fix */
149     public static final String JavaDoc FIX_UNKNOWN_PORT_TYPE = "FIX_UNKNOWN_PORT_TYPE"; //Not I18N
150
/** minimym needed for assign */
151     public static final String JavaDoc VAL_ASSIGN_MUST_HAVE_MINIMUM = "VAL_ASSIGN_MUST_HAVE_MINIMUM"; //Not I18N
152
/** min fix for assing */
153     public static final String JavaDoc FIX_ASSIGN_MUST_HAVE_MINIMUM = "FIX_ASSIGN_MUST_HAVE_MINIMUM"; //Not I18N
154
/**
155      * min foreach
156      */

157     public static final String JavaDoc VAL_FOR_EACH_MUST_HAVE_MIN_ONE_COPY =
158         "VAL_FOR_EACH_MUST_HAVE_MIN_ONE_COPY"; //Not I18N
159
/** for each min fix */
160     public static final String JavaDoc FIX_FOR_EACH_MUST_HAVE_MIN_ONE_COPY =
161         "FIX_FOR_EACH_MUST_HAVE_MIN_ONE_COPY"; //Not I18N
162

163     /**
164      * empty scope
165      */

166     public static final String JavaDoc VAL_EMPTY_SCOPE = "VAL_EMPTY_SCOPE"; //Not I18N
167

168     /**
169      * empty scope fix
170      */

171     public static final String JavaDoc FIX_EMPTY_SCOPE = "FIX_EMPTY_SCOPE"; //Not I18N
172

173     /**
174      * empty while
175      */

176     public static final String JavaDoc VAL_EMPTY_WHILE = "VAL_EMPTY_WHILE"; //Not I18N
177

178     /**
179      * empty while fix
180      */

181     public static final String JavaDoc FIX_EMPTY_WHILE = "FIX_EMPTY_WHILE"; //Not I18N
182

183     /**
184      * empty compensation handler
185      */

186     public static final String JavaDoc VAL_EMPTY_COMPENSATION_HANDLER = "VAL_EMPTY_COMPENSATION_HANDLER"; //Not I18N
187

188     /**
189      * fix for an empty compensdation handler
190      */

191     public static final String JavaDoc FIX_EMPTY_COMPENSATION_HANDLER = "FIX_EMPTY_COMPENSATION_HANDLER"; //Not I18N
192

193      /**
194       * empty catch
195       */

196     public static final String JavaDoc VAL_EMPTY_CATCH = "VAL_EMPTY_CATCH"; //Not I18N
197

198     /**
199      * fix for an empty catch
200      */

201      public static final String JavaDoc FIX_EMPTY_CATCH = "FIX_EMPTY_CATCH"; //Not I18N
202

203      /**
204       * empty catch
205       */

206     public static final String JavaDoc VAL_EMPTY_CATCHALL = "VAL_EMPTY_CATCHALL"; //Not I18N
207

208     /**
209      * fix for an empty catch
210      */

211      public static final String JavaDoc FIX_EMPTY_CATCHALL = "FIX_EMPTY_CATCHALL"; //Not I18N
212

213      /** No eInsight license for eVison */
214      public static final String JavaDoc VAL_NO_EINSIGHT_LICENSE_W_EVISION = "VAL_NO_EINSIGHT_LICENSE_W_EVISION"; // Not I18N
215

216      /** Only create instance from Page Link for eVision */
217      public static final String JavaDoc FIX_NO_EINSIGHT_LICENSE_W_EVISION = "FIX_NO_EINSIGHT_LICENSE_W_EVISION"; // Not I18N
218

219         
220     private Collection JavaDoc<ResultItem> mResultItems;
221     private Validator mValidator;
222     
223     /** Creates a new instance of ValidateSupport.
224      * @param valConfig Validate configuration.
225      */

226     public ValidateSupport(ValidateConfiguration valConfig) {
227         super();
228         mValConfig = valConfig;
229     }
230     
231     /** Gets the validate configuration currently used.
232      * @return Validate configuration currently used.
233      */

234     public ValidateConfiguration getValidateConfiguration() {
235         return mValConfig;
236     }
237     
238     /** Sets the validate configuration currently used.
239      * @param valConfig Validate configuration to use.
240      */

241     public void setValidateConfiguration(ValidateConfiguration valConfig) {
242         mValConfig = valConfig;
243     }
244     
245     public void setResultItems(Collection JavaDoc<ResultItem> resultItems) {
246         mResultItems = resultItems;
247     }
248     public void setValidator(Validator validator) {
249         mValidator = validator;
250     }
251     
252     /** Tests if an attribute value is absent.
253      * @param value Value of attribute.
254      * @return <code>true</code> if value is absent.
255      */

256     public static boolean isAttributeAbsent(String JavaDoc value) {
257         return ((null == value) || (value.trim().length() == 0));
258     }
259     
260     /** Asserts that a required attribute is present.
261      * @param value Value of attribute.
262      * @param name Name of attribute.
263      * @param source Source element.
264      * @param category Category of failure.
265      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
266      */

267     public boolean assertRequiredAttrib(String JavaDoc value, String JavaDoc name, Component source) {
268         if (((source instanceof WSDLComponent)
269                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_REQUIRED))) {
270             return true;
271         }
272         
273         if (isAttributeAbsent(value)) {
274             return fireToDo(Validator.ResultType.ERROR, source, NbBundle.getMessage(ValidateSupport.class, VAL_MISSING_ATTRIB, name),
275                     NbBundle.getMessage(ValidateSupport.class, FIX_MISSING_ATTRIB, name));
276         }
277         
278         return true;
279     }
280
281     /** Asserts that a required attribute is present.
282      * @param value Value of attribute.
283      * @param name Name of attribute.
284      * @param source Source element.
285      * @param category Category of failure.
286      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
287      */

288     public boolean assertRequiredAttrib(QName JavaDoc value, String JavaDoc name, Component source, int category) {
289         if (((source instanceof WSDLComponent)
290                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_REQUIRED))) {
291             return true;
292         }
293         
294         if (value == null || isAttributeAbsent(value.toString())) {
295             return fireToDo(Validator.ResultType.ERROR, source, NbBundle.getMessage(ValidateSupport.class, VAL_MISSING_ATTRIB, name),
296                 NbBundle.getMessage(ValidateSupport.class, FIX_MISSING_ATTRIB, name));
297         }
298         
299         return true;
300     }
301
302     /** Asserts that an attribute is a NCName.
303      * @param value Value of attribute.
304      * @param name Name of attribute.
305      * @param source Source element.
306      * @param category Category of failure.
307      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
308      */

309     public boolean assertNCNameAttrib(String JavaDoc value, String JavaDoc name, Component source) {
310         if (((source instanceof WSDLComponent)
311                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_NCNAME))) {
312             return true;
313         }
314         
315         if (!isAttributeAbsent(value) && !ValidationUtils.isNCName(value)) {
316             return fireToDo(Validator.ResultType.ERROR, source,
317                 NbBundle.getMessage(ValidateSupport.class, VAL_NOT_NCNAME_ATTRIB, name),
318                 NbBundle.getMessage(ValidateSupport.class, FIX_NOT_NCNAME_ATTRIB, name)
319             );
320         }
321         return true;
322     }
323
324     /** Asserts that an attribute is a QName list.
325      * @param value Value of attribute.
326      * @param name Name of attribute.
327      * @param source Source element.
328      * @param category Category of failure.
329      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
330      */

331     public boolean assertQNameListAttrib(String JavaDoc value, String JavaDoc name, Component source, int category) {
332         if ((source instanceof WSDLComponent)
333                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_QNAME)) {
334             return true;
335         }
336         
337         if (!isAttributeAbsent(value)) {
338             StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(value, " ");
339             while (parser.hasMoreTokens()) {
340                 if (!assertQNameAttrib(parser.nextToken(), name, source, category)) {
341                     return false;
342                 }
343             }
344         }
345         return true;
346     }
347     
348     /** Asserts that a required attribute is a QName.
349      * @param value Value of attribute.
350      * @param name Name of attribute.
351      * @param source Source element.
352      * @param category Category of failure.
353      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
354      */

355     public boolean assertQNameAttrib(QName JavaDoc value, String JavaDoc name, Component source, int category) {
356         if(value != null) {
357             return assertQNameAttrib(value.toString(), name, source, category);
358         }
359         return true;
360     }
361     
362     /** Asserts that a required attribute is a QName.
363      * @param value Value of attribute.
364      * @param name Name of attribute.
365      * @param source Source element.
366      * @param category Category of failure.
367      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
368      */

369     public boolean assertQNameAttrib(String JavaDoc value, String JavaDoc name, Component source, int category) {
370         if (((source instanceof WSDLComponent)
371                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_QNAME))) {
372             return true;
373         }
374         
375         if (!isAttributeAbsent(value)) {
376             // First, check if QName compliant
377
if (!ValidationUtils.isQName(value)) {
378                 if (!fireToDo(Validator.ResultType.ERROR,
379                             source,
380                             
381                             NbBundle.getMessage(ValidateSupport.class, VAL_NOT_QNAME_ATTRIB, name),
382                             NbBundle.getMessage(ValidateSupport.class, FIX_NOT_QNAME_ATTRIB, name)
383                         )) {
384                     return false;
385                 }
386             }
387             String JavaDoc[] parts = value.split(":");//QName.getPrefix(value)
388
if (parts != null && parts.length > 1) {
389                 
390                 String JavaDoc prefix = parts[0];
391                 if (prefix != null) {
392                     // Second, check if prefix corresponds to a namespace
393
String JavaDoc ns = ((AbstractDocumentComponent) source).lookupNamespaceURI(prefix);
394                      
395                     if (null == ns) {
396                         if (!fireToDo(Validator.ResultType.ERROR,
397                                 source,
398                                 NbBundle.getMessage(ValidateSupport.class, VAL_PREFIX_NOT_DEFINED, prefix),
399                                 NbBundle.getMessage(ValidateSupport.class, FIX_PREFIX_NOT_DEFINED, prefix)
400                         )) {
401                             return false;
402                         }
403                     }
404                 }
405             }
406         }
407         return true;
408     }
409
410     /** Asserts that a required attribute is a QName. Apart from the QName test, also
411      * verify that the prefix is not null
412      * @param value Value of attribute.
413      * @param name Name of attribute.
414      * @param source Source element.
415      * @param category Category of failure.
416      * @param verifyNullPrefix If set verify that the prefix in the QName is not null
417      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
418      */

419     public boolean assertQNameAttrib(String JavaDoc value, String JavaDoc name, Component source,
420                                      int category, boolean verifyNullPrefix) {
421         boolean valid = assertQNameAttrib(value, name, source, category);
422         if (valid && verifyNullPrefix) {
423             /*String prefix = QName.getPrefix(value);*/
424             String JavaDoc[] parts = value.split(":");//QName.getPrefix(value)
425
if (parts != null && parts.length > 1) {
426                 
427                 String JavaDoc prefix = parts[0];
428                 // Second, check if prefix is not null
429
if (prefix == null || "".equals(prefix.trim())) {
430                     if (!fireToDo(Validator.ResultType.ERROR,
431                             source,
432                                     NbBundle.getMessage(ValidateSupport.class, VAL_PREFIX_NULL_QNAME_ATTRIB, name),
433                                     NbBundle.getMessage(ValidateSupport.class, FIX_PREFIX_NULL_QNAME_ATTRIB, name)
434                             )) {
435                         return false;
436                     }
437                 }
438             }
439         }
440
441         return true;
442     }
443     
444     /** Asserts that an attribute has a boolean value.
445      * @param value Value of attribute.
446      * @param name Name of attribute.
447      * @param source Source element.
448      * @param category Category of failure.
449      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
450      */

451     public boolean assertBooleanAttrib(String JavaDoc value, String JavaDoc name, Component source, int category) {
452         if ((source instanceof WSDLComponent)
453                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_BOOLEAN)) {
454             return true;
455         }
456         
457         if (!isAttributeAbsent(value) && !(value.equals("yes") || value.equals("no"))) {
458             return fireToDo(Validator.ResultType.ERROR,
459                 source,
460                 NbBundle.getMessage(ValidateSupport.class, VAL_NOT_BOOLEAN_ATTRIB, name),
461                 NbBundle.getMessage(ValidateSupport.class, FIX_NOT_BOOLEAN_ATTRIB, name)
462             );
463         }
464         return true;
465     }
466     
467     /** Asserts that a minimum number of sub-elements is required.
468      * @param num Number of existing sub-elements.
469      * @param min Minimum number of sub-elements required.
470      * @param name Name of sub-element.
471      * @param source Source element.
472      * @param category Category of failure.
473      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
474      */

475     public boolean assertMinimumElem(int num, int min, String JavaDoc name, Component source, int category) {
476         if (((source instanceof WSDLComponent)
477                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ELEM_MIN))) {
478             return true;
479         }
480         
481         if (num < min) {
482             return fireToDo(Validator.ResultType.ERROR,
483                 source,
484                /* category,
485                 Severity.ERROR,*/

486                 NbBundle.getMessage(ValidateSupport.class, VAL_MIN_ELEM_NOT_MET, Integer.valueOf(min), name, Integer.valueOf(num)),
487                 NbBundle.getMessage(ValidateSupport.class, FIX_MIN_ELEM_NOT_MET, Integer.valueOf(min - num), name)
488             );
489         }
490         return true;
491     }
492
493     /** Asserts that an attribute has an enumerated value.
494      * @param value Value of attribute.
495      * @param enums Enumerated values as an array.
496      * @param name Name of attribute.
497      * @param source Source element.
498      * @param category Category of failure.
499      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
500      */

501     public boolean assertEnumeratedAttrib(String JavaDoc value, String JavaDoc[] enums, String JavaDoc name, Component source,
502                                           int category) {
503        if (((source instanceof WSDLComponent)
504                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ATTRIB_ENUMERATED))) {
505            return true;
506        }
507        
508        if (!isAttributeAbsent(value) && (enums != null) && (enums.length > 0)) {
509            boolean found = false;
510            for (int i = 0; i < enums.length; i++) {
511                if (ValidationUtils.areEqualXMLValues(value, enums[i])) {
512                    found = true;
513                    break;
514                }
515            }
516            if (!found) {
517                StringBuffer JavaDoc enumsb = new StringBuffer JavaDoc();
518                for (int i = 0; i < enums.length; i++) {
519                    if (i > 0) {
520                        enumsb.append(", ");
521                    }
522                    enumsb.append(enums[i]);
523                }
524                return fireToDo(Validator.ResultType.ERROR,
525                     source, /*Category.BPEL_SYNTAX, Severity.ERROR,*/
526                     NbBundle.getMessage(ValidateSupport.class, VAL_NOT_ENUM_ATTRIB, name, enumsb.toString()),
527                     NbBundle.getMessage(ValidateSupport.class, FIX_NOT_ENUM_ATTRIB, enumsb.toString(), name)
528                );
529            }
530        }
531        return true;
532     }
533     
534     /** Asserts that a required sub-element is present.
535      * @param subElem Sub-element.
536      * @param name Name of sub-element.
537      * @param source Source element.
538      * @param category Category of failure.
539      * @return <code>true</code> if more validations can be made; <code>false</code> otherwise.
540      */

541     public boolean assertRequiredElement(Component subElem, String JavaDoc name, Component source, int category) {
542         if (((source instanceof WSDLComponent)
543                     && !mValConfig.getBooleanProperty(ValidateConfiguration.WSDL_SYNTAX_ELEM_REQUIRED))) {
544             return true;
545         }
546         
547         if (null == subElem) {
548             return fireToDo(Validator.ResultType.ERROR,
549                 source,
550                 NbBundle.getMessage(ValidateSupport.class, VAL_MISSING_ELEM, name),
551                 NbBundle.getMessage(ValidateSupport.class, FIX_MISSING_ELEM, name));
552         }
553         return true;
554     }
555     
556     /** Fires to-do events to listeners.
557      * @param toDoEvent To-do event to fire.
558      * @return <code>true</code> if more events can be accepted by the listener;
559      * <code>false</code> otherwise.
560      */

561     public boolean fireToDo(Validator.ResultType type, Component component, String JavaDoc desc, String JavaDoc correction) {
562         String JavaDoc message = desc;
563         if (correction != null) {
564             message = desc + " : " + correction;
565         }
566         ResultItem item = new Validator.ResultItem(mValidator, type, component, message);
567         mResultItems.add(item);
568         return true;
569     }
570 }
571
Popular Tags