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 org.apache.commons.lang.StringUtils;
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.kuali.core.datadictionary.exception.ClassValidationException;
023:
024: /**
025: * A single BusinessObject entry in the DataDictionary, which contains information relating to the display, validation, and general
026: * maintenance of a BusinessObject and its attributes.
027: *
028: * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
029: */
030: public class BusinessObjectEntry extends DataDictionaryEntryBase {
031: // logger
032: private static Log LOG = LogFactory
033: .getLog(BusinessObjectEntry.class);
034:
035: private Class businessObjectClass;
036:
037: private boolean boNotesEnabled;
038:
039: private InquiryDefinition inquiryDefinition;
040: private LookupDefinition lookupDefinition;
041:
042: private String titleAttribute;
043: private String objectLabel;
044: private String objectDescription;
045:
046: private HelpDefinition helpDefinition;
047:
048: public BusinessObjectEntry() {
049: super ();
050: LOG.debug("creating new BusinessObjectEntry");
051: }
052:
053: /**
054: * @see org.kuali.core.datadictionary.DataDictionaryEntry#getJstlKey()
055: */
056: public String getJstlKey() {
057: if (this .businessObjectClass == null) {
058: throw new IllegalStateException(
059: "cannot generate JSTL key: businessObjectClass is null");
060: }
061:
062: String jstlKey = StringUtils.substringAfterLast(
063: this .businessObjectClass.getName(), ".");
064: return jstlKey;
065: }
066:
067: public void setBusinessObjectClass(Class businessObjectClass) {
068: if (businessObjectClass == null) {
069: throw new IllegalArgumentException(
070: "invalid (null) businessObjectClass");
071: }
072:
073: this .businessObjectClass = businessObjectClass;
074: }
075:
076: public Class getBusinessObjectClass() {
077: return businessObjectClass;
078: }
079:
080: public boolean isBoNotesEnabled() {
081: return boNotesEnabled;
082: }
083:
084: public void setBoNotesEnabled(boolean boNotesEnabled) {
085: this .boNotesEnabled = boNotesEnabled;
086: }
087:
088: /**
089: * @return true if this instance has an inquiryDefinition
090: */
091: public boolean hasInquiryDefinition() {
092: return (inquiryDefinition != null);
093: }
094:
095: /**
096: * @return current inquiryDefinition for this BusinessObjectEntry, or null if there is none
097: */
098: public InquiryDefinition getInquiryDefinition() {
099: return inquiryDefinition;
100: }
101:
102: /**
103: * Sets the inquiryDefinition for this BusinessObjectEntry to the given inquiryDefinition.
104: *
105: * @param inquiryDefinition
106: */
107: public void setInquiryDefinition(InquiryDefinition inquiryDefinition) {
108: if (inquiryDefinition == null) {
109: throw new IllegalArgumentException(
110: "invalid (null) inquiryDefinition");
111: }
112: LOG.debug("calling setInquiryDefinition '"
113: + inquiryDefinition.getTitle() + "'");
114:
115: this .inquiryDefinition = inquiryDefinition;
116: }
117:
118: /**
119: * @return true if this instance has a lookupDefinition
120: */
121: public boolean hasLookupDefinition() {
122: return (lookupDefinition != null);
123: }
124:
125: /**
126: * @return current lookupDefinition for this BusinessObjectEntry, or null if there is none
127: */
128: public LookupDefinition getLookupDefinition() {
129: return lookupDefinition;
130: }
131:
132: /**
133: * Sets the lookupDefinition for this BusinessObjectEntry to the given lookupDefinition.
134: *
135: * @param lookupDefinition
136: */
137: public void setLookupDefinition(LookupDefinition lookupDefinition) {
138: if (lookupDefinition == null) {
139: throw new IllegalArgumentException(
140: "invalid (null) lookupDefinition");
141: }
142: LOG.debug("calling setLookupDefinition '"
143: + lookupDefinition.getTitle() + "'");
144:
145: this .lookupDefinition = lookupDefinition;
146: }
147:
148: /**
149: * @return Returns the titleAttribute.
150: */
151: public String getTitleAttribute() {
152: return titleAttribute;
153: }
154:
155: /**
156: * @param titleAttribute The titleAttribute to set.
157: */
158: public void setTitleAttribute(String titleAttribute) {
159: this .titleAttribute = titleAttribute;
160: }
161:
162: /**
163: * Directly validate simple fields, call completeValidation on Definition fields.
164: */
165: public void completeValidation(
166: ValidationCompletionUtils validationCompletionUtils) {
167: super .completeValidation(validationCompletionUtils);
168:
169: if (!validationCompletionUtils
170: .isBusinessObjectClass(businessObjectClass)) {
171: throw new ClassValidationException("businessObjectClass '"
172: + businessObjectClass.getName()
173: + "' is not a BusinessObject class");
174: }
175:
176: if (hasInquiryDefinition()) {
177: inquiryDefinition.completeValidation(businessObjectClass,
178: null, validationCompletionUtils);
179: }
180:
181: if (hasLookupDefinition()) {
182: lookupDefinition.completeValidation(businessObjectClass,
183: null, validationCompletionUtils);
184: }
185:
186: }
187:
188: /**
189: * @see org.kuali.core.datadictionary.DataDictionaryEntryBase#getEntryClass()
190: */
191: public Class getEntryClass() {
192: return getBusinessObjectClass();
193: }
194:
195: /**
196: * @see org.kuali.core.datadictionary.DataDictionaryEntry#getFullClassName()
197: */
198: public String getFullClassName() {
199: return getBusinessObjectClass().getName();
200: }
201:
202: /**
203: * @return Returns the objectLabel.
204: */
205: public String getObjectLabel() {
206: return objectLabel;
207: }
208:
209: /**
210: * @param objectLabel The objectLabel to set.
211: */
212: public void setObjectLabel(String objectLabel) {
213: this .objectLabel = objectLabel;
214: }
215:
216: /**
217: * @return Returns the description.
218: */
219: public String getObjectDescription() {
220: return objectDescription;
221: }
222:
223: /**
224: * @param description The description to set.
225: */
226: public void setObjectDescription(String objectDescription) {
227: if (StringUtils.isBlank(objectDescription)) {
228: throw new IllegalArgumentException(
229: "invalid (blank) objectDescription");
230: }
231: LOG.debug("calling setObjectDescription '" + objectDescription
232: + "'");
233:
234: this .objectDescription = objectDescription;
235: }
236:
237: /**
238: * Gets the helpDefinition attribute.
239: *
240: * @return Returns the helpDefinition.
241: */
242: public HelpDefinition getHelpDefinition() {
243: return helpDefinition;
244: }
245:
246: /**
247: * Sets the helpDefinition attribute value.
248: *
249: * @param helpDefinition The helpDefinition to set.
250: */
251: public void setHelpDefinition(HelpDefinition helpDefinition) {
252: this .helpDefinition = helpDefinition;
253: }
254:
255: /**
256: * @see java.lang.Object#toString()
257: */
258: public String toString() {
259: String className = null;
260: if (getBusinessObjectClass() != null) {
261: className = getBusinessObjectClass().getName();
262: }
263:
264: return "BusinessObjectEntry for class " + className;
265: }
266:
267: }
|