001/*
002 * Copyright 2002-2006 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.validation;
018
019import java.io.Serializable;
020import java.util.Map;
021
022import org.springframework.util.Assert;
023
024/**
025 * Map-based implementation of the BindingResult interface,
026 * supporting registration and evaluation of binding errors on
027 * Map attributes.
028 *
029 * <p>Can be used as errors holder for custom binding onto a
030 * Map, for example when invoking a Validator for a Map object.
031 *
032 * @author Juergen Hoeller
033 * @since 2.0
034 * @see java.util.Map
035 */
036@SuppressWarnings("serial")
037public class MapBindingResult extends AbstractBindingResult implements Serializable {
038
039        private final Map<?, ?> target;
040
041
042        /**
043         * Create a new MapBindingResult instance.
044         * @param target the target Map to bind onto
045         * @param objectName the name of the target object
046         */
047        public MapBindingResult(Map<?, ?> target, String objectName) {
048                super(objectName);
049                Assert.notNull(target, "Target Map must not be null");
050                this.target = target;
051        }
052
053
054        public final Map<?, ?> getTargetMap() {
055                return this.target;
056        }
057
058        @Override
059        public final Object getTarget() {
060                return this.target;
061        }
062
063        @Override
064        protected Object getActualFieldValue(String field) {
065                return this.target.get(field);
066        }
067
068}