001/*
002 * Copyright 2002-2014 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 Formatter to format fields of a specific type.
034         * The field type is implied by the parameterized Formatter instance.
035         * @param formatter the formatter to add
036         * @see #addFormatterForFieldType(Class, Formatter)
037         * @since 3.1
038         */
039        void addFormatter(Formatter<?> formatter);
040
041        /**
042         * Adds a Formatter to format fields of the given type.
043         * <p>On print, if the Formatter's type T is declared and {@code fieldType} is not assignable to T,
044         * a coercion to T will be attempted before delegating to {@code formatter} to print a field value.
045         * On parse, if the parsed object returned by {@code formatter} is not assignable to the runtime field type,
046         * a coercion to the field type will be attempted before returning the parsed field value.
047         * @param fieldType the field type to format
048         * @param formatter the formatter to add
049         */
050        void addFormatterForFieldType(Class<?> fieldType, Formatter<?> formatter);
051
052        /**
053         * Adds a Printer/Parser pair to format fields of a specific type.
054         * The formatter will delegate to the specified {@code printer} for printing
055         * and the specified {@code parser} for parsing.
056         * <p>On print, if the Printer's type T is declared and {@code fieldType} is not assignable to T,
057         * a coercion to T will be attempted before delegating to {@code printer} to print a field value.
058         * On parse, if the object returned by the Parser is not assignable to the runtime field type,
059         * a coercion to the field type will be attempted before returning the parsed field value.
060         * @param fieldType the field type to format
061         * @param printer the printing part of the formatter
062         * @param parser the parsing part of the formatter
063         */
064        void addFormatterForFieldType(Class<?> fieldType, Printer<?> printer, Parser<?> parser);
065
066        /**
067         * Adds a Formatter to format fields annotated with a specific format annotation.
068         * @param annotationFormatterFactory the annotation formatter factory to add
069         */
070        void addFormatterForFieldAnnotation(AnnotationFormatterFactory<? extends Annotation> annotationFormatterFactory);
071
072}