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.messaging.support;
018
019import org.springframework.messaging.MessageHeaders;
020
021/**
022 * Generic strategy interface for mapping {@link MessageHeaders} to and from other
023 * types of objects. This would typically be used by adapters where the "other type"
024 * has a concept of headers or properties (HTTP, JMS, AMQP, etc).
025 *
026 * @author Mark Fisher
027 * @since 4.1
028 * @param <T> type of the instance to and from which headers will be mapped
029 */
030public interface HeaderMapper<T> {
031
032        /**
033         * Map from the given {@link MessageHeaders} to the specified target message.
034         * @param headers the abstracted MessageHeaders
035         * @param target the native target message
036         */
037        void fromHeaders(MessageHeaders headers, T target);
038
039        /**
040         * Map from the given target message to abstracted {@link MessageHeaders}.
041         * @param source the native target message
042         * @return the abstracted MessageHeaders
043         */
044        MessageHeaders toHeaders(T source);
045
046}