View Javadoc

1   /*
2    * Copyright 2005-2007 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.kns.datadictionary.exporter;
17  
18  import java.util.Collections;
19  import java.util.Map;
20  
21  /*
22   * An ExportMap represents an entry or definition from the dataDictionary as a Map of the contents of that entry or definintion, and
23   * the key by which that entry or definition will be stored in the parent Map.
24   * 
25   * 
26   */
27  public class ExportMap {
28      private final String exportKey;
29      private final StringMap exportData;
30  
31      public ExportMap(String exportKey) {
32          this.exportKey = exportKey;
33          this.exportData = new StringMap();
34      }
35  
36  
37      /**
38       * @return exportKey associated with this instance
39       */
40      public String getExportKey() {
41          return this.exportKey;
42      }
43  
44      /**
45       * @return unmodifiable copy of the exportData associated with this Map
46       */
47      public Map getExportData() {
48          return Collections.unmodifiableMap(this.exportData);
49      }
50  
51  
52      /**
53       * Adds the ExportMap's exportKey and exportData as a key,value pair to this Map
54       * 
55       * @param key
56       * @param value
57       */
58      public void set(ExportMap map) {
59          if (map == null) {
60              throw new IllegalArgumentException("invalid (null) map");
61          }
62  
63          exportData.set(map.getExportKey(), map.getExportData());
64      }
65  
66      /**
67       * If the given map is not null, adds the ExportMap's exportKey and exportData as a key,value pair to this Map
68       * 
69       * @param key
70       * @param value
71       */
72      public void setOptional(ExportMap map) {
73          if (map != null) {
74              set(map);
75          }
76      }
77  
78      /**
79       * Adds the given key,value pair to this Map
80       * 
81       * @param key
82       * @param value
83       */
84      public void set(String key, String value) {
85          if (key == null) {
86              throw new IllegalArgumentException("invalid (null) key");
87          }
88          if (value == null) {
89              throw new IllegalArgumentException("invalid (null) value - key=" + key);
90          }
91  
92          exportData.set(key, value);
93      }
94  
95  
96      /**
97       * @see java.lang.Object#toString()
98       */
99      public String toString() {
100         return this.exportKey + "(" + this.exportData.size() + " children)";
101     }
102 }