001/*
002 * Copyright 2002-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.format.datetime.joda;
018
019import java.text.ParseException;
020import java.util.Locale;
021
022import org.joda.time.LocalTime;
023import org.joda.time.format.DateTimeFormatter;
024
025import org.springframework.format.Parser;
026
027/**
028 * Parses Joda {@link org.joda.time.LocalTime} instances using a
029 * {@link org.joda.time.format.DateTimeFormatter}.
030 *
031 * @author Juergen Hoeller
032 * @since 4.0
033 */
034public final class LocalTimeParser implements Parser<LocalTime> {
035
036        private final DateTimeFormatter formatter;
037
038
039        /**
040         * Create a new DateTimeParser.
041         * @param formatter the Joda DateTimeFormatter instance
042         */
043        public LocalTimeParser(DateTimeFormatter formatter) {
044                this.formatter = formatter;
045        }
046
047
048        @Override
049        public LocalTime parse(String text, Locale locale) throws ParseException {
050                return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseLocalTime(text);
051        }
052
053}