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 java.math.BigDecimal;
19: import java.math.BigInteger;
20:
21: import org.springframework.binding.format.support.SimpleFormatterFactory;
22: import org.springframework.core.enums.LabeledEnum;
23:
24: /**
25: * Default, local implementation of a conversion service. Will automatically
26: * register <i>from string</i> converters for a number of standard Java
27: * types like Class, Number, Boolean and so on.
28: *
29: * @author Keith Donald
30: */
31: public class DefaultConversionService extends GenericConversionService {
32:
33: /**
34: * Creates a new default conversion service, installing the default
35: * converters.
36: */
37: public DefaultConversionService() {
38: addDefaultConverters();
39: }
40:
41: /**
42: * Add all default converters to the conversion service.
43: */
44: protected void addDefaultConverters() {
45: addConverter(new TextToClass());
46: addConverter(new TextToNumber(new SimpleFormatterFactory()));
47: addConverter(new TextToBoolean());
48: addConverter(new TextToLabeledEnum());
49:
50: // we're not using addDefaultAlias here for efficiency reasons
51: addAlias("string", String.class);
52: addAlias("short", Short.class);
53: addAlias("integer", Integer.class);
54: addAlias("int", Integer.class);
55: addAlias("byte", Byte.class);
56: addAlias("long", Long.class);
57: addAlias("float", Float.class);
58: addAlias("double", Double.class);
59: addAlias("bigInteger", BigInteger.class);
60: addAlias("bigDecimal", BigDecimal.class);
61: addAlias("boolean", Boolean.class);
62: addAlias("class", Class.class);
63: addAlias("labeledEnum", LabeledEnum.class);
64: }
65: }
|