KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > ObjectRetrievalFailureException


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm;
18
19 import org.springframework.dao.DataRetrievalFailureException;
20
21 /**
22  * Exception thrown if a mapped object could not be retrieved via its identifier.
23  * Provides information about the persistent class and the identifier.
24  *
25  * @author Juergen Hoeller
26  * @since 13.10.2003
27  */

28 public class ObjectRetrievalFailureException extends DataRetrievalFailureException {
29
30     private Object JavaDoc persistentClass;
31
32     private Object JavaDoc identifier;
33
34
35     /**
36      * Create a general ObjectRetrievalFailureException with the given message,
37      * without any information on the affected object.
38      * @param msg the detail message
39      * @param cause the source exception
40      */

41     public ObjectRetrievalFailureException(String JavaDoc msg, Throwable JavaDoc cause) {
42         super(msg, cause);
43     }
44
45     /**
46      * Create a new ObjectRetrievalFailureException for the given object,
47      * with the default "not found" message.
48      * @param persistentClass the persistent class
49      * @param identifier the ID of the object that should have been retrieved
50      */

51     public ObjectRetrievalFailureException(Class JavaDoc persistentClass, Object JavaDoc identifier) {
52         this(persistentClass, identifier,
53                 "Object of class [" + persistentClass.getName() + "] with identifier [" + identifier + "]: not found",
54                 null);
55     }
56
57     /**
58      * Create a new ObjectRetrievalFailureException for the given object,
59      * with the given explicit message and exception.
60      * @param persistentClass the persistent class
61      * @param identifier the ID of the object that should have been retrieved
62      * @param msg the detail message
63      * @param cause the source exception
64      */

65     public ObjectRetrievalFailureException(
66             Class JavaDoc persistentClass, Object JavaDoc identifier, String JavaDoc msg, Throwable JavaDoc cause) {
67
68         super(msg, cause);
69         this.persistentClass = persistentClass;
70         this.identifier = identifier;
71     }
72
73     /**
74      * Create a new ObjectRetrievalFailureException for the given object,
75      * with the default "not found" message.
76      * @param persistentClassName the name of the persistent class
77      * @param identifier the ID of the object that should have been retrieved
78      */

79     public ObjectRetrievalFailureException(String JavaDoc persistentClassName, Object JavaDoc identifier) {
80         this(persistentClassName, identifier,
81                 "Object of class [" + persistentClassName + "] with identifier [" + identifier + "]: not found",
82                 null);
83     }
84
85     /**
86      * Create a new ObjectRetrievalFailureException for the given object,
87      * with the given explicit message and exception.
88      * @param persistentClassName the name of the persistent class
89      * @param identifier the ID of the object that should have been retrieved
90      * @param msg the detail message
91      * @param cause the source exception
92      */

93     public ObjectRetrievalFailureException(
94             String JavaDoc persistentClassName, Object JavaDoc identifier, String JavaDoc msg, Throwable JavaDoc cause) {
95
96         super(msg, cause);
97         this.persistentClass = persistentClassName;
98         this.identifier = identifier;
99     }
100
101
102     /**
103      * Return the persistent class of the object that was not found.
104      * If no Class was specified, this method returns null.
105      */

106     public Class JavaDoc getPersistentClass() {
107         return (this.persistentClass instanceof Class JavaDoc ? (Class JavaDoc) this.persistentClass : null);
108     }
109
110     /**
111      * Return the name of the persistent class of the object that was not found.
112      * Will work for both Class objects and String names.
113      */

114     public String JavaDoc getPersistentClassName() {
115         if (this.persistentClass instanceof Class JavaDoc) {
116             return ((Class JavaDoc) this.persistentClass).getName();
117         }
118         return (this.persistentClass != null ? this.persistentClass.toString() : null);
119     }
120
121     /**
122      * Return the identifier of the object that was not found.
123      */

124     public Object JavaDoc getIdentifier() {
125         return identifier;
126     }
127
128 }
129
Popular Tags