Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / net / n3 / nanoxml / XMLValidationException.java @ 15280

History | View | Annotate | Download (5.36 KB)

1
/* XMLValidationException.java                                     NanoXML/Java
2
 *
3
 * $Revision: 1.1 $
4
 * $Date: 2006/06/14 07:29:07 $
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
/**
33
 * An XMLValidationException is thrown when the XML passed to the XML parser is
34
 * well-formed but not valid.
35
 *
36
 * @author Marc De Scheemaecker
37
 * @version $Name:  $, $Revision: 1.1 $
38
 */
39
public class XMLValidationException
40
    extends XMLException
41
{
42

    
43
    /**
44
     * An element was missing.
45
     */
46
    public static final int MISSING_ELEMENT = 1;
47
    
48
    
49
    /**
50
     * An unexpected element was encountered.
51
     */
52
    public static final int UNEXPECTED_ELEMENT = 2;
53
    
54
    
55
    /**
56
     * An attribute was missing.
57
     */
58
    public static final int MISSING_ATTRIBUTE = 3;
59
    
60
    
61
    /**
62
     * An unexpected attribute was encountered.
63
     */
64
    public static final int UNEXPECTED_ATTRIBUTE = 4;
65
    
66
    
67
    /**
68
     * An attribute has an invalid value.
69
     */
70
    public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5;
71
    
72
    
73
    /**
74
     * A PCDATA element was missing.
75
     */
76
    public static final int MISSING_PCDATA = 6;
77
    
78
    
79
    /**
80
     * An unexpected PCDATA element was encountered.
81
     */
82
    public static final int UNEXPECTED_PCDATA = 7;
83
    
84
    
85
    /**
86
     * Another error than those specified in this class was encountered.
87
     */
88
    public static final int MISC_ERROR = 0;
89
    
90
    
91
    /**
92
     * Which error occurred.
93
     */
94
    private int errorType;
95
    
96
    
97
    /**
98
     * The name of the element where the exception occurred.
99
     */
100
    private String elementName;
101
    
102
    
103
    /**
104
     * The name of the attribute where the exception occurred.
105
     */
106
    private String attributeName;
107
    
108
    
109
    /**
110
     * The value of the attribute where the exception occurred.
111
     */
112
    private String attributeValue;
113
    
114
    
115
    /**
116
     * Creates a new exception.
117
     *
118
     * @param errorType      the type of validity error
119
     * @param systemID       the system ID from where the data came
120
     * @param lineNr         the line number in the XML data where the
121
     *                       exception occurred.
122
     * @param elementName    the name of the offending element
123
     * @param attributeName  the name of the offending attribute
124
     * @param attributeValue the value of the offending attribute
125
     * @param msg            the message of the exception.
126
     */
127
    public XMLValidationException(int    errorType,
128
                                  String systemID,
129
                                  int    lineNr,
130
                                  String elementName,
131
                                  String attributeName,
132
                                  String attributeValue,
133
                                  String msg)
134
    {
135
        super(systemID, lineNr, null,
136
              msg + ((elementName == null) ? "" : (", element=" + elementName))
137
                  + ((attributeName == null) ? ""
138
                        : (", attribute=" + attributeName))
139
                  + ((attributeValue == null) ? ""
140
                        : (", value='" + attributeValue + "'")),
141
              false);
142
        this.elementName = elementName;
143
        this.attributeName = attributeName;
144
        this.attributeValue = attributeValue;
145
    }
146
    
147
    
148
    /**
149
     * Cleans up the object when it's destroyed.
150
     */
151
    protected void finalize()
152
        throws Throwable
153
    {
154
        this.elementName = null;
155
        this.attributeName = null;
156
        this.attributeValue = null;
157
        super.finalize();
158
    }
159
    
160
    
161
    /**
162
     * Returns the name of the element in which the validation is violated.
163
     * If there is no current element, null is returned.
164
     */
165
    public String getElementName()
166
    {
167
        return this.elementName;
168
    }
169
    
170
    
171
    /**
172
     * Returns the name of the attribute in which the validation is violated.
173
     * If there is no current attribute, null is returned.
174
     */
175
    public String getAttributeName()
176
    {
177
        return this.attributeName;
178
    }
179
    
180
    
181
    /**
182
     * Returns the value of the attribute in which the validation is violated.
183
     * If there is no current attribute, null is returned.
184
     */
185
    public String getAttributeValue()
186
    {
187
        return this.attributeValue;
188
    }
189
    
190
}