KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > format > support > SimpleFormatterFactory


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.format.support;
17
18 import java.text.NumberFormat JavaDoc;
19 import java.text.SimpleDateFormat JavaDoc;
20
21 import org.springframework.binding.format.Formatter;
22 import org.springframework.binding.format.Style;
23
24 /**
25  * FormatterLocator that caches Formatters in thread-local storage.
26  *
27  * @author Keith Donald
28  */

29 public class SimpleFormatterFactory extends AbstractFormatterFactory {
30
31     public SimpleFormatterFactory() {
32     }
33
34     public Formatter getDateFormatter(Style style) {
35         return new DateFormatter(SimpleDateFormat.getDateInstance(style.shortValue(), getLocale()));
36     }
37
38     public Formatter getDateTimeFormatter(Style dateStyle, Style timeStyle) {
39         return new DateFormatter(SimpleDateFormat.getDateTimeInstance(dateStyle.shortValue(), timeStyle.shortValue(),
40                 getLocale()));
41     }
42
43     public Formatter getTimeFormatter(Style style) {
44         return new DateFormatter(SimpleDateFormat.getTimeInstance(style.shortValue(), getLocale()));
45     }
46
47     public Formatter getNumberFormatter(Class JavaDoc numberClass) {
48         return new NumberFormatter(NumberFormat.getNumberInstance(getLocale()));
49     }
50
51     public Formatter getCurrencyFormatter() {
52         return new NumberFormatter(NumberFormat.getCurrencyInstance(getLocale()));
53     }
54
55     public Formatter getDateFormatter(String JavaDoc encodedFormat) {
56         return new DateFormatter(new SimpleDateFormat JavaDoc(encodedFormat));
57     }
58
59     public Formatter getPercentFormatter() {
60         return new NumberFormatter(NumberFormat.getPercentInstance(getLocale()));
61     }
62 }
Popular Tags