001: /*
002: * Copyright 2005-2007 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:
017: package org.kuali.core.datadictionary;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.Iterator;
023: import java.util.LinkedHashMap;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.commons.lang.StringUtils;
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.kuali.core.datadictionary.exception.DuplicateEntryException;
031:
032: /**
033: * Contains section-related information relating to the parent MaintainableDocument.
034: *
035: * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
036: *
037: *
038: */
039: public class MaintainableSectionDefinition extends
040: DataDictionaryDefinitionBase {
041: // logger
042: private static Log LOG = LogFactory
043: .getLog(MaintainableSectionDefinition.class);
044:
045: private String title;
046:
047: private Map<String, MaintainableItemDefinition> maintainableItems;
048:
049: public MaintainableSectionDefinition() {
050: LOG.debug("creating new LookupDefinition");
051:
052: this .maintainableItems = new LinkedHashMap();
053: }
054:
055: /**
056: * @return title
057: */
058: public String getTitle() {
059: return title;
060: }
061:
062: /**
063: * Sets title to the given value.
064: *
065: * @param title
066: * @throws IllegalArgumentException if the given title is blank
067: */
068: public void setTitle(String title) {
069: if (StringUtils.isBlank(title)) {
070: throw new IllegalArgumentException("invalid (blank) title");
071: }
072: LOG.debug("calling setTitle '" + title + "'");
073:
074: this .title = title;
075: }
076:
077: /**
078: * @param maintainableField
079: * @throws IllegalArgumentException if the given maintainableField is null
080: */
081: public void addMaintainableItem(
082: MaintainableItemDefinition maintainableItem) {
083: if (maintainableItem == null) {
084: throw new IllegalArgumentException(
085: "invalid (null) maintainableItem");
086: }
087: LOG.debug("calling addMaintainableItem for item '"
088: + maintainableItem.getName() + "'");
089:
090: String itemName = maintainableItem.getName();
091: if (this .maintainableItems.containsKey(itemName)) {
092: throw new DuplicateEntryException(
093: "duplicate itemName entry for item '" + itemName
094: + "'");
095: }
096:
097: this .maintainableItems.put(itemName, maintainableItem);
098: }
099:
100: /**
101: * @return List of attributeNames of all MaintainableFieldDefinitions associated with this MaintainableSection, in the order in
102: * which they were added
103: */
104: public List getMaintainableItemNames() {
105: List itemNames = new ArrayList();
106: itemNames.addAll(this .maintainableItems.keySet());
107:
108: return Collections.unmodifiableList(itemNames);
109: }
110:
111: /**
112: * @return Collection of all MaintainableFieldDefinitions associated with this MaintainableSection, in the order in which they
113: * were added
114: */
115: public Collection<MaintainableItemDefinition> getMaintainableItems() {
116: return Collections
117: .unmodifiableCollection(this .maintainableItems.values());
118: }
119:
120: /**
121: * Directly validate simple fields, call completeValidation on Definition fields.
122: *
123: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
124: */
125: public void completeValidation(Class rootBusinessObjectClass,
126: Class otherBusinessObjectClass,
127: ValidationCompletionUtils validationCompletionUtils) {
128: for (Iterator i = maintainableItems.entrySet().iterator(); i
129: .hasNext();) {
130: Map.Entry e = (Map.Entry) i.next();
131:
132: MaintainableItemDefinition maintainableItem = (MaintainableItemDefinition) e
133: .getValue();
134: maintainableItem.completeValidation(
135: rootBusinessObjectClass, null,
136: validationCompletionUtils);
137: }
138: }
139:
140: public String toString() {
141: return "MaintainableSectionDefinition '" + getTitle() + "'";
142: }
143: }
|