001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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 * http://www.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.krad.datadictionary.exporter;
017
018import org.kuali.rice.core.api.exception.RiceRuntimeException;
019
020import java.util.LinkedHashMap;
021import java.util.Map;
022
023/**
024 * Adds a litle strong type-checking and validation on top of the generic LinkedHashMap
025 */
026@Deprecated
027public class StringMap extends LinkedHashMap<String, Object> {
028    private static final long serialVersionUID = 7364206011639131063L;
029
030    /**
031     * Associates the given String with the given Map value.
032     *
033     * @param key
034     * @param value
035     */
036    public void set(String key, Map<String, Object> value) {
037        setUnique(key, value);
038    }
039
040    /**
041     * Associates the given String with the given String value.
042     *
043     * @param key
044     * @param value
045     */
046    public void set(String key, String value) {
047        setUnique(key, value);
048    }
049
050    /**
051     * Verifies that the key isn't blank, and that the value isn't null, and prevents duplicate keys from being used.
052     *
053     * @param key
054     * @param value
055     */
056    private void setUnique(String key, Object value) {
057        if (value == null) {
058            throw new IllegalArgumentException("invalid (null) value");
059        }
060
061        if (containsKey(key)) {
062            throw new RiceRuntimeException("duplicate key '" + key + "'");
063        }
064
065        super.put(key, value);
066    }
067
068    @Override
069    public Object put(String key, Object value) {
070        throw new UnsupportedOperationException("direct calls to put not supported");
071    }
072
073    @Override
074    public void putAll(Map<? extends String, ? extends Object> m) {
075        throw new UnsupportedOperationException("direct calls to put not supported");
076    }
077}