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.Nullable;
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 */
037public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory
038                implements FactoryBean<DateTimeFormatter>, InitializingBean {
039
040        @Nullable
041        private DateTimeFormatter dateTimeFormatter;
042
043
044        @Override
045        public void afterPropertiesSet() {
046                this.dateTimeFormatter = createDateTimeFormatter();
047        }
048
049        @Override
050        @Nullable
051        public DateTimeFormatter getObject() {
052                return this.dateTimeFormatter;
053        }
054
055        @Override
056        public Class<?> getObjectType() {
057                return DateTimeFormatter.class;
058        }
059
060        @Override
061        public boolean isSingleton() {
062                return true;
063        }
064
065}