001: /*
002: * Copyright 2006-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 for inquiry sections
034: * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
035: */
036: public class InquirySectionDefinition extends
037: DataDictionaryDefinitionBase {
038: private static Log LOG = LogFactory
039: .getLog(InquirySectionDefinition.class);
040:
041: private String title;
042: private Map<String, FieldDefinition> inquiryFields;
043: private Map inquiryCollections;
044:
045: private String numberOfColumns;
046:
047: public InquirySectionDefinition() {
048: LOG.debug("creating new InquirySectionDefinition");
049: this .inquiryFields = new LinkedHashMap();
050: this .inquiryCollections = new LinkedHashMap();
051: }
052:
053: /**
054: * @return title
055: */
056: public String getTitle() {
057: return title;
058: }
059:
060: /**
061: * Sets title to the given value.
062: *
063: * @param title
064: * @throws IllegalArgumentException if the given title is blank
065: */
066: public void setTitle(String title) {
067: if (StringUtils.isBlank(title)) {
068: throw new IllegalArgumentException("invalid (blank) title");
069: }
070: LOG.debug("calling setTitle '" + title + "'");
071:
072: this .title = title;
073: }
074:
075: /**
076: * @param FieldDefinition
077: * @throws IllegalArgumentException if the given FieldDefinition is null
078: */
079: public void addInquiryField(FieldDefinition inquiryField) {
080: if (inquiryField == null) {
081: throw new IllegalArgumentException(
082: "invalid (null) inquiryField");
083: }
084:
085: String itemName = inquiryField.getAttributeName();
086: if (this .inquiryFields.containsKey(itemName)) {
087: throw new DuplicateEntryException(
088: "duplicate itemName entry for item '" + itemName
089: + "'");
090: }
091:
092: this .inquiryFields.put(itemName, inquiryField);
093: }
094:
095: /**
096: * @return List of attributeNames of all FieldDefinitions associated with this InquirySection, in the order in
097: * which they were added
098: */
099: public List getInquiryFieldNames() {
100: List itemNames = new ArrayList();
101: itemNames.addAll(this .inquiryFields.keySet());
102:
103: return Collections.unmodifiableList(itemNames);
104: }
105:
106: /**
107: * @return Collection of all FieldDefinitions associated with this InquirySection, in the order in which they
108: * were added
109: */
110: public Collection<FieldDefinition> getInquiryFields() {
111: return Collections.unmodifiableCollection(this .inquiryFields
112: .values());
113: }
114:
115: /**
116: * Directly validate simple fields, call completeValidation on Definition fields.
117: *
118: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
119: */
120: public void completeValidation(Class rootBusinessObjectClass,
121: Class otherBusinessObjectClass,
122: ValidationCompletionUtils validationCompletionUtils) {
123: for (Iterator i = inquiryFields.entrySet().iterator(); i
124: .hasNext();) {
125: Map.Entry e = (Map.Entry) i.next();
126:
127: FieldDefinition inquiryField = (FieldDefinition) e
128: .getValue();
129: inquiryField.completeValidation(rootBusinessObjectClass,
130: null, validationCompletionUtils);
131: }
132: }
133:
134: public String toString() {
135: return "InquirySectionDefinition '" + getTitle() + "'";
136: }
137:
138: public Map getInquiryCollections() {
139: return inquiryCollections;
140: }
141:
142: public void setInquiryCollections(Map inquiryCollections) {
143: this .inquiryCollections = inquiryCollections;
144: }
145:
146: public String getNumberOfColumns() {
147: return numberOfColumns;
148: }
149:
150: public void setNumberOfColumns(String numberOfColumns) {
151: this.numberOfColumns = numberOfColumns;
152: }
153: }
|