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: package org.kuali.core.datadictionary;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021: import org.kuali.core.bo.BusinessObject;
022: import org.kuali.core.datadictionary.exception.AttributeValidationException;
023: import org.kuali.core.datadictionary.exception.ClassValidationException;
024: import org.kuali.core.datadictionary.mask.Mask;
025: import org.kuali.core.datadictionary.mask.MaskFormatter;
026: import org.kuali.core.lookup.valueFinder.ValueFinder;
027:
028: /**
029: * MaintainableFieldDefinition
030: *
031: *
032: */
033: public class MaintainableFieldDefinition extends
034: MaintainableItemDefinition implements FieldDefinitionI {
035: // logger
036: private static Log LOG = LogFactory
037: .getLog(MaintainableFieldDefinition.class);
038:
039: private String name;
040: private boolean required;
041: private boolean readOnly;
042: private boolean readOnlyAfterAdd = false;
043:
044: private String defaultValue;
045: private String template;
046: private Class defaultValueFinderClass;
047:
048: private String displayEditMode;
049: private Mask displayMask;
050:
051: private String webUILeaveFieldFunction = "";
052: private String webUILeaveFieldCallbackFunction = "";
053:
054: private Class overrideLookupClass;
055: private String overrideFieldConversions;
056:
057: public MaintainableFieldDefinition() {
058: LOG.debug("creating new MaintainableFieldDefinition");
059:
060: this .required = false;
061: }
062:
063: /**
064: * @return attributeName
065: */
066: public String getName() {
067: return name;
068: }
069:
070: /**
071: * Sets name to the given value.
072: *
073: * @param name
074: * @throws IllegalArgumentException if the given name is blank
075: */
076: public void setName(String name) {
077: if (StringUtils.isBlank(name)) {
078: throw new IllegalArgumentException("invalid (blank) name");
079: }
080: LOG.debug("calling setName '" + name + "'");
081:
082: this .name = name;
083: }
084:
085: /**
086: * @return true if this attribute is required
087: */
088: public boolean isRequired() {
089: return required;
090: }
091:
092: /**
093: * Sets isRequired to the given value
094: *
095: * @param isRequired
096: */
097: public void setRequired(boolean required) {
098: LOG.debug("calling setRequired '" + required + "'");
099:
100: this .required = required;
101: }
102:
103: /**
104: * @return Returns the defaultValue.
105: */
106: public String getDefaultValue() {
107: return defaultValue;
108: }
109:
110: /**
111: * @param defaultValue The defaultValue to set.
112: */
113: public void setDefaultValue(String defaultValue) {
114: this .defaultValue = defaultValue;
115: }
116:
117: /**
118: * @param defaultValueFinderClass
119: */
120: public void setDefaultValueFinderClass(Class defaultValueFinderClass) {
121: if (defaultValueFinderClass == null) {
122: throw new IllegalArgumentException(
123: "invalid (null) defaultValueFinderClass");
124: }
125:
126: this .defaultValueFinderClass = defaultValueFinderClass;
127: }
128:
129: /**
130: * @return custom defaultValue class
131: */
132: public Class getDefaultValueFinderClass() {
133: return this .defaultValueFinderClass;
134: }
135:
136: /**
137: * @return Returns the readOnly.
138: */
139: public boolean isReadOnly() {
140: return readOnly;
141: }
142:
143: /**
144: * @param readOnly The readOnly to set.
145: */
146: public void setReadOnly(boolean readOnly) {
147: this .readOnly = readOnly;
148: }
149:
150: /**
151: * Gets the displayEditMode attribute.
152: *
153: * @return Returns the displayEditMode.
154: */
155: public String getDisplayEditMode() {
156: return displayEditMode;
157: }
158:
159: /**
160: * Sets the displayEditMode attribute value.
161: *
162: * @param displayEditMode The displayEditMode to set.
163: */
164: public void setDisplayEditMode(String displayEditMode) {
165: this .displayEditMode = displayEditMode;
166: }
167:
168: /**
169: * Gets the displayMask attribute.
170: *
171: * @return Returns the displayMask.
172: */
173: public Mask getDisplayMask() {
174: return displayMask;
175: }
176:
177: /**
178: * Sets the displayMask attribute value.
179: *
180: * @param displayMask The displayMask to set.
181: */
182: public void setDisplayMask(Mask displayMask) {
183: this .displayMask = displayMask;
184: }
185:
186: /**
187: * Gets the overrideFieldConversions attribute.
188: * @return Returns the overrideFieldConversions.
189: */
190: public String getOverrideFieldConversions() {
191: return overrideFieldConversions;
192: }
193:
194: /**
195: * Sets the overrideFieldConversions attribute value.
196: * @param overrideFieldConversions The overrideFieldConversions to set.
197: */
198: public void setOverrideFieldConversions(
199: String overrideFieldConversions) {
200: this .overrideFieldConversions = overrideFieldConversions;
201: }
202:
203: /**
204: * Gets the overrideLookupClass attribute.
205: * @return Returns the overrideLookupClass.
206: */
207: public Class getOverrideLookupClass() {
208: return overrideLookupClass;
209: }
210:
211: /**
212: * Sets the overrideLookupClass attribute value.
213: * @param overrideLookupClass The overrideLookupClass to set.
214: */
215: public void setOverrideLookupClass(Class overrideLookupClass) {
216: this .overrideLookupClass = overrideLookupClass;
217: }
218:
219: /**
220: * Directly validate simple fields.
221: *
222: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
223: */
224: public void completeValidation(Class rootBusinessObjectClass,
225: Class otherBusinessObjectClass,
226: ValidationCompletionUtils validationCompletionUtils) {
227: if (!validationCompletionUtils.isPropertyOf(
228: rootBusinessObjectClass, name)) {
229: throw new AttributeValidationException(
230: "unable to find attribute or collection named '"
231: + name + "' in rootBusinessObjectClass '"
232: + rootBusinessObjectClass.getName() + "' ("
233: + getParseLocation() + ")");
234: }
235:
236: if (defaultValueFinderClass != null && defaultValue != null) {
237: throw new AttributeValidationException(
238: "Both defaultValue and defaultValueFinderClass can not be specified on attribute "
239: + name
240: + " in rootBusinessObjectClass "
241: + rootBusinessObjectClass.getName());
242: }
243:
244: if (defaultValueFinderClass != null) {
245: if (!ValueFinder.class
246: .isAssignableFrom(defaultValueFinderClass)) {
247: throw new ClassValidationException(
248: "defaultValueFinderClass '"
249: + defaultValueFinderClass
250: + "' is not a subclasss of ValueFinder ("
251: + getParseLocation() + ")");
252: }
253: }
254:
255: if (StringUtils.isNotBlank(displayEditMode)
256: && displayMask == null) {
257: throw new AttributeValidationException(
258: "property '"
259: + getName()
260: + "' has a display edit mode defined but not a valid display mask '"
261: + "' (" + getParseLocation() + ")");
262: }
263:
264: if (displayMask != null) {
265: if (getDisplayMask().getMaskFormatter() == null
266: && getDisplayMask().getMaskFormatterClass() == null) {
267: throw new AttributeValidationException(
268: "No mask formatter or formatter class specified for secure attribute "
269: + getName() + "' ("
270: + getParseLocation() + ")");
271: }
272:
273: if (getDisplayMask().getMaskFormatterClass() != null) {
274: if (!MaskFormatter.class
275: .isAssignableFrom(getDisplayMask()
276: .getMaskFormatterClass())) {
277: throw new ClassValidationException(
278: "Class '"
279: + getDisplayMask()
280: .getMaskFormatterClass()
281: .getName()
282: + "' for secure attribute '"
283: + getName()
284: + "' does not implement org.kuali.core.datadictionary.mask.MaskFormatter ("
285: + getParseLocation() + ")");
286: }
287: }
288: }
289:
290: if (overrideLookupClass != null) {
291: if (!BusinessObject.class
292: .isAssignableFrom(overrideLookupClass)) {
293: throw new ClassValidationException(
294: "overrideLookupClass '"
295: + overrideLookupClass
296: + "' is not a subclasss of BusinessObject ("
297: + getParseLocation() + ")");
298: }
299: }
300: }
301:
302: /**
303: * @see java.lang.Object#toString()
304: */
305: public String toString() {
306: return "MaintainableFieldDefinition for field " + getName();
307: }
308:
309: public String getTemplate() {
310: return template;
311: }
312:
313: public void setTemplate(String template) {
314: this .template = template;
315: }
316:
317: public String getWebUILeaveFieldCallbackFunction() {
318: return webUILeaveFieldCallbackFunction;
319: }
320:
321: public void setWebUILeaveFieldCallbackFunction(
322: String webUILeaveFieldCallbackFunction) {
323: this .webUILeaveFieldCallbackFunction = webUILeaveFieldCallbackFunction;
324: }
325:
326: public String getWebUILeaveFieldFunction() {
327: return webUILeaveFieldFunction;
328: }
329:
330: public void setWebUILeaveFieldFunction(
331: String webUILeaveFieldFunction) {
332: this .webUILeaveFieldFunction = webUILeaveFieldFunction;
333: }
334:
335: public boolean isReadOnlyAfterAdd() {
336: return readOnlyAfterAdd;
337: }
338:
339: public void setReadOnlyAfterAdd(boolean readOnlyAfterAdd) {
340: this.readOnlyAfterAdd = readOnlyAfterAdd;
341: }
342: }
|