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 org.joda.time.format.DateTimeFormatter; 020 021import org.springframework.beans.factory.FactoryBean; 022import org.springframework.beans.factory.InitializingBean; 023 024/** 025 * {@link FactoryBean} that creates a Joda-Time {@link DateTimeFormatter}. 026 * See the {@link DateTimeFormatterFactory base class} for configuration details. 027 * 028 * @author Phillip Webb 029 * @author Sam Brannen 030 * @since 3.2 031 * @see #setPattern 032 * @see #setIso 033 * @see #setStyle 034 * @see DateTimeFormatterFactory 035 */ 036public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory 037 implements FactoryBean<DateTimeFormatter>, InitializingBean { 038 039 private DateTimeFormatter dateTimeFormatter; 040 041 042 @Override 043 public void afterPropertiesSet() { 044 this.dateTimeFormatter = createDateTimeFormatter(); 045 } 046 047 @Override 048 public DateTimeFormatter getObject() { 049 return this.dateTimeFormatter; 050 } 051 052 @Override 053 public Class<?> getObjectType() { 054 return DateTimeFormatter.class; 055 } 056 057 @Override 058 public boolean isSingleton() { 059 return true; 060 } 061 062}