01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.kuali.core.datadictionary;
18:
19: import org.apache.commons.lang.StringUtils;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22: import org.kuali.core.datadictionary.exception.AttributeValidationException;
23:
24: /**
25: * Contains an attribute name for use doing sorting.
26: *
27: * Note: the setters do copious amounts of validation, to facilitate generating errors during the parsing process.
28: *
29: *
30: */
31: public class SortAttributeDefinition extends
32: DataDictionaryDefinitionBase {
33: // logger
34: private static Log LOG = LogFactory
35: .getLog(SortAttributeDefinition.class);
36:
37: private String attributeName;
38:
39: public SortAttributeDefinition() {
40: LOG.debug("creating new SortAttributeDefinition");
41: }
42:
43: /**
44: * @return attributeName
45: */
46: public String getAttributeName() {
47: return attributeName;
48: }
49:
50: /**
51: * Sets attributeName to the given value.
52: *
53: * @param attributeName
54: * @throws IllegalArgumentException if the given attributeName is blank
55: */
56: public void setAttributeName(String attributeName) {
57: if (StringUtils.isBlank(attributeName)) {
58: throw new IllegalArgumentException(
59: "invalid (blank) attributeName");
60: }
61: LOG.debug("calling setAttributeName '" + attributeName + "'");
62:
63: this .attributeName = attributeName;
64: }
65:
66: /**
67: * Directly validate simple fields.
68: *
69: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
70: */
71: public void completeValidation(Class rootBusinessObjectClass,
72: Class otherBusinessObjectClass,
73: ValidationCompletionUtils validationCompletionUtils) {
74: if (!validationCompletionUtils.isPropertyOf(
75: rootBusinessObjectClass, attributeName)) {
76: throw new AttributeValidationException(
77: "unable to find attribute '" + attributeName
78: + "' in rootBusinessObjectClass '"
79: + rootBusinessObjectClass.getName() + "' ("
80: + getParseLocation() + ")");
81: }
82: }
83:
84: /**
85: * @see java.lang.Object#toString()
86: */
87: public String toString() {
88: return "SortAttributeDefinition for attribute "
89: + getAttributeName();
90: }
91: }
|