KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > validator > ValidationHelper


1 /*
2  * ValidationHelper.java
3  *
4  * Created on June 29, 2006, 4:54 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.xml.wsdl.validator;
11
12 import java.util.Iterator JavaDoc;
13 import java.util.Set JavaDoc;
14 import java.util.regex.Pattern JavaDoc;
15 import org.netbeans.modules.xml.xam.spi.Validation;
16 import org.netbeans.modules.xml.xam.spi.ValidationResult;
17 import org.netbeans.modules.xml.xam.spi.Validator;
18
19 /**
20  *
21  * @author radval
22  */

23 public class ValidationHelper {
24     
25     private static Pattern JavaDoc p = Pattern.compile("\"?+\\{\\d\\}\"?+");
26     
27     /** Creates a new instance of ValidationHelper */
28     public ValidationHelper() {
29     }
30     
31     public static void dumpExpecedErrors(Set JavaDoc<String JavaDoc> expectedErrors) {
32         int counter = 1;
33         Iterator JavaDoc<String JavaDoc> it = expectedErrors.iterator();
34         while(it.hasNext()) {
35             String JavaDoc expectedError = it.next();
36             System.out.println("expected error :"+ counter + " " + expectedError);
37             counter++;
38         }
39     }
40     
41     public static boolean containsExpectedError(Set JavaDoc<String JavaDoc> expectedErrors, String JavaDoc actualError) {
42         boolean result = false;
43         Iterator JavaDoc<String JavaDoc> it = expectedErrors.iterator();
44         while(it.hasNext()) {
45             String JavaDoc[] needToMatch = null;
46             String JavaDoc expectedError = it.next();
47             needToMatch = p.split(expectedError);
48
49             //now let see if expected error can be matched with actual error.
50
if(needToMatch != null) {
51                 //assume we have a match unless we found a mismatch below
52
boolean foundMatch = true;
53                 for(int i = 0; i < needToMatch.length; i++) {
54                     String JavaDoc match = needToMatch[i];
55                     if(!actualError.contains(match)) {
56                         //no exact match found.
57
foundMatch = false;
58                         break;
59                     }
60                 }
61                 
62                 result = foundMatch;
63                 if(result) {
64                     break;
65                 }
66             }
67             
68         }
69         return result;
70     }
71     
72     public static void dumpErrors(ValidationResult result) {
73         int counter = 1;
74         
75         Iterator JavaDoc<Validator.ResultItem> it = result.getValidationResult().iterator();
76         while(it.hasNext()) {
77              Validator.ResultItem item = it.next();
78              String JavaDoc expectedError = item.getDescription();
79             System.out.println("found error :"+ counter + " " + expectedError);
80             counter++;
81         }
82     }
83     
84 }
85
Popular Tags