KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > convert > ConversionException


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 package org.springframework.binding.convert;
17
18 import org.springframework.core.NestedRuntimeException;
19
20 /**
21  * Base class for exceptions thrown by the type conversion system.
22  * @author Keith Donald
23  */

24 public class ConversionException extends NestedRuntimeException {
25
26     /**
27      * The value we tried to convert.
28      */

29     private Object JavaDoc value;
30
31     /**
32      * The target type we tried to convert to.
33      */

34     private Class JavaDoc targetClass;
35
36     /**
37      * Creates a new conversion exception.
38      * @param value
39      * @param targetClass
40      */

41     public ConversionException(Object JavaDoc value, Class JavaDoc targetClass) {
42         super("Unable to convert value '" + value + "' of type '" + (value != null ? value.getClass().getName() : null)
43                 + "' to class '" + targetClass.getName() + "'");
44         this.value = value;
45         this.targetClass = targetClass;
46     }
47
48     /**
49      * Creates a new conversion exception.
50      * @param value
51      * @param targetClass
52      * @param cause
53      */

54     public ConversionException(Object JavaDoc value, Class JavaDoc targetClass, Throwable JavaDoc cause) {
55         super("Unable to convert value '" + value + "' of type '" + (value != null ? value.getClass().getName() : null)
56                 + "' to class '" + targetClass.getName() + "'", cause);
57         this.value = value;
58         this.targetClass = targetClass;
59     }
60
61     /**
62      * Creates a new conversion exception.
63      * @param value
64      * @param targetClass
65      * @param cause
66      * @param message
67      */

68     public ConversionException(Object JavaDoc value, Class JavaDoc targetClass, Throwable JavaDoc cause, String JavaDoc message) {
69         super(message, cause);
70         this.value = value;
71         this.targetClass = targetClass;
72     }
73
74     /**
75      * Returns the source value
76      * @return the source value
77      */

78     public Object JavaDoc getValue() {
79         return value;
80     }
81
82     /**
83      * @return Returns the targetClass.
84      */

85     public Class JavaDoc getTargetClass() {
86         return targetClass;
87     }
88 }
Popular Tags