01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.converter;
16:
17: import org.strecks.exceptions.ConversionException;
18:
19: /**
20: * Defines interface for converting from a String to an Object (which can be bound to a richly typed property in a
21: * domain class). Converters are typically one of two types:
22: * <ul>
23: * <li><b>Generic</b> converters which use an underlying conversion library (e.g. Commons BeanUtils or OGNL) to
24: * perform conversion</li>
25: * <li><b>Specific</b> converters which apply a custom conversion
26: * </ul>
27: * @author Phil Zoio
28: */
29: public interface Converter<S extends Object, T extends Object> {
30:
31: /**
32: * Identifies the target class for the conversion. For <i>generic</i> converters this may be used by the conversion
33: * library to determine the target type for the conversion. For <i>specific</i> converters this will typically just
34: * to apply a runtime check to ensure that the passed in object in <code>convertToString()</code> is of the
35: * correct type
36: */
37: public void setTargetClass(Class clazz);
38:
39: /**
40: * Converts from a String to an object, which can be bound as a property of a richly typed domain class
41: */
42: public T toTargetType(S toConvert) throws ConversionException;
43:
44: /**
45: * Performs reverse of <code>convertToObject()</code>: returns the original type representation of the object,
46: * typically used as the value which will appear as a form input field
47: */
48: public S toSourceType(T toConvert) throws ConversionException;
49: }
|