01: /*
02: * Copyright 2004-2007 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: package org.springframework.binding.convert.support;
17:
18: import org.springframework.binding.convert.ConversionContext;
19: import org.springframework.binding.format.support.LabeledEnumFormatter;
20: import org.springframework.core.enums.LabeledEnum;
21:
22: /**
23: * Converter that converts textual representations of enum
24: * instances to a specific instance of <code>LabeledEnum</code>.
25: *
26: * @author Keith Donald
27: */
28: public class TextToLabeledEnum extends AbstractConverter {
29:
30: private LabeledEnumFormatter labeledEnumFormatter = new LabeledEnumFormatter();
31:
32: public Class[] getSourceClasses() {
33: return new Class[] { String.class };
34: }
35:
36: public Class[] getTargetClasses() {
37: return new Class[] { LabeledEnum.class };
38: }
39:
40: protected Object doConvert(Object source, Class targetClass,
41: ConversionContext context) throws Exception {
42: return labeledEnumFormatter.parseValue((String) source,
43: targetClass);
44: }
45: }
|