001: /* XMLValidationException.java NanoXML/Java
002: *
003: * $Revision: 1.17 $
004: * $Date: 2005/01/05 17:20:04 $
005: * $Name: $
006: *
007: * This file is part of NanoXML 2 for Java.
008: * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009: *
010: * This software is provided 'as-is', without any express or implied warranty.
011: * In no event will the authors be held liable for any damages arising from the
012: * use of this software.
013: *
014: * Permission is granted to anyone to use this software for any purpose,
015: * including commercial applications, and to alter it and redistribute it
016: * freely, subject to the following restrictions:
017: *
018: * 1. The origin of this software must not be misrepresented; you must not
019: * claim that you wrote the original software. If you use this software in
020: * a product, an acknowledgment in the product documentation would be
021: * appreciated but is not required.
022: *
023: * 2. Altered source versions must be plainly marked as such, and must not be
024: * misrepresented as being the original software.
025: *
026: * 3. This notice may not be removed or altered from any source distribution.
027: */
028:
029: package net.n3.nanoxml;
030:
031: /**
032: * An XMLValidationException is thrown when the XML passed to the XML parser is
033: * well-formed but not valid.
034: *
035: * @author Marc De Scheemaecker
036: * @version $Name: $, $Revision: 1.17 $
037: */
038: public class XMLValidationException extends XMLException {
039:
040: /**
041: * An element was missing.
042: */
043: public static final int MISSING_ELEMENT = 1;
044:
045: /**
046: * An unexpected element was encountered.
047: */
048: public static final int UNEXPECTED_ELEMENT = 2;
049:
050: /**
051: * An attribute was missing.
052: */
053: public static final int MISSING_ATTRIBUTE = 3;
054:
055: /**
056: * An unexpected attribute was encountered.
057: */
058: public static final int UNEXPECTED_ATTRIBUTE = 4;
059:
060: /**
061: * An attribute has an invalid value.
062: */
063: public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5;
064:
065: /**
066: * A PCDATA element was missing.
067: */
068: public static final int MISSING_PCDATA = 6;
069:
070: /**
071: * An unexpected PCDATA element was encountered.
072: */
073: public static final int UNEXPECTED_PCDATA = 7;
074:
075: /**
076: * Another error than those specified in this class was encountered.
077: */
078: public static final int MISC_ERROR = 0;
079:
080: /**
081: * Which error occurred.
082: */
083: private int errorType;
084:
085: /**
086: * The name of the element where the exception occurred.
087: */
088: private String elementName;
089:
090: /**
091: * The name of the attribute where the exception occurred.
092: */
093: private String attributeName;
094:
095: /**
096: * The value of the attribute where the exception occurred.
097: */
098: private String attributeValue;
099:
100: /**
101: * Creates a new exception.
102: *
103: * @param errorType the type of validity error
104: * @param systemID the system ID from where the data came
105: * @param lineNr the line number in the XML data where the
106: * exception occurred.
107: * @param elementName the name of the offending element
108: * @param attributeName the name of the offending attribute
109: * @param attributeValue the value of the offending attribute
110: * @param msg the message of the exception.
111: */
112: public XMLValidationException(int errorType, String systemID,
113: int lineNr, String elementName, String attributeName,
114: String attributeValue, String msg) {
115: super (systemID, lineNr, null, msg
116: + ((elementName == null) ? ""
117: : (", element=" + elementName))
118: + ((attributeName == null) ? ""
119: : (", attribute=" + attributeName))
120: + ((attributeValue == null) ? "" : (", value='"
121: + attributeValue + "'")), false);
122: this .elementName = elementName;
123: this .attributeName = attributeName;
124: this .attributeValue = attributeValue;
125: }
126:
127: /**
128: * Cleans up the object when it's destroyed.
129: */
130: protected void finalize() throws Throwable {
131: this .elementName = null;
132: this .attributeName = null;
133: this .attributeValue = null;
134: super .finalize();
135: }
136:
137: /**
138: * Returns the name of the element in which the validation is violated.
139: * If there is no current element, null is returned.
140: */
141: public String getElementName() {
142: return this .elementName;
143: }
144:
145: /**
146: * Returns the name of the attribute in which the validation is violated.
147: * If there is no current attribute, null is returned.
148: */
149: public String getAttributeName() {
150: return this .attributeName;
151: }
152:
153: /**
154: * Returns the value of the attribute in which the validation is violated.
155: * If there is no current attribute, null is returned.
156: */
157: public String getAttributeValue() {
158: return this.attributeValue;
159: }
160:
161: }
|