001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.core.datadictionary.exporter;
017:
018: import java.util.Collections;
019: import java.util.Map;
020:
021: /*
022: * An ExportMap represents an entry or definition from the dataDictionary as a Map of the contents of that entry or definintion, and
023: * the key by which that entry or definition will be stored in the parent Map.
024: *
025: *
026: */
027: public class ExportMap {
028: private final String exportKey;
029: private final StringMap exportData;
030:
031: public ExportMap(String exportKey) {
032: this .exportKey = exportKey;
033: this .exportData = new StringMap();
034: }
035:
036: /**
037: * @return exportKey associated with this instance
038: */
039: public String getExportKey() {
040: return this .exportKey;
041: }
042:
043: /**
044: * @return unmodifiable copy of the exportData associated with this Map
045: */
046: public Map getExportData() {
047: return Collections.unmodifiableMap(this .exportData);
048: }
049:
050: /**
051: * Adds the ExportMap's exportKey and exportData as a key,value pair to this Map
052: *
053: * @param key
054: * @param value
055: */
056: public void set(ExportMap map) {
057: if (map == null) {
058: throw new IllegalArgumentException("invalid (null) map");
059: }
060:
061: exportData.set(map.getExportKey(), map.getExportData());
062: }
063:
064: /**
065: * If the given map is not null, adds the ExportMap's exportKey and exportData as a key,value pair to this Map
066: *
067: * @param key
068: * @param value
069: */
070: public void setOptional(ExportMap map) {
071: if (map != null) {
072: set(map);
073: }
074: }
075:
076: /**
077: * Adds the given key,value pair to this Map
078: *
079: * @param key
080: * @param value
081: */
082: public void set(String key, String value) {
083: if (key == null) {
084: throw new IllegalArgumentException("invalid (null) key");
085: }
086: if (value == null) {
087: throw new IllegalArgumentException("invalid (null) value");
088: }
089:
090: exportData.set(key, value);
091: }
092:
093: /**
094: * @see java.lang.Object#toString()
095: */
096: public String toString() {
097: return this .exportKey + "(" + this .exportData.size()
098: + " children)";
099: }
100: }
|