001/*
002 * Copyright 2002-2017 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.standard;
018
019import java.time.format.DateTimeFormatter;
020
021import org.springframework.beans.factory.FactoryBean;
022import org.springframework.beans.factory.InitializingBean;
023import org.springframework.lang.UsesJava8;
024
025/**
026 * {@link FactoryBean} that creates a JSR-310 {@link java.time.format.DateTimeFormatter}.
027 * See the {@link DateTimeFormatterFactory base class} for configuration details.
028 *
029 * @author Juergen Hoeller
030 * @since 4.0
031 * @see #setPattern
032 * @see #setIso
033 * @see #setDateStyle
034 * @see #setTimeStyle
035 * @see DateTimeFormatterFactory
036 */
037@UsesJava8
038public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory
039                implements FactoryBean<DateTimeFormatter>, InitializingBean {
040
041        private DateTimeFormatter dateTimeFormatter;
042
043
044        @Override
045        public void afterPropertiesSet() {
046                this.dateTimeFormatter = createDateTimeFormatter();
047        }
048
049        @Override
050        public DateTimeFormatter getObject() {
051                return this.dateTimeFormatter;
052        }
053
054        @Override
055        public Class<?> getObjectType() {
056                return DateTimeFormatter.class;
057        }
058
059        @Override
060        public boolean isSingleton() {
061                return true;
062        }
063
064}