KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > validation > ValidationOutputWindowController


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.validation;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.xml.validation.ui.ValidationOutputWindow;
26 import org.netbeans.modules.xml.xam.Model;
27 import org.netbeans.modules.xml.xam.Model.State;
28 import org.netbeans.modules.xml.xam.spi.Validation;
29 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
30 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
31 import org.openide.util.NbBundle;
32
33 /**
34  *
35  * @author Praveen Savur
36  */

37 public class ValidationOutputWindowController {
38     
39     /** Creates a new instance of ValidationOutputWindowController */
40     public ValidationOutputWindowController() {
41     }
42     
43     
44     /**
45      * Validates the model. Call this on a non-AWT thread. The model
46      * will be synchronized (i.e. sync() will be called) before the
47      * validation is performed.
48      *
49      * @param model the model to validate.
50      */

51     public List JavaDoc<ResultItem> validate(Model model) {
52         
53         // Ensure the model is in sync.
54
if (model!=null && !model.inSync()) {
55             try {
56                 model.sync();
57             } catch (IOException JavaDoc ioe) {
58                 // Ignore and let the validator discover the error
59
// and report it to the user.
60
}
61         }
62         
63         Validation validation = new Validation();
64         validation.validate(model, ValidationType.COMPLETE);
65         List JavaDoc<ResultItem> validationResult = validation.getValidationResult();
66         printGuidanceInformation(validationResult);
67         
68         return validationResult;
69     }
70     
71     
72     
73     private void printGuidanceInformation(List JavaDoc<ResultItem> guidanceInformation) {
74         ValidationOutputWindow guidanceOutputWindow = new ValidationOutputWindow();
75         guidanceOutputWindow.displayValidationInformation(guidanceInformation);
76     }
77     
78 }
79
Popular Tags