org.springframework.format.FormatterRegistrar Java Examples

The following examples show how to use org.springframework.format.FormatterRegistrar. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormattingConversionServiceFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void registerFormatters(FormattingConversionService conversionService) {
	if (this.formatters != null) {
		for (Object formatter : this.formatters) {
			if (formatter instanceof Formatter<?>) {
				conversionService.addFormatter((Formatter<?>) formatter);
			}
			else if (formatter instanceof AnnotationFormatterFactory<?>) {
				conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
			}
			else {
				throw new IllegalArgumentException(
						"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
			}
		}
	}
	if (this.formatterRegistrars != null) {
		for (FormatterRegistrar registrar : this.formatterRegistrars) {
			registrar.registerFormatters(conversionService);
		}
	}
}
 
Example #2
Source File: FormattingConversionServiceFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void registerFormatters(FormattingConversionService conversionService) {
	if (this.formatters != null) {
		for (Object formatter : this.formatters) {
			if (formatter instanceof Formatter<?>) {
				conversionService.addFormatter((Formatter<?>) formatter);
			}
			else if (formatter instanceof AnnotationFormatterFactory<?>) {
				conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
			}
			else {
				throw new IllegalArgumentException(
						"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
			}
		}
	}
	if (this.formatterRegistrars != null) {
		for (FormatterRegistrar registrar : this.formatterRegistrars) {
			registrar.registerFormatters(conversionService);
		}
	}
}
 
Example #3
Source File: FormattingConversionServiceFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void registerFormatters() {
	if (this.formatters != null) {
		for (Object formatter : this.formatters) {
			if (formatter instanceof Formatter<?>) {
				this.conversionService.addFormatter((Formatter<?>) formatter);
			}
			else if (formatter instanceof AnnotationFormatterFactory<?>) {
				this.conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
			}
			else {
				throw new IllegalArgumentException(
						"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
			}
		}
	}
	if (this.formatterRegistrars != null) {
		for (FormatterRegistrar registrar : this.formatterRegistrars) {
			registrar.registerFormatters(this.conversionService);
		}
	}
}
 
Example #4
Source File: FormattingConversionServiceFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void registerFormatters() {
	if (this.formatters != null) {
		for (Object formatter : this.formatters) {
			if (formatter instanceof Formatter<?>) {
				this.conversionService.addFormatter((Formatter<?>) formatter);
			}
			else if (formatter instanceof AnnotationFormatterFactory<?>) {
				this.conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
			}
			else {
				throw new IllegalArgumentException(
						"Custom formatters must be implementations of Formatter or AnnotationFormatterFactory");
			}
		}
	}
	if (this.formatterRegistrars != null) {
		for (FormatterRegistrar registrar : this.formatterRegistrars) {
			registrar.registerFormatters(this.conversionService);
		}
	}
}
 
Example #5
Source File: FormattingConversionServiceFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testFormatterRegistrar() throws Exception {
	FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
	Set<FormatterRegistrar> registrars = new HashSet<>();
	registrars.add(new TestFormatterRegistrar());
	factory.setFormatterRegistrars(registrars);
	factory.afterPropertiesSet();
	FormattingConversionService fcs = factory.getObject();

	TestBean testBean = fcs.convert("5", TestBean.class);
	assertEquals(5, testBean.getSpecialInt());
	assertEquals("5", fcs.convert(testBean, String.class));
}
 
Example #6
Source File: FormattingConversionServiceFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testFormatterRegistrar() throws Exception {
	FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
	Set<FormatterRegistrar> registrars = new HashSet<>();
	registrars.add(new TestFormatterRegistrar());
	factory.setFormatterRegistrars(registrars);
	factory.afterPropertiesSet();
	FormattingConversionService fcs = factory.getObject();

	TestBean testBean = fcs.convert("5", TestBean.class);
	assertEquals(5, testBean.getSpecialInt());
	assertEquals("5", fcs.convert(testBean, String.class));
}
 
Example #7
Source File: FormattingConversionServiceFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormatterRegistrar() throws Exception {
	FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
	Set<FormatterRegistrar> registrars = new HashSet<FormatterRegistrar>();
	registrars.add(new TestFormatterRegistrar());
	factory.setFormatterRegistrars(registrars);
	factory.afterPropertiesSet();
	FormattingConversionService fcs = factory.getObject();

	TestBean testBean = fcs.convert("5", TestBean.class);
	assertEquals(5, testBean.getSpecialInt());
	assertEquals("5", fcs.convert(testBean, String.class));
}
 
Example #8
Source File: DateTimeConverter.java    From DCMonitor with MIT License 5 votes vote down vote up
@Bean
FormattingConversionServiceFactoryBean conversionService() {
  FormattingConversionServiceFactoryBean bean = new FormattingConversionServiceFactoryBean();
  Set<FormatterRegistrar> set = new HashSet<FormatterRegistrar>();
  JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
  registrar.setUseIsoFormat(true);
  set.add(registrar);
  bean.setFormatterRegistrars(set);
  return bean;
}
 
Example #9
Source File: FormattingConversionServiceFactoryBean.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * <p>Configure the set of FormatterRegistrars to invoke to register
 * Converters and Formatters in addition to those added declaratively
 * via {@link #setConverters(Set)} and {@link #setFormatters(Set)}.
 * <p>FormatterRegistrars are useful when registering multiple related
 * converters and formatters for a formatting category, such as Date
 * formatting. All types related needed to support the formatting
 * category can be registered from one place.
 * <p>FormatterRegistrars can also be used to register Formatters
 * indexed under a specific field type different from its own &lt;T&gt;,
 * or when registering a Formatter from a Printer/Parser pair.
 * @see FormatterRegistry#addFormatterForFieldType(Class, Formatter)
 * @see FormatterRegistry#addFormatterForFieldType(Class, Printer, Parser)
 */
public void setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars) {
	this.formatterRegistrars = formatterRegistrars;
}
 
Example #10
Source File: FormattingConversionServiceFactoryBean.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * <p>Configure the set of FormatterRegistrars to invoke to register
 * Converters and Formatters in addition to those added declaratively
 * via {@link #setConverters(Set)} and {@link #setFormatters(Set)}.
 * <p>FormatterRegistrars are useful when registering multiple related
 * converters and formatters for a formatting category, such as Date
 * formatting. All types related needed to support the formatting
 * category can be registered from one place.
 * <p>FormatterRegistrars can also be used to register Formatters
 * indexed under a specific field type different from its own &lt;T&gt;,
 * or when registering a Formatter from a Printer/Parser pair.
 * @see FormatterRegistry#addFormatterForFieldType(Class, Formatter)
 * @see FormatterRegistry#addFormatterForFieldType(Class, Printer, Parser)
 */
public void setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars) {
	this.formatterRegistrars = formatterRegistrars;
}
 
Example #11
Source File: FormattingConversionServiceFactoryBean.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * <p>Configure the set of FormatterRegistrars to invoke to register
 * Converters and Formatters in addition to those added declaratively
 * via {@link #setConverters(Set)} and {@link #setFormatters(Set)}.
 * <p>FormatterRegistrars are useful when registering multiple related
 * converters and formatters for a formatting category, such as Date
 * formatting. All types related needed to support the formatting
 * category can be registered from one place.
 * <p>FormatterRegistrars can also be used to register Formatters
 * indexed under a specific field type different from its own &lt;T&gt;,
 * or when registering a Formatter from a Printer/Parser pair.
 * @see FormatterRegistry#addFormatterForFieldType(Class, Formatter)
 * @see FormatterRegistry#addFormatterForFieldType(Class, Printer, Parser)
 */
public void setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars) {
	this.formatterRegistrars = formatterRegistrars;
}
 
Example #12
Source File: FormattingConversionServiceFactoryBean.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * <p>Configure the set of FormatterRegistrars to invoke to register
 * Converters and Formatters in addition to those added declaratively
 * via {@link #setConverters(Set)} and {@link #setFormatters(Set)}.
 * <p>FormatterRegistrars are useful when registering multiple related
 * converters and formatters for a formatting category, such as Date
 * formatting. All types related needed to support the formatting
 * category can be registered from one place.
 * <p>FormatterRegistrars can also be used to register Formatters
 * indexed under a specific field type different from its own &lt;T&gt;,
 * or when registering a Formatter from a Printer/Parser pair.
 * @see FormatterRegistry#addFormatterForFieldType(Class, Formatter)
 * @see FormatterRegistry#addFormatterForFieldType(Class, Printer, Parser)
 */
public void setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars) {
	this.formatterRegistrars = formatterRegistrars;
}