001/*
002 * Copyright 2002-2012 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.web.bind.support;
018
019import org.springframework.web.context.request.WebRequest;
020
021/**
022 * Strategy interface for storing model attributes in a backend session.
023 *
024 * @author Juergen Hoeller
025 * @since 2.5
026 * @see org.springframework.web.bind.annotation.SessionAttributes
027 */
028public interface SessionAttributeStore {
029
030        /**
031         * Store the supplied attribute in the backend session.
032         * <p>Can be called for new attributes as well as for existing attributes.
033         * In the latter case, this signals that the attribute value may have been modified.
034         * @param request the current request
035         * @param attributeName the name of the attribute
036         * @param attributeValue the attribute value to store
037         */
038        void storeAttribute(WebRequest request, String attributeName, Object attributeValue);
039
040        /**
041         * Retrieve the specified attribute from the backend session.
042         * <p>This will typically be called with the expectation that the
043         * attribute is already present, with an exception to be thrown
044         * if this method returns {@code null}.
045         * @param request the current request
046         * @param attributeName the name of the attribute
047         * @return the current attribute value, or {@code null} if none
048         */
049        Object retrieveAttribute(WebRequest request, String attributeName);
050
051        /**
052         * Clean up the specified attribute in the backend session.
053         * <p>Indicates that the attribute name will not be used anymore.
054         * @param request the current request
055         * @param attributeName the name of the attribute
056         */
057        void cleanupAttribute(WebRequest request, String attributeName);
058
059}