Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SqlTimeConverter |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2009 the Seasar Foundation and the Others. | |
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, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.cubby.converter.impl; | |
17 | ||
18 | import java.util.Date; | |
19 | ||
20 | import org.seasar.cubby.converter.ConversionException; | |
21 | import org.seasar.cubby.converter.ConversionHelper; | |
22 | ||
23 | /** | |
24 | * {@link java.sql.Time}への変換を行うコンバータです。 | |
25 | * <p> | |
26 | * 変換元のオブジェクトの文字列表現をフォーマットに従って{@link java.sql.Time}に変換した結果を変換先とします。 | |
27 | * </p> | |
28 | * | |
29 | * @author baba | |
30 | * @since 1.1.0 | |
31 | */ | |
32 | 57 | public class SqlTimeConverter extends AbstractDateConverter { |
33 | ||
34 | /** | |
35 | * {@inheritDoc} | |
36 | */ | |
37 | public Class<?> getObjectType() { | |
38 | 447 | return java.sql.Time.class; |
39 | } | |
40 | ||
41 | /** | |
42 | * {@inheritDoc} | |
43 | */ | |
44 | public Object convertToObject(final Object value, | |
45 | final Class<?> objectType, final ConversionHelper helper) | |
46 | throws ConversionException { | |
47 | 18 | if (value == null) { |
48 | 0 | return null; |
49 | } | |
50 | 18 | final String pattern = helper.getFormatPattern().getTimePattern(); |
51 | 18 | final Date date = toDate(value.toString(), pattern); |
52 | 12 | return new java.sql.Time(date.getTime()); |
53 | } | |
54 | ||
55 | /** | |
56 | * {@inheritDoc} | |
57 | */ | |
58 | public String convertToString(final Object value, | |
59 | final ConversionHelper helper) { | |
60 | 0 | if (value == null) { |
61 | 0 | return null; |
62 | } | |
63 | 0 | final String pattern = helper.getFormatPattern().getTimePattern(); |
64 | 0 | return toString((java.sql.Time) value, pattern); |
65 | } | |
66 | ||
67 | } |