View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.exporter;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.exception.DuplicateKeyException;
20  
21  import java.util.LinkedHashMap;
22  import java.util.Map;
23  
24  
25  /**
26   * Adds a litle strong type-checking and validation on top of the generic LinkedHashMap
27   * 
28   * 
29   */
30  @Deprecated
31  public class StringMap extends LinkedHashMap {
32      private static final long serialVersionUID = 7364206011639131063L;
33  
34      /**
35       * Associates the given String with the given Map value.
36       * 
37       * @param key
38       * @param value
39       */
40      public void set(String key, Map value) {
41          setUnique(key, value);
42      }
43  
44      /**
45       * Associates the given String with the given String value.
46       * 
47       * @param key
48       * @param value
49       */
50      public void set(String key, String value) {
51          setUnique(key, value);
52      }
53  
54  
55      /**
56       * Verifies that the key isn't blank, and that the value isn't null, and prevents duplicate keys from being used.
57       * 
58       * @param key
59       * @param value
60       */
61      private void setUnique(String key, Object value) {
62          if (StringUtils.isBlank(key)) {
63              throw new IllegalArgumentException("invalid (blank) key");
64          }
65          if (value == null) {
66              throw new IllegalArgumentException("invalid (null) value");
67          }
68  
69          if (containsKey(key)) {
70              throw new DuplicateKeyException("duplicate key '" + key + "'");
71          }
72  
73          super.put(key, value);
74      }
75  
76  
77      /**
78       * Overridden to prevent direct calls
79       * 
80       * @see java.util.Map#put(java.lang.Object, java.lang.Object)
81       */
82      public Object put(Object key, Object value) {
83          throw new UnsupportedOperationException("direct calls to put not supported");
84      }
85  
86      /**
87       * Overridden to prevent direct calls
88       * 
89       * @see java.util.Map#put(java.lang.Object, java.lang.Object)
90       */
91      public void putAll(Map m) {
92          throw new UnsupportedOperationException("direct calls to putAll not supported");
93      }
94  }