KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > type > ValidationException


1 package net.sf.saxon.type;
2
3 import net.sf.saxon.trans.XPathException;
4 import org.xml.sax.Locator JavaDoc;
5
6 import javax.xml.transform.SourceLocator JavaDoc;
7
8 /**
9  * This exception indicates a failure when validating an instance against a type
10  * defined in a schema.
11  */

12
13 public class ValidationException extends XPathException
14         implements SourceLocator JavaDoc, Locator JavaDoc {
15
16     private String JavaDoc systemId;
17     private String JavaDoc publicId;
18     private int lineNumber = -1;
19     private int columnNumber = -1;
20
21     /**
22      * Creates a new ValidationException with the given message.
23      * @param message the message for this Exception
24     **/

25     public ValidationException(String JavaDoc message) {
26         super(message);
27     }
28
29     /**
30      * Creates a new ValidationException with the given nested
31      * exception.
32      * @param exception the nested exception
33     **/

34     public ValidationException(Exception JavaDoc exception) {
35         super(exception);
36     }
37
38     /**
39      * Creates a new ValidationException with the given message
40      * and nested exception.
41      * @param message the detail message for this exception
42      * @param exception the nested exception
43     **/

44     public ValidationException(String JavaDoc message, Exception JavaDoc exception) {
45         super(message, exception);
46     }
47
48     /**
49      * Create a new XPathException from a message and a Locator.
50      * @param message The error or warning message.
51      * @param locator The locator object for the error or warning.
52      */

53     public ValidationException(String JavaDoc message, SourceLocator JavaDoc locator) {
54         super(message, locator);
55         // With Xerces, it's enough to store the locator as part of the exception. But with Crimson,
56
// the locator is destroyed when the parse terminates, which means the location information
57
// will not be available in the final error message. So we copy the location information now,
58
// as part of the exception object itself.
59
setSourceLocator(locator);
60     }
61
62      /**
63      * Returns the String representation of this Exception
64      * @return the String representation of this Exception
65     **/

66     public String JavaDoc toString() {
67         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ValidationException: ");
68         String JavaDoc message = getMessage();
69         if (message != null) sb.append(message);
70         return sb.toString();
71     }
72
73     public String JavaDoc getPublicId() {
74         if (publicId == null && getLocator() != this) {
75             return getLocator().getPublicId();
76         } else{
77             return publicId;
78         }
79     }
80
81     public String JavaDoc getSystemId() {
82         if (systemId == null && getLocator() != this) {
83             return getLocator().getSystemId();
84         } else{
85             return systemId;
86         }
87     }
88
89     public int getLineNumber() {
90         if (lineNumber == -1 && getLocator() != this) {
91             return getLocator().getLineNumber();
92         } else{
93             return lineNumber;
94         }
95     }
96
97     public int getColumnNumber() {
98         if (columnNumber == -1 && getLocator() != this) {
99             return getLocator().getColumnNumber();
100         } else{
101             return columnNumber;
102         }
103     }
104
105     public void setPublicId(String JavaDoc id) {
106         publicId = id;
107     }
108
109     public void setSystemId(String JavaDoc id) {
110         systemId = id;
111     }
112
113     public void setLineNumber(int line) {
114         lineNumber = line;
115     }
116
117     public void setColumnNumber(int column) {
118         columnNumber = column;
119     }
120
121     public void setLocator(Locator JavaDoc locator) {
122         setPublicId(locator.getPublicId());
123         setSystemId(locator.getSystemId());
124         setLineNumber(locator.getLineNumber());
125         setColumnNumber(locator.getColumnNumber());
126         super.setLocator(null);
127     }
128
129     public void setSourceLocator(SourceLocator JavaDoc locator) {
130         setPublicId(locator.getPublicId());
131         setSystemId(locator.getSystemId());
132         setLineNumber(locator.getLineNumber());
133         setColumnNumber(locator.getColumnNumber());
134         super.setLocator(null);
135     }
136
137     public SourceLocator JavaDoc getLocator() {
138         SourceLocator JavaDoc loc = super.getLocator();
139         if (loc != null) {
140             return loc;
141         } else {
142             return this;
143         }
144     }
145
146 }
147
148 //
149
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
150
// you may not use this file except in compliance with the License. You may obtain a copy of the
151
// License at http://www.mozilla.org/MPL/
152
//
153
// Software distributed under the License is distributed on an "AS IS" basis,
154
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
155
// See the License for the specific language governing rights and limitations under the License.
156
//
157
// The Original Code is: all this file.
158
//
159
// The Initial Developer of the Original Code is Saxonica Limited
160
//
161
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
162
//
163
// Contributor(s): none
164
//
Popular Tags