001: /*
002: * Copyright 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: package org.kuali.core.datadictionary;
017:
018: import java.util.Collection;
019: import java.util.Collections;
020: import java.util.LinkedHashMap;
021: import java.util.Map;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.kuali.core.datadictionary.exception.DuplicateEntryException;
026:
027: public class InquiryCollectionDefinition extends FieldDefinition
028: implements CollectionDefinitionI {
029: private static Log LOG = LogFactory
030: .getLog(InquiryCollectionDefinition.class);
031:
032: private String name;
033:
034: private Class businessObjectClass;
035:
036: private String numberOfColumns;
037:
038: private Map inquiryFields;
039:
040: private Map inquiryCollections;
041:
042: private String summaryTitle;
043:
044: private Map summaryFields;
045:
046: public InquiryCollectionDefinition() {
047: this .inquiryFields = new LinkedHashMap();
048: this .inquiryCollections = new LinkedHashMap();
049: this .summaryFields = new LinkedHashMap();
050: }
051:
052: public Class getBusinessObjectClass() {
053: return businessObjectClass;
054: }
055:
056: public void setBusinessObjectClass(Class businessObjectClass) {
057: this .businessObjectClass = businessObjectClass;
058: }
059:
060: public Collection getInquiryFields() {
061: return Collections.unmodifiableCollection(this .inquiryFields
062: .values());
063: }
064:
065: public void setInquiryFields(Map inquiryFields) {
066: this .inquiryFields = inquiryFields;
067: }
068:
069: public String getNumberOfColumns() {
070: return numberOfColumns;
071: }
072:
073: public void setNumberOfColumns(String numberOfColumns) {
074: this .numberOfColumns = numberOfColumns;
075: }
076:
077: public String getName() {
078: return name;
079: }
080:
081: public void setName(String name) {
082: this .name = name;
083: }
084:
085: // don't like this, but need to be able get resolve the property
086: // AttriubteName
087: public String getAttributeName() {
088: return this .name;
089: }
090:
091: public void addInquiryField(FieldDefinition inquiryField) {
092: if (inquiryField == null) {
093: throw new IllegalArgumentException(
094: "invalid (null) inquiryField");
095: }
096:
097: String itemName = inquiryField.getAttributeName();
098: if (this .inquiryFields.containsKey(itemName)) {
099: throw new DuplicateEntryException(
100: "duplicate itemName entry for item '" + itemName
101: + "'");
102: }
103:
104: this .inquiryFields.put(itemName, inquiryField);
105: }
106:
107: public void addSummaryField(FieldDefinition inquiryField) {
108: if (inquiryField == null) {
109: throw new IllegalArgumentException(
110: "invalid (null) inquiryField");
111: }
112:
113: String itemName = inquiryField.getAttributeName();
114: if (this .summaryFields.containsKey(itemName)) {
115: throw new DuplicateEntryException(
116: "duplicate itemName entry for item '" + itemName
117: + "'");
118: }
119:
120: this .summaryFields.put(itemName, inquiryField);
121: }
122:
123: /**
124: * @param inquiryCollection
125: * @throws IllegalArgumentException
126: * if the given maintainableCollection is null
127: */
128: public void addInquiryCollection(
129: InquiryCollectionDefinition inquiryCollection) {
130: if (inquiryCollection == null) {
131: throw new IllegalArgumentException(
132: "invalid (null) inquiryCollection");
133: }
134: if (LOG.isDebugEnabled()) {
135: LOG.debug("calling addinquiryCollection for field '"
136: + inquiryCollection.getName() + "'");
137: }
138:
139: String fieldName = inquiryCollection.getName();
140: if (this .inquiryCollections.containsKey(fieldName)) {
141: throw new DuplicateEntryException(
142: "duplicate fieldName entry for field '" + fieldName
143: + "'");
144: }
145:
146: this .inquiryCollections.put(fieldName, inquiryCollection);
147: }
148:
149: /**
150: * @return Collection of all lookupField MaintainableCollectionDefinitions
151: * associated with this MaintainableCollectionDefinition, in the
152: * order in which they were added
153: */
154: public Collection<InquiryCollectionDefinition> getInquiryCollections() {
155: return Collections
156: .unmodifiableCollection(this .inquiryCollections
157: .values());
158: }
159:
160: public Collection<? extends CollectionDefinitionI> getCollections() {
161: return this .getInquiryCollections();
162: }
163:
164: public Collection getFields() {
165: // TODO Auto-generated method stub
166: return this .getInquiryFields();
167: }
168:
169: public boolean getIncludeAddLine() {
170: return false;
171: }
172:
173: /**
174: * @return Collection of all SummaryFieldDefinitions associated with this
175: * SummaryFieldDefinition, in the order in which they were added
176: */
177: public Collection<? extends FieldDefinitionI> getSummaryFields() {
178: return Collections.unmodifiableCollection(this .summaryFields
179: .values());
180: }
181:
182: public boolean hasSummaryField(String key) {
183: return this .summaryFields.containsKey(key);
184: }
185:
186: public void setSummaryTitle(String summaryTitle) {
187: this .summaryTitle = summaryTitle;
188: }
189:
190: public String getSummaryTitle() {
191: return this.summaryTitle;
192: }
193: }
|