001: /* XMLValidationException.java NanoXML/Java
002: *
003: * $Revision: 1421 $
004: * $Date: 2006-03-12 09:32:32 -0700 (Sun, 12 Mar 2006) $
005: * $Name$
006: *
007: * This file is part of NanoXML 2 for Java.
008: * Copyright (C) 2001 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 well-formed but not
033: * valid.
034: *
035: * @author Marc De Scheemaecker
036: * @version $Name$, $Revision: 1421 $
037: */
038: public class XMLValidationException extends XMLException {
039:
040: /**
041: *
042: */
043: private static final long serialVersionUID = 3616453380025890867L;
044:
045: /**
046: * An element was missing.
047: */
048: public static final int MISSING_ELEMENT = 1;
049:
050: /**
051: * An unexpected element was encountered.
052: */
053: public static final int UNEXPECTED_ELEMENT = 2;
054:
055: /**
056: * An attribute was missing.
057: */
058: public static final int MISSING_ATTRIBUTE = 3;
059:
060: /**
061: * An unexpected attribute was encountered.
062: */
063: public static final int UNEXPECTED_ATTRIBUTE = 4;
064:
065: /**
066: * An attribute has an invalid value.
067: */
068: public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5;
069:
070: /**
071: * A PCDATA element was missing.
072: */
073: public static final int MISSING_PCDATA = 6;
074:
075: /**
076: * An unexpected PCDATA element was encountered.
077: */
078: public static final int UNEXPECTED_PCDATA = 7;
079:
080: /**
081: * Another error than those specified in this class was encountered.
082: */
083: public static final int MISC_ERROR = 0;
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 exception occurred.
106: * @param elementName the name of the offending element
107: * @param attributeName the name of the offending attribute
108: * @param attributeValue the value of the offending attribute
109: * @param msg the message of the exception.
110: */
111: public XMLValidationException(int errorType, String systemID,
112: int lineNr, String elementName, String attributeName,
113: String attributeValue, String msg) {
114: super (systemID, lineNr, null, msg
115: + ((elementName == null) ? ""
116: : (", element=" + elementName))
117: + ((attributeName == null) ? ""
118: : (", attribute=" + attributeName))
119: + ((attributeValue == null) ? "" : (", value='"
120: + attributeValue + "'")), false);
121: this .elementName = elementName;
122: this .attributeName = attributeName;
123: this .attributeValue = attributeValue;
124: }
125:
126: /**
127: * Cleans up the object when it's destroyed.
128: */
129: protected void finalize() throws Throwable {
130: this .elementName = null;
131: this .attributeName = null;
132: this .attributeValue = null;
133: super .finalize();
134: }
135:
136: /**
137: * Returns the name of the element in which the validation is violated. If there is no current
138: * element, null is returned.
139: */
140: public String getElementName() {
141: return this .elementName;
142: }
143:
144: /**
145: * Returns the name of the attribute in which the validation is violated. If there is no current
146: * attribute, null is returned.
147: */
148: public String getAttributeName() {
149: return this .attributeName;
150: }
151:
152: /**
153: * Returns the value of the attribute in which the validation is violated. If there is no
154: * current attribute, null is returned.
155: */
156: public String getAttributeValue() {
157: return this.attributeValue;
158: }
159:
160: }
|