KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > RDFException


1 /*
2     (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3     [See end of file]
4     $Id: RDFException.java,v 1.13 2005/02/21 12:14:21 andy_seaborne Exp $
5  */

6
7 package com.hp.hpl.jena.rdf.model;
8
9 import com.hp.hpl.jena.shared.*;
10
11 /** LEGACY Generic RDF Exception class. This class is preserved to allow
12  * users moving from Jena 1 to Jena 2 to continue to use the magic numbers
13  * for Jena exceptions. The codebase no longer uses these numbers directly,
14  * but instead uses particular Jena exceptions. Those exceptions presently
15  * subclass RDFException and set the magic numbers, but This Will Change.
16  * @author bwm
17  * @version $Name: $ $Revision: 1.13 $ $Date: 2005/02/21 12:14:21 $
18  */

19 public class RDFException extends JenaException {
20     
21     protected int errorCode = 0;
22     protected int otherCode = 0;
23     protected Exception JavaDoc nestedException = null;
24     protected String JavaDoc message = null;
25
26     /** A method which would access a model has been invoked on an object
27      * with no associated model.
28      */

29     public static final int NOTRELATEDTOMODEL = 1;
30     /** The URI supplied for a Property is invalid.
31      */

32     public static final int INVALIDPROPERTYURI = 2;
33     /** A method which is unsupported has been called.
34      */

35     public static final int UNSUPPORTEDOPERATION = 3;
36     /** The object of a statement is not a Resource.
37      */

38     public static final int OBJECTNOTRESOURCE = 4;
39     /** The object of a Statement is not a Literal.
40      */

41     public static final int OBJECTNOTLITERAL = 5;
42     /** A property was not found in the model.
43      */

44     public static final int PROPERTYNOTFOUND = 6;
45     /** The resource is no anonymous.
46      */

47     public static final int NOTANONRESOURCE = 7;
48     /** The iterator is closed.
49      */

50     public static final int ITERATORCLOSED = 8;
51     /** The error code is invalid.
52      */

53     public static final int INVALIDERRORCODE = 9;
54     /** This exception contains another which has been caught and encapsulated as
55      * an RDF exception.
56      */

57     public static final int NESTEDEXCEPTION = 10;
58     /** A literal did not represent a boolean value.
59      */

60     public static final int INVALIDBOOLEANFORMAT = 11;
61     /** A literal did not contain a valid char.
62      */

63     public static final int LITERALNOTCHAR = 12;
64     /** An Alt resource has no default value.
65      */

66     public static final int ALTHASNODEFAULT = 13;
67     /** An application supplied Selector has raised an exception, which is
68      * encapsulated in this exception.
69      */

70     public static final int SELECTOREXCEPTION = 14;
71     /** The object of a statement is not of the expected type.
72      */

73     public static final int OBJECTWRONGTYPE = 15;
74     /** A required element does not exist.
75      */

76     public static final int NOSUCHELEMENT = 16;
77     /** Internal Error - an assertion has failed.
78      */

79     public static final int ASSERTIONFAILURE = 17;
80     /** A sequence index is out of the valid range for that sequence.
81      */

82     public static final int SEQINDEXBOUNDS = 18;
83     /** An enhanced resource does not have a constructor of the form
84         foo(Resource r)
85      */

86     public static final int NORESOURCECONSTRUCTOR = 19;
87
88 /** No reader is know for that lanaguage
89  */

90     public static final int NOREADERFORLANG = 20;
91     
92 /** No Writer is known for that language
93  */

94     public static final int NOWRITERFORLANG = 21;
95     
96 /** Unknown Property
97  */

98     public static final int UNKNOWNPROPERTY = 22;
99
100 /** Statement not present
101  */

102     public static final int STATEMENTNOTPRESENT = 23;
103     
104 /** Syntax Errors in input stream
105  */

106     public static final int SYNTAXERROR = 24;
107     
108     protected static final int MAXERRORCODE = 24;
109
110     protected static final String JavaDoc[] errorMessage =
111         { "not used",
112           "Object is not related to a model",
113           "Invalid property URI",
114           "Unsupported operation",
115           "Object of statement is not a resource",
116           "Object of statement is not a literal",
117           "Subject does not have that property",
118           "Resource is not anonymous",
119           "Iterator has been closed",
120           "Invalid error code",
121           "Nested Exception",
122           "Literal is not a boolean",
123           "Literal is not a single character",
124           "Alt container has no default",
125           "Selector threw exception",
126           "Statement object does match requested type",
127           "Iterator does not have an element",
128           "Assertion failure",
129           "Sequence index out of range",
130           "Enhanced Resource lacks Resource constructor",
131           "No RDFReader is defined for that language",
132           "No RDFWriter is defined for that lanaguage",
133           "Property not known",
134           "Statement not present",
135           "Syntax errors in input stream"
136         };
137         
138         protected RDFException(){}
139     
140     /** Create an RDF exception with the given error code.
141      * @param errorCode The code number of the error which has occurred.
142      */

143     public RDFException(int errorCode) {
144         if (1<=errorCode && errorCode<=MAXERRORCODE) {
145             this.errorCode = errorCode;
146         } else {
147             this.errorCode = INVALIDERRORCODE;
148             this.otherCode = errorCode;
149         }
150         message = errorMessage[this.errorCode];
151     }
152     
153     /** Encapsulate an exception in an RDFException.
154      * @param e The exception to be encapsulated.
155      */

156     
157     public RDFException(Exception JavaDoc e) {
158         this.errorCode = NESTEDEXCEPTION;
159         this.message = errorMessage[this.errorCode];
160         nestedException = e;
161     }
162
163     /** Create a new RDFException with a given error code and message
164      * @param errorCode The code number of the error which has occurred.
165      * @param message The message associated with the error
166      */

167     
168     public RDFException(int errorCode, String JavaDoc message) {
169         this.errorCode = errorCode;
170         this.message = message;
171     }
172     
173     public RDFException(String JavaDoc s) {
174         super(s); this.message = s;
175     }
176
177
178     /** Return an error message describing the exception.
179      * @return the error message
180      */

181     public String JavaDoc toString() {
182         String JavaDoc m = getMessage(), name = this.getClass().getName();
183         return m == null ? name : name + ": " + m;
184     }
185     
186     public String JavaDoc getMessage() {
187         String JavaDoc result = Integer.toString(errorCode) + " " + this.message;
188         if (errorCode == INVALIDERRORCODE) {
189             result = result + " = " + Integer.toString(otherCode);
190         } else if (errorCode == NESTEDEXCEPTION
191                 || errorCode == SELECTOREXCEPTION) {
192             result = this.message + " = " + nestedException.toString();
193         }
194         return result;
195     }
196     
197     public int getErrorCode() {
198         return errorCode;
199     }
200     
201     /**
202         changed by Chris, because "use this if we haven't one" caused
203         a recursive failure of test cases that exported DoesNotReifyException.
204     */

205     public Throwable JavaDoc getCause() {
206         return nestedException ; // was: !=null?nestedException:this;
207
}
208     public Exception JavaDoc getNestedException() {
209         
210         return nestedException;
211     }
212 }
213 /*
214  * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
215  * All rights reserved.
216  *
217  * Redistribution and use in source and binary forms, with or without
218  * modification, are permitted provided that the following conditions
219  * are met:
220  * 1. Redistributions of source code must retain the above copyright
221  * notice, this list of conditions and the following disclaimer.
222  * 2. Redistributions in binary form must reproduce the above copyright
223  * notice, this list of conditions and the following disclaimer in the
224  * documentation and/or other materials provided with the distribution.
225  * 3. The name of the author may not be used to endorse or promote products
226  * derived from this software without specific prior written permission.
227
228  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
229  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
230  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
231  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
232  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
233  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
236  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
237  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
238  *
239  * $Id: RDFException.java,v 1.13 2005/02/21 12:14:21 andy_seaborne Exp $
240  *
241  * Created on 26 July 2000, 07:00
242  */

243
Popular Tags