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