KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > spi > Validator


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.xam.spi;
20
21 import org.netbeans.modules.xml.xam.Component;
22 import org.netbeans.modules.xml.xam.Model;
23 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
24
25
26 /**
27  * Common interface for validation services on models and components.
28  * Typical implementation would implement a domain-specific subtype and publish
29  * the implemenation through META-INF/services.
30  * Typical client would lookup and select applicable services for the validation
31  * target model.
32  *
33  * @author Nam Nguyen
34  * @author Ritesh
35  * @author Praveen Savur
36  */

37
38 public interface Validator {
39     
40     /**
41      * Returns name of this validation service.
42      * @return Name of the validator.
43      */

44     String JavaDoc getName();
45     
46     
47     
48     /**
49      * Validates given model.
50      * @return ValidationResult.
51      * @param validationType Type of validation. Complete(slow) or partial(fast).
52      * @param model model to validate.
53      * @param validation reference to the validation context.
54      */

55     ValidationResult validate(Model model, Validation validation,
56             ValidationType validationType);
57     
58     
59     enum ResultType {
60         ADVICE, WARNING, ERROR
61     }
62     
63     public class ResultItem {
64         private Validator validator;
65         private ResultType type;
66         private Component component = null;
67         private String JavaDoc description;
68         private int lineNumber = -1;
69         private int columnNumber = -1;
70         private Model model;
71         
72         /**
73          * Constructor to create an instance of ResultItem
74          * @param validator Reference to validator.
75          * @param type Type of message.
76          * @param component Component to which this resultItem points.
77          * @param desc Message text string.
78          */

79         public ResultItem(Validator validator, ResultType type, Component component,
80                 String JavaDoc desc) {
81             this.validator = validator;
82             this.type = type;
83             this.component = component;
84             this.description = desc;
85             this.model = component.getModel();
86         }
87         
88         
89         /**
90          * Constructor to create an instance of ResultItem
91          * @param validator Reference to validator.
92          * @param type Type of message.
93          * @param desc Message text string.
94          * @param lineNumber Line number where this error happens.
95          * @param columnNumber Column Number where this error happens.
96          * @param model Model on which this is reported.
97          */

98         public ResultItem(Validator validator, ResultType type,
99                 String JavaDoc desc, int lineNumber, int columnNumber, Model model) {
100                 this.validator = validator;
101                 this.type = type;
102                 this.description = desc;
103                 this.lineNumber = lineNumber;
104                 this.columnNumber = columnNumber;
105                 this.model = model;
106         }
107         
108         
109         /**
110          * Get the validator which generated this error.
111          * @return The validator that generated this ResultItem.
112          */

113         public Validator getValidator() {
114             return validator;
115         }
116         
117         /**
118          * Returns type of validation result.
119          * @return Type of message. Advice/Warning or Error.
120          */

121         public ResultType getType() {
122             return type;
123         }
124         
125         /**
126          * Returns target component of the validation result.
127          * @return Component on which this validation result is reported.
128          * Return value can be null if the model is non-well formed, in this case
129          * use line/column numbers.
130          * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
131          */

132         public Component getComponents() {
133             return component;
134         }
135         
136         /**
137          * Returns description of the validation result item.
138          * @return Message describing advice/warning or error.
139          */

140         public String JavaDoc getDescription() {
141             return description;
142         }
143         
144         /**
145          * Line position of advice/warning/error.
146          * @return Line number on which this ResultItem was reported on.
147          * Use Component if line number is -1.
148          * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
149          */

150         public int getLineNumber() {
151             return lineNumber;
152         }
153         
154         /**
155          * Column position of advice/warning/error.
156          * @return Column number on which this ResultItem was reported on.
157          * Use Component if column number is -1.
158          * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
159          */

160         public int getColumnNumber() {
161             return columnNumber;
162         }
163         
164         /**
165          * Model on which this ResultItem was reported on.
166          * @return Model
167          */

168         public Model getModel() {
169             return model;
170         }
171         
172     }
173 }
174
Popular Tags