KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > ValidationHelper


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation;
21
22 import java.net.URI JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.regex.Pattern JavaDoc;
26 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel;
27 import org.netbeans.modules.xml.xam.spi.Validation;
28 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
29 import org.netbeans.modules.xml.xam.spi.ValidationResult;
30 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
31
32 /**
33  *
34  * @author radval
35  */

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