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: import org.strecks.util.Assert;
19:
20: /**
21: * This is the default implementation of Converter which simply delegates to the registered Bean Utils converter using
22: * <code>BeanUtilsBean.getInstance().getConvertUtils().convert()</code>
23: * @author Phil Zoio
24: */
25: public class StandardBeanUtilsConverter implements
26: Converter<String, Object> {
27:
28: private Class clazz;
29:
30: public void setTargetClass(Class clazz) {
31: this .clazz = clazz;
32: }
33:
34: public Object toTargetType(String toConvert)
35: throws ConversionException {
36: Assert.notNull(clazz);
37:
38: if (toConvert == null)
39: return null;
40:
41: Object convert = null;
42: try {
43: convert = BeanUtilsConverter.getInstance().convert(
44: toConvert, clazz);
45: } catch (Exception e) {
46: throw new ConversionException(e);
47: }
48: return convert;
49: }
50:
51: public String toSourceType(Object toConvert)
52: throws ConversionException {
53: Assert.notNull(clazz);
54:
55: String convert = null;
56: try {
57: convert = BeanUtilsConverter.getInstance().convert(
58: toConvert);
59: } catch (Exception e) {
60: throw new ConversionException(e);
61: }
62: return convert;
63: }
64:
65: }
|