KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > TypeConverter


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.beans;
18
19 import org.springframework.core.MethodParameter;
20
21 /**
22  * Interface that defines type conversion methods. Typically (but not necessarily)
23  * implemented in conjunction with the PropertyEditorRegistry interface.
24  *
25  * @author Juergen Hoeller
26  * @since 2.0
27  * @see PropertyEditorRegistry
28  * @see SimpleTypeConverter
29  * @see BeanWrapperImpl
30  */

31 public interface TypeConverter {
32
33     /**
34      * Convert the value to the required type (if necessary from a String).
35      * <p>Conversions from String to any type will typically use the <code>setAsText</code>
36      * method of the PropertyEditor class. Note that a PropertyEditor must be registered
37      * for the given class for this to work; this is a standard JavaBeans API.
38      * A number of PropertyEditors are automatically registered.
39      * @param value the value to convert
40      * @param requiredType the type we must convert to
41      * (or <code>null</code> if not known, for example in case of a collection element)
42      * @return the new value, possibly the result of type conversion
43      * @throws TypeMismatchException if type conversion failed
44      * @see java.beans.PropertyEditor#setAsText(String)
45      * @see java.beans.PropertyEditor#getValue()
46      */

47     Object JavaDoc convertIfNecessary(Object JavaDoc value, Class JavaDoc requiredType) throws TypeMismatchException;
48
49     /**
50      * Convert the value to the required type (if necessary from a String).
51      * <p>Conversions from String to any type will typically use the <code>setAsText</code>
52      * method of the PropertyEditor class. Note that a PropertyEditor must be registered
53      * for the given class for this to work; this is a standard JavaBeans API.
54      * A number of PropertyEditors are automatically registered.
55      * @param value the value to convert
56      * @param requiredType the type we must convert to
57      * (or <code>null</code> if not known, for example in case of a collection element)
58      * @param methodParam the method parameter that is the target of the conversion
59      * (for analysis of generic types; may be <code>null</code>)
60      * @return the new value, possibly the result of type conversion
61      * @throws TypeMismatchException if type conversion failed
62      * @see java.beans.PropertyEditor#setAsText(String)
63      * @see java.beans.PropertyEditor#getValue()
64      */

65     Object JavaDoc convertIfNecessary(Object JavaDoc value, Class JavaDoc requiredType, MethodParameter methodParam)
66             throws TypeMismatchException;
67
68 }
69
Popular Tags