1 /*
2 * Redistribution and use of this software and associated documentation ("Software"), with or
3 * without modification, are permitted provided that the following conditions are met:
4 *
5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions
6 * must also contain a copy of this document.
7 *
8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials provided with
10 * the distribution.
11 *
12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software
13 * without prior written permission of Intalio, Inc. For written permission, please contact
14 * info@exolab.org.
15 *
16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in
17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of
18 * Intalio, Inc.
19 *
20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/).
21 *
22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
32 *
33 * $Id$
34 */
35 package org.exolab.castor.xml;
36
37 import org.exolab.castor.core.exceptions.CastorException;
38 import org.exolab.castor.xml.location.Location;
39
40 /**
41 * An exception that is used to signal an error that has occurred during marshaling or unmarshaling.
42 *
43 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
44 * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
45 */
46 public class XMLException extends CastorException {
47 /** SerialVersionUID */
48 private static final long serialVersionUID = 7512918645754995146L;
49
50 /**
51 * The location for this Exception.
52 */
53 private Location _location = null;
54
55 /**
56 * The error code for this exception.
57 */
58 private int errorCode = -1;
59
60 /**
61 * Creates a new instance of this class with no message or nested exception.
62 */
63 public XMLException() {
64 super();
65 }
66
67 /**
68 * Creates a new {@link XMLException} instance with the given message.
69 *
70 * @param message the message for this Exception
71 */
72 public XMLException(final String message) {
73 super(message);
74 }
75
76 /**
77 * Creates a new XMLException with the given nested Exception.
78 *
79 * @param exception the nested exception
80 */
81 public XMLException(final Throwable exception) {
82 super(exception);
83 }
84
85 /**
86 * Creates a new XMLException with the given message and error code.
87 *
88 * @param message the message for this Exception
89 * @param errorCode the errorCode for this Exception
90 *
91 * @deprecated
92 */
93 public XMLException(final String message, final int errorCode) {
94 super(message);
95 this.errorCode = errorCode;
96 }
97
98 /**
99 * Creates a new XMLException with the given message and nested Exception.
100 *
101 * @param message the detail message for this Exception
102 * @param exception the nested exception
103 */
104 public XMLException(final String message, final Throwable exception) {
105 super(message, exception);
106 }
107
108 /**
109 * Creates a new XMLException with the given message, nested Exception, and errorCode.
110 *
111 * @param message the detail message for this exception
112 * @param exception the nested exception
113 * @param errorCode the errorCode for this Exception
114 *
115 * @deprecated
116 */
117 public XMLException(final String message, final Throwable exception, final int errorCode) {
118 super(message, exception);
119 this.errorCode = errorCode;
120 }
121
122 /**
123 * Sets the location information for this Exception.
124 *
125 * @param location The location information for this validation exception.
126 */
127 public void setLocation(final Location location) {
128 _location = location;
129 }
130
131 /**
132 * Returns the String representation of this Exception.
133 *
134 * @return the String representation of this Exception.
135 */
136 public String toString() {
137 StringBuilder buff = new StringBuilder(this.getClass().getName());
138
139 String msg = this.getMessage();
140 if (msg != null) {
141 buff.append(": ").append(msg);
142 }
143
144 if (this._location != null) {
145 buff.append('{').append(this._location).append('}');
146 }
147
148 return buff.toString();
149 }
150
151 /**
152 * Returns the error code for this Exception, or -1 if no error code exists.
153 *
154 * @return the error code for this Exception, or -1 if no error code exists
155 */
156 public int getErrorCode() {
157 return errorCode;
158 }
159
160 /**
161 * Sets the error code for this Exception.
162 *
163 * @param errorCode the error code
164 */
165 public void setErrorCode(final int errorCode) {
166 this.errorCode = errorCode;
167 }
168
169 }