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.ui; 018 019import java.util.Collection; 020import java.util.Map; 021 022/** 023 * Java-5-specific interface that defines a holder for model attributes. 024 * Primarily designed for adding attributes to the model. 025 * Allows for accessing the overall model as a {@code java.util.Map}. 026 * 027 * @author Juergen Hoeller 028 * @since 2.5.1 029 */ 030public interface Model { 031 032 /** 033 * Add the supplied attribute under the supplied name. 034 * @param attributeName the name of the model attribute (never {@code null}) 035 * @param attributeValue the model attribute value (can be {@code null}) 036 */ 037 Model addAttribute(String attributeName, Object attributeValue); 038 039 /** 040 * Add the supplied attribute to this {@code Map} using a 041 * {@link org.springframework.core.Conventions#getVariableName generated name}. 042 * <p><emphasis>Note: Empty {@link java.util.Collection Collections} are not added to 043 * the model when using this method because we cannot correctly determine 044 * the true convention name. View code should check for {@code null} rather 045 * than for empty collections as is already done by JSTL tags.</emphasis> 046 * @param attributeValue the model attribute value (never {@code null}) 047 */ 048 Model addAttribute(Object attributeValue); 049 050 /** 051 * Copy all attributes in the supplied {@code Collection} into this 052 * {@code Map}, using attribute name generation for each element. 053 * @see #addAttribute(Object) 054 */ 055 Model addAllAttributes(Collection<?> attributeValues); 056 057 /** 058 * Copy all attributes in the supplied {@code Map} into this {@code Map}. 059 * @see #addAttribute(String, Object) 060 */ 061 Model addAllAttributes(Map<String, ?> attributes); 062 063 /** 064 * Copy all attributes in the supplied {@code Map} into this {@code Map}, 065 * with existing objects of the same name taking precedence (i.e. not getting 066 * replaced). 067 */ 068 Model mergeAttributes(Map<String, ?> attributes); 069 070 /** 071 * Does this model contain an attribute of the given name? 072 * @param attributeName the name of the model attribute (never {@code null}) 073 * @return whether this model contains a corresponding attribute 074 */ 075 boolean containsAttribute(String attributeName); 076 077 /** 078 * Return the current set of model attributes as a Map. 079 */ 080 Map<String, Object> asMap(); 081 082}