001/*
002 * Copyright 2002-2018 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;
018
019import java.lang.annotation.Annotation;
020
021import org.springframework.core.convert.converter.ConverterRegistry;
022
023/**
024 * A registry of field formatting logic.
025 *
026 * @author Keith Donald
027 * @author Juergen Hoeller
028 * @since 3.0
029 */
030public interface FormatterRegistry extends ConverterRegistry {
031
032        /**
033         * Adds a Printer to print fields of a specific type.
034         * The field type is implied by the parameterized Printer instance.
035         * @param printer the printer to add
036         * @since 5.2
037         * @see #addFormatter(Formatter)
038         */
039        void addPrinter(Printer<?> printer);
040
041        /**
042         * Adds a Parser to parse fields of a specific type.
043         * The field type is implied by the parameterized Parser instance.
044         * @param parser the parser to add
045         * @since 5.2
046         * @see #addFormatter(Formatter)
047         */
048        void addParser(Parser<?> parser);
049
050        /**
051         * Adds a Formatter to format fields of a specific type.
052         * The field type is implied by the parameterized Formatter instance.
053         * @param formatter the formatter to add
054         * @since 3.1
055         * @see #addFormatterForFieldType(Class, Formatter)
056         */
057        void addFormatter(Formatter<?> formatter);
058
059        /**
060         * Adds a Formatter to format fields of the given type.
061         * <p>On print, if the Formatter's type T is declared and {@code fieldType} is not assignable to T,
062         * a coercion to T will be attempted before delegating to {@code formatter} to print a field value.
063         * On parse, if the parsed object returned by {@code formatter} is not assignable to the runtime field type,
064         * a coercion to the field type will be attempted before returning the parsed field value.
065         * @param fieldType the field type to format
066         * @param formatter the formatter to add
067         */
068        void addFormatterForFieldType(Class<?> fieldType, Formatter<?> formatter);
069
070        /**
071         * Adds a Printer/Parser pair to format fields of a specific type.
072         * The formatter will delegate to the specified {@code printer} for printing
073         * and the specified {@code parser} for parsing.
074         * <p>On print, if the Printer's type T is declared and {@code fieldType} is not assignable to T,
075         * a coercion to T will be attempted before delegating to {@code printer} to print a field value.
076         * On parse, if the object returned by the Parser is not assignable to the runtime field type,
077         * a coercion to the field type will be attempted before returning the parsed field value.
078         * @param fieldType the field type to format
079         * @param printer the printing part of the formatter
080         * @param parser the parsing part of the formatter
081         */
082        void addFormatterForFieldType(Class<?> fieldType, Printer<?> printer, Parser<?> parser);
083
084        /**
085         * Adds a Formatter to format fields annotated with a specific format annotation.
086         * @param annotationFormatterFactory the annotation formatter factory to add
087         */
088        void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory);
089
090}