001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.xam.spi;
042:
043: import org.netbeans.modules.xml.xam.Component;
044: import org.netbeans.modules.xml.xam.Model;
045: import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
046:
047: /**
048: * Common interface for validation services on models and components.
049: * Typical implementation would implement a domain-specific subtype and publish
050: * the implemenation through META-INF/services.
051: * Typical client would lookup and select applicable services for the validation
052: * target model.
053: *
054: * @author Nam Nguyen
055: * @author Ritesh
056: * @author Praveen Savur
057: */
058:
059: public interface Validator {
060:
061: /**
062: * Returns name of this validation service.
063: * @return Name of the validator.
064: */
065: String getName();
066:
067: /**
068: * Validates given model.
069: * @return ValidationResult.
070: * @param validationType Type of validation. Complete(slow) or partial(fast).
071: * @param model model to validate.
072: * @param validation reference to the validation context.
073: */
074: ValidationResult validate(Model model, Validation validation,
075: ValidationType validationType);
076:
077: enum ResultType {
078: ADVICE, WARNING, ERROR
079: }
080:
081: public class ResultItem {
082: private Validator validator;
083: private ResultType type;
084: private Component component;
085: private String description;
086: private int lineNumber;
087: private int columnNumber;
088: private Model model;
089:
090: /**
091: * Constructor to create an instance of ResultItem
092: * @param validator Reference to validator.
093: * @param type Type of message.
094: * @param component Component to which this resultItem points.
095: * @param desc Message text string.
096: */
097: public ResultItem(Validator validator, ResultType type,
098: Component component, String desc) {
099: this (validator, type, desc, component, -1, -1, null);
100: }
101:
102: /**
103: * Constructor to create an instance of ResultItem
104: * @param validator Reference to validator.
105: * @param type Type of message.
106: * @param desc Message text string.
107: * @param lineNumber Line number where this error happens.
108: * @param columnNumber Column Number where this error happens.
109: * @param model Model on which this is reported.
110: */
111: public ResultItem(Validator validator, ResultType type,
112: String desc, int lineNumber, int columnNumber,
113: Model model) {
114: this (validator, type, desc, null, lineNumber, columnNumber,
115: model);
116: }
117:
118: private ResultItem(Validator validator, ResultType type,
119: String desc, Component component, int lineNumber,
120: int columnNumber, Model model) {
121: this .validator = validator;
122: this .type = type;
123: this .description = desc;
124: this .lineNumber = lineNumber;
125: this .columnNumber = columnNumber;
126: this .component = component;
127:
128: if (model != null) {
129: this .model = model;
130: } else {
131: this .model = (component == null) ? null : component
132: .getModel();
133: }
134: }
135:
136: /**
137: * Get the validator which generated this error.
138: * @return The validator that generated this ResultItem.
139: */
140: public Validator getValidator() {
141: return validator;
142: }
143:
144: /**
145: * Returns type of validation result.
146: * @return Type of message. Advice/Warning or Error.
147: */
148: public ResultType getType() {
149: return type;
150: }
151:
152: /**
153: * Returns target component of the validation result.
154: * @return Component on which this validation result is reported.
155: * Return value can be null if the model is non-well formed, in this case
156: * use line/column numbers.
157: * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
158: */
159: public Component getComponents() {
160: return component;
161: }
162:
163: /**
164: * Returns description of the validation result item.
165: * @return Message describing advice/warning or error.
166: */
167: public String getDescription() {
168: return description;
169: }
170:
171: /**
172: * Line position of advice/warning/error.
173: * @return Line number on which this ResultItem was reported on.
174: * Use Component if line number is -1.
175: * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
176: */
177: public int getLineNumber() {
178: return lineNumber;
179: }
180:
181: /**
182: * Column position of advice/warning/error.
183: * @return Column number on which this ResultItem was reported on.
184: * Use Component if column number is -1.
185: * Either getComponents() or getLineNumber/getColumnNumber() will be valid.
186: */
187: public int getColumnNumber() {
188: return columnNumber;
189: }
190:
191: /**
192: * Model on which this ResultItem was reported on.
193: * @return Model
194: */
195: public Model getModel() {
196: return model;
197: }
198: }
199: }
|