KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > RepositoryException


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper;
24
25 import org.xquark.xml.xdbc.XMLDBCException;
26 /**
27  * XMLCollection application exception that can encapsulate an original exception,
28  * for instance, a SQLException
29  *
30  */

31 public class RepositoryException extends XMLDBCException
32 {
33 private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
34 private static final String JavaDoc RCSName = "$Name: $";
35     // COMMENT IT SEEMS NOT SO COOL TO MAINTAIN MESSAGES TWO TIMES (here with comments and with constructor...)
36

37     public static final int PERMISSION_DENIED = 2;
38     /** Access denied */
39     public static final int ACCESS_REFUSED = 3;
40     /** Object already used in repository */
41     public static final int ALREADY_EXISTS = 4;
42     /** A failure occured with the SAX parser */
43     public static final int PARSER_ERROR = 5;
44     /** The data mapped in the rdbms is incoherent */
45     public static final int CONSISTENCY_ERROR = 6;
46         /** A SAX handling exception thrown by the output SAX Handler */
47         public static final int SAX_OUTPUT_ERROR = 7;
48         /** Data that should have been saved to database couldn't */
49         public static final int DATA_LOSS = 8;
50         /** Extra data loss (PI, Comment) */
51         public static final int EXTRA_DATA_LOSS = 9;
52         /** Object does not exists in repository */
53         public static final int NOT_EXISTS = 10;
54         /** A paramater passed to the repository API is not allowed */
55         public static final int ILLEGAL_EXPRESSION = 11;
56         /** The function is not supported yet */
57         public static final int NOT_IMPLEMENTED = 12;
58         /** This action is not allowed */
59         public static final short NOT_ALLOWED = 13;
60         /** The user database was found inconsistent : for instance some data that is to be fetched is missing */
61         public static final int DB_CONSISTENCY_ERROR = 14;
62         /** An internal error occured */
63         public static final int INTERNAL_ERROR = 15;
64         /** A system error like an IO error */
65         public static final int SYSTEM_ERROR = 16;
66         /** The metadata information for mapping is incoherent */
67         public static final int MAPPING_CONSISTENCY_ERROR = 17;
68         /** Error while XQuark XMLCollection was retrieving configuration information */
69         public static final int XQUARK_CONF = 18;
70         /** RDBMS raised a non-fatal error (e.g. a statement couldn't be closed) */
71         public static final int DB_WARNING = 19;
72         /** XML schema unconsistency */
73         public static final int SCHEMA_ERROR = 20;
74         /** The underlying database is not initialized by the repository */
75         public static final int NO_INIT = 21;
76         /** Attemp to modify read-only data */
77         public static final int READ_ONLY = 22;
78         /** Action interrupted by user */
79         public static final int USER_ABORT = 23;
80         /** RDBMS raised an error for no reason explicable by the application */
81         public static final int DB_ERROR = 24;
82         /** The value is out of repository bounds. Maybe space for resource is exhausted */
83         public static final int OUT_OF_RANGE = 25;
84         
85         /** Constructor.
86          * @param code the code featuring the kind of error
87          * (see RepositoryException constants).
88          * @param message A litteral message bringing precisions on the error.
89          */

90         public RepositoryException(int code, String JavaDoc message)
91         {
92             super(code, message);
93         }
94         
95         /** Constructor for application exceptions encapsulating an underlying exception.
96          * @param code the code featuring the kind of error
97          * (see RepositoryException constants).
98          * @param message A litteral message bringing precisions on the error.
99          * @param underlyingException the original Exception that carried out this
100          * exception.
101          */

102         public RepositoryException(int code, String JavaDoc message, Throwable JavaDoc underlyingException)
103         {
104             super(code, message, underlyingException);
105         }
106
107         /** Returns a String describing the Exception and the underlying
108          * exception if any.
109          * @return a printable string.
110          */

111         public String JavaDoc toString() // TO RETROFIT 1.0? (change from getMessage to toString)
112
{
113             String JavaDoc message = "XQuark Storage exception : " + super.getMessage();
114             if ((exception != null) &&
115                 ((errorCode == DB_ERROR) || (errorCode == PARSER_ERROR)
116                 || (errorCode == SAX_OUTPUT_ERROR) || (errorCode == SYSTEM_ERROR)))
117                 message += "\nUnderlying exception : " + exception.getMessage();
118             return message;
119         }
120        
121         /** Prints the stack of the Exception or the underlying one if existing
122          */

123         public void printStackTrace()
124         {
125             if (exception != null)
126                 exception.printStackTrace();
127             else
128                 super.printStackTrace();
129         }
130 }
131
Popular Tags