1/*2 * $Id: AddableParameterMap.java 1064782 2011-01-28 17:08:52Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.request.collection;
2223import java.util.Collection;
24import java.util.Map;
25import java.util.Set;
2627import org.apache.tiles.request.attribute.HasAddableKeys;
2829/**30 * Exposes an {@link HasAddableKeys} object as a put/get (no remove) map.31 *32 * @version $Rev: 1064782 $ $Date: 2011-01-29 04:08:52 +1100 (Sat, 29 Jan 2011) $33 */34publicclassAddableParameterMapextends ReadOnlyEnumerationMap<String> {
3536/**37 * The request.38 */39private HasAddableKeys<String> request;
4041/**42 * Constructor.43 *44 * @param request The request object to use.45 */46publicAddableParameterMap(HasAddableKeys<String> request) {
47super(request);
48this.request = request;
49 }
5051/** {@inheritDoc} */52public Set<Map.Entry<String, String>> entrySet() {
53returnnewAddableParameterEntrySet();
54 }
5556/** {@inheritDoc} */57public String put(String key, String value) {
58 String oldValue = request.getValue(key);
59 request.setValue(key, value);
60return oldValue;
61 }
626364/** {@inheritDoc} */65publicvoid putAll(Map<? extends String, ? extends String> map) {
66for (Map.Entry<? extends String, ? extends String> entry : map
67 .entrySet()) {
68 request.setValue(entry.getKey(), entry.getValue());
69 }
70 }
717273/**74 * Entry set implementation for {@link AddableParameterMap}.75 */76privateclassAddableParameterEntrySetextends ReadOnlyEnumerationMap<String>.ReadOnlyEnumerationMapEntrySet {
7778 @Override
79publicboolean add(java.util.Map.Entry<String, String> e) {
80 request.setValue(e.getKey(), e.getValue());
81returntrue;
82 }
8384 @Override
85publicboolean addAll(
86 Collection<? extends java.util.Map.Entry<String, String>> c) {
87for (Map.Entry<String, String> entry : c) {
88 request.setValue(entry.getKey(), entry.getValue());
89 }
90returntrue;
91 }
92 }
93 }