001: package net.sf.saxon.type;
002:
003: import net.sf.saxon.trans.XPathException;
004: import org.xml.sax.Locator;
005:
006: import javax.xml.transform.SourceLocator;
007:
008: /**
009: * This exception indicates a failure when validating an instance against a type
010: * defined in a schema.
011: */
012:
013: public class ValidationException extends XPathException implements
014: SourceLocator, Locator {
015:
016: private String systemId;
017: private String publicId;
018: private int lineNumber = -1;
019: private int columnNumber = -1;
020:
021: /**
022: * Creates a new ValidationException with the given message.
023: * @param message the message for this Exception
024: **/
025: public ValidationException(String message) {
026: super (message);
027: }
028:
029: /**
030: * Creates a new ValidationException with the given nested
031: * exception.
032: * @param exception the nested exception
033: **/
034: public ValidationException(Exception exception) {
035: super (exception);
036: }
037:
038: /**
039: * Creates a new ValidationException with the given message
040: * and nested exception.
041: * @param message the detail message for this exception
042: * @param exception the nested exception
043: **/
044: public ValidationException(String message, Exception exception) {
045: super (message, exception);
046: }
047:
048: /**
049: * Create a new XPathException from a message and a Locator.
050: * @param message The error or warning message.
051: * @param locator The locator object for the error or warning.
052: */
053: public ValidationException(String message, SourceLocator locator) {
054: super (message, locator);
055: // With Xerces, it's enough to store the locator as part of the exception. But with Crimson,
056: // the locator is destroyed when the parse terminates, which means the location information
057: // will not be available in the final error message. So we copy the location information now,
058: // as part of the exception object itself.
059: setSourceLocator(locator);
060: }
061:
062: /**
063: * Returns the String representation of this Exception
064: * @return the String representation of this Exception
065: **/
066: public String toString() {
067: StringBuffer sb = new StringBuffer("ValidationException: ");
068: String message = getMessage();
069: if (message != null)
070: sb.append(message);
071: return sb.toString();
072: }
073:
074: public String getPublicId() {
075: if (publicId == null && getLocator() != this ) {
076: return getLocator().getPublicId();
077: } else {
078: return publicId;
079: }
080: }
081:
082: public String getSystemId() {
083: if (systemId == null && getLocator() != this ) {
084: return getLocator().getSystemId();
085: } else {
086: return systemId;
087: }
088: }
089:
090: public int getLineNumber() {
091: if (lineNumber == -1 && getLocator() != this ) {
092: return getLocator().getLineNumber();
093: } else {
094: return lineNumber;
095: }
096: }
097:
098: public int getColumnNumber() {
099: if (columnNumber == -1 && getLocator() != this ) {
100: return getLocator().getColumnNumber();
101: } else {
102: return columnNumber;
103: }
104: }
105:
106: public void setPublicId(String id) {
107: publicId = id;
108: }
109:
110: public void setSystemId(String id) {
111: systemId = id;
112: }
113:
114: public void setLineNumber(int line) {
115: lineNumber = line;
116: }
117:
118: public void setColumnNumber(int column) {
119: columnNumber = column;
120: }
121:
122: public void setLocator(Locator locator) {
123: setPublicId(locator.getPublicId());
124: setSystemId(locator.getSystemId());
125: setLineNumber(locator.getLineNumber());
126: setColumnNumber(locator.getColumnNumber());
127: super .setLocator(null);
128: }
129:
130: public void setSourceLocator(SourceLocator locator) {
131: setPublicId(locator.getPublicId());
132: setSystemId(locator.getSystemId());
133: setLineNumber(locator.getLineNumber());
134: setColumnNumber(locator.getColumnNumber());
135: super .setLocator(null);
136: }
137:
138: public SourceLocator getLocator() {
139: SourceLocator loc = super .getLocator();
140: if (loc != null) {
141: return loc;
142: } else {
143: return this ;
144: }
145: }
146:
147: }
148:
149: //
150: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
151: // you may not use this file except in compliance with the License. You may obtain a copy of the
152: // License at http://www.mozilla.org/MPL/
153: //
154: // Software distributed under the License is distributed on an "AS IS" basis,
155: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
156: // See the License for the specific language governing rights and limitations under the License.
157: //
158: // The Original Code is: all this file.
159: //
160: // The Initial Developer of the Original Code is Saxonica Limited
161: //
162: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
163: //
164: // Contributor(s): none
165: //
|