01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 convertIfNecessary(Object value, Class requiredType)
48: throws TypeMismatchException;
49:
50: /**
51: * Convert the value to the required type (if necessary from a String).
52: * <p>Conversions from String to any type will typically use the <code>setAsText</code>
53: * method of the PropertyEditor class. Note that a PropertyEditor must be registered
54: * for the given class for this to work; this is a standard JavaBeans API.
55: * A number of PropertyEditors are automatically registered.
56: * @param value the value to convert
57: * @param requiredType the type we must convert to
58: * (or <code>null</code> if not known, for example in case of a collection element)
59: * @param methodParam the method parameter that is the target of the conversion
60: * (for analysis of generic types; may be <code>null</code>)
61: * @return the new value, possibly the result of type conversion
62: * @throws TypeMismatchException if type conversion failed
63: * @see java.beans.PropertyEditor#setAsText(String)
64: * @see java.beans.PropertyEditor#getValue()
65: */
66: Object convertIfNecessary(Object value, Class requiredType,
67: MethodParameter methodParam) throws TypeMismatchException;
68:
69: }
|