KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > n3 > nanoxml > XMLValidationException


1 /* XMLValidationException.java NanoXML/Java
2  *
3  * $Revision: 1421 $
4  * $Date: 2006-03-12 17:32:32 +0100 (Sun, 12 Mar 2006) $
5  * $Name$
6  *
7  * This file is part of NanoXML 2 for Java.
8  * Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved.
9  *
10  * This software is provided 'as-is', without any express or implied warranty.
11  * In no event will the authors be held liable for any damages arising from the
12  * use of this software.
13  *
14  * Permission is granted to anyone to use this software for any purpose,
15  * including commercial applications, and to alter it and redistribute it
16  * freely, subject to the following restrictions:
17  *
18  * 1. The origin of this software must not be misrepresented; you must not
19  * claim that you wrote the original software. If you use this software in
20  * a product, an acknowledgment in the product documentation would be
21  * appreciated but is not required.
22  *
23  * 2. Altered source versions must be plainly marked as such, and must not be
24  * misrepresented as being the original software.
25  *
26  * 3. This notice may not be removed or altered from any source distribution.
27  */

28
29 package net.n3.nanoxml;
30
31 /**
32  * An XMLValidationException is thrown when the XML passed to the XML parser is well-formed but not
33  * valid.
34  *
35  * @author Marc De Scheemaecker
36  * @version $Name$, $Revision: 1421 $
37  */

38 public class XMLValidationException extends XMLException
39 {
40
41     /**
42      *
43      */

44     private static final long serialVersionUID = 3616453380025890867L;
45
46     /**
47      * An element was missing.
48      */

49     public static final int MISSING_ELEMENT = 1;
50
51     /**
52      * An unexpected element was encountered.
53      */

54     public static final int UNEXPECTED_ELEMENT = 2;
55
56     /**
57      * An attribute was missing.
58      */

59     public static final int MISSING_ATTRIBUTE = 3;
60
61     /**
62      * An unexpected attribute was encountered.
63      */

64     public static final int UNEXPECTED_ATTRIBUTE = 4;
65
66     /**
67      * An attribute has an invalid value.
68      */

69     public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5;
70
71     /**
72      * A PCDATA element was missing.
73      */

74     public static final int MISSING_PCDATA = 6;
75
76     /**
77      * An unexpected PCDATA element was encountered.
78      */

79     public static final int UNEXPECTED_PCDATA = 7;
80
81     /**
82      * Another error than those specified in this class was encountered.
83      */

84     public static final int MISC_ERROR = 0;
85
86     /**
87      * The name of the element where the exception occurred.
88      */

89     private String JavaDoc elementName;
90
91     /**
92      * The name of the attribute where the exception occurred.
93      */

94     private String JavaDoc attributeName;
95
96     /**
97      * The value of the attribute where the exception occurred.
98      */

99     private String JavaDoc attributeValue;
100
101     /**
102      * Creates a new exception.
103      *
104      * @param errorType the type of validity error
105      * @param systemID the system ID from where the data came
106      * @param lineNr the line number in the XML data where the 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 JavaDoc systemID, int lineNr, String JavaDoc elementName,
113             String JavaDoc attributeName, String JavaDoc attributeValue, String JavaDoc msg)
114     {
115         super(systemID, lineNr, null, msg
116                 + ((elementName == null) ? "" : (", element=" + elementName))
117                 + ((attributeName == null) ? "" : (", attribute=" + attributeName))
118                 + ((attributeValue == null) ? "" : (", value='" + attributeValue + "'")), false);
119         this.elementName = elementName;
120         this.attributeName = attributeName;
121         this.attributeValue = attributeValue;
122     }
123
124     /**
125      * Cleans up the object when it's destroyed.
126      */

127     protected void finalize() throws Throwable JavaDoc
128     {
129         this.elementName = null;
130         this.attributeName = null;
131         this.attributeValue = null;
132         super.finalize();
133     }
134
135     /**
136      * Returns the name of the element in which the validation is violated. If there is no current
137      * element, null is returned.
138      */

139     public String JavaDoc getElementName()
140     {
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 JavaDoc getAttributeName()
149     {
150         return this.attributeName;
151     }
152
153     /**
154      * Returns the value of the attribute in which the validation is violated. If there is no
155      * current attribute, null is returned.
156      */

157     public String JavaDoc getAttributeValue()
158     {
159         return this.attributeValue;
160     }
161
162 }
163
Popular Tags