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.RiceConstants;
023: import org.kuali.core.datadictionary.exception.AttributeValidationException;
024: import org.kuali.core.datadictionary.exception.ClassValidationException;
025: import org.kuali.core.datadictionary.mask.Mask;
026: import org.kuali.core.lookup.valueFinder.ValueFinder;
027:
028: /**
029: * Contains field-related information for DataDictionary entries.
030: *
031: * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
032: *
033: *
034: */
035: public class FieldDefinition extends DataDictionaryDefinitionBase
036: implements FieldDefinitionI {
037: // logger
038: private static Log LOG = LogFactory.getLog(FieldDefinition.class);
039:
040: private String attributeName;
041: private boolean required;
042: private boolean forceInquiry;
043: private boolean noInquiry;
044: private boolean forceLookup;
045: private boolean noLookup;
046: private String defaultValue;
047: private Class defaultValueFinderClass;
048: /**
049: * This field is stored as a String because apache digester does not make it
050: * easy to detect number format exceptions because it swallows parsing exceptions.
051: */
052: private Integer maxLength;
053:
054: private String displayEditMode;
055: private Mask displayMask;
056:
057: public FieldDefinition() {
058: LOG.debug("creating new FieldDefinition");
059:
060: this .required = false;
061: this .forceInquiry = false;
062: this .noInquiry = false;
063: this .forceLookup = false;
064: this .noLookup = false;
065: this .maxLength = null;
066: }
067:
068: /**
069: * @return attributeName
070: */
071: public String getAttributeName() {
072: return attributeName;
073: }
074:
075: /**
076: * Sets attributeName to the given value.
077: *
078: * @param attributeName
079: * @throws IllegalArgumentException if the given attributeName is blank
080: */
081: public void setAttributeName(String attributeName) {
082: if (StringUtils.isBlank(attributeName)) {
083: throw new IllegalArgumentException(
084: "invalid (blank) attributeName");
085: }
086: LOG.debug("calling setAttributeName '" + attributeName + "'");
087:
088: this .attributeName = attributeName;
089: }
090:
091: /**
092: * @return true if this attribute is required
093: */
094: public boolean isRequired() {
095: return required;
096: }
097:
098: /**
099: * Sets required to the given value.
100: *
101: * @param required
102: */
103: public void setRequired(boolean required) {
104: LOG.debug("calling setRequired '" + required + "'");
105:
106: this .required = required;
107: }
108:
109: /**
110: * @return Returns the forceInquiry.
111: */
112: public boolean isForceInquiry() {
113: return forceInquiry;
114: }
115:
116: /**
117: * @param forceInquiry The forceInquiry to set.
118: */
119: public void setForceInquiry(boolean forceInquiry) {
120: this .forceInquiry = forceInquiry;
121: }
122:
123: /**
124: * @return Returns the forceLookup.
125: */
126: public boolean isForceLookup() {
127: return forceLookup;
128: }
129:
130: /**
131: * @param forceLookup The forceLookup to set.
132: */
133: public void setForceLookup(boolean forceLookup) {
134: this .forceLookup = forceLookup;
135: }
136:
137: /**
138: * @return Returns the noInquiry.
139: */
140: public boolean isNoInquiry() {
141: return noInquiry;
142: }
143:
144: /**
145: * @param noInquiry The noInquiry to set.
146: */
147: public void setNoInquiry(boolean noInquiry) {
148: this .noInquiry = noInquiry;
149: }
150:
151: /**
152: * @return Returns the noLookup.
153: */
154: public boolean isNoLookup() {
155: return noLookup;
156: }
157:
158: /**
159: * @param noLookup The noLookup to set.
160: */
161: public void setNoLookup(boolean noLookup) {
162: this .noLookup = noLookup;
163: }
164:
165: /**
166: * @return Returns the defaultValue.
167: */
168: public String getDefaultValue() {
169: return defaultValue;
170: }
171:
172: /**
173: * @param defaultValue The defaultValue to set.
174: */
175: public void setDefaultValue(String defaultValue) {
176: this .defaultValue = defaultValue;
177: }
178:
179: /**
180: * @param defaultValueFinderClass
181: */
182: public void setDefaultValueFinderClass(Class defaultValueFinderClass) {
183: if (defaultValueFinderClass == null) {
184: throw new IllegalArgumentException(
185: "invalid (null) defaultValueFinderClass");
186: }
187:
188: this .defaultValueFinderClass = defaultValueFinderClass;
189: }
190:
191: /**
192: * @return custom defaultValue class
193: */
194: public Class getDefaultValueFinderClass() {
195: return this .defaultValueFinderClass;
196: }
197:
198: /**
199: * Directly validate simple fields.
200: *
201: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
202: */
203: public void completeValidation(Class rootBusinessObjectClass,
204: Class otherBusinessObjectClass,
205: ValidationCompletionUtils validationCompletionUtils) {
206:
207: if (!validationCompletionUtils.isPropertyOf(
208: rootBusinessObjectClass, getAttributeName())) {
209: throw new AttributeValidationException(
210: "unable to find attribute '" + attributeName
211: + "' in rootBusinessObjectClass '"
212: + rootBusinessObjectClass.getName() + "' ("
213: + getParseLocation() + ")");
214: }
215:
216: if (defaultValueFinderClass != null && defaultValue != null) {
217: throw new AttributeValidationException(
218: "Both defaultValue and defaultValueFinderClass can not be specified on attribute "
219: + getAttributeName()
220: + " in rootBusinessObjectClass "
221: + rootBusinessObjectClass.getName());
222: }
223:
224: if (defaultValueFinderClass != null) {
225: if (!ValueFinder.class
226: .isAssignableFrom(defaultValueFinderClass)) {
227: throw new ClassValidationException(
228: "defaultValueFinderClass '"
229: + defaultValueFinderClass
230: + "' is not a subclasss of ValueFinder ("
231: + getParseLocation() + ")");
232: }
233: }
234:
235: if (forceInquiry == true && noInquiry == true) {
236: throw new AttributeValidationException(
237: "Both forceInquiry and noInquiry can not be set to true on attribute "
238: + getAttributeName()
239: + " in rootBusinessObjectClass "
240: + rootBusinessObjectClass.getName());
241: }
242: if (forceLookup == true && noLookup == true) {
243: throw new AttributeValidationException(
244: "Both forceLookup and noLookup can not be set to true on attribute "
245: + getAttributeName()
246: + " in rootBusinessObjectClass "
247: + rootBusinessObjectClass.getName());
248: }
249: }
250:
251: /**
252: * @see java.lang.Object#toString()
253: */
254: public String toString() {
255: return "FieldDefinition for attribute " + getAttributeName();
256: }
257:
258: public String getName() {
259: return this .getAttributeName();
260: }
261:
262: public String getDisplayEditMode() {
263: return displayEditMode;
264: }
265:
266: public void setDisplayEditMode(String displayEditMode) {
267: this .displayEditMode = displayEditMode;
268: }
269:
270: public Mask getDisplayMask() {
271: return displayMask;
272: }
273:
274: public void setDisplayMask(Mask displayMask) {
275: this .displayMask = displayMask;
276: }
277:
278: public boolean isReadOnlyAfterAdd() {
279: return false;
280: }
281:
282: /**
283: * Gets the maxLength attribute.
284: * @return Returns the maxLength.
285: */
286: public Integer getMaxLength() {
287: return maxLength;
288: }
289:
290: /**
291: * Sets the maxLength attribute value.
292: * @param maxLength The maxLength to set.
293: */
294: public void setMaxLength(Integer maxLength) {
295: this.maxLength = maxLength;
296: }
297: }
|