1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class SortDefinition extends DataDictionaryDefinitionBase {
40 private static final long serialVersionUID = -1092811342186612461L;
41
42 protected boolean sortAscending = true;
43 protected List<String> attributeNames = new ArrayList<String>();
44
45 public SortDefinition() {}
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public void setAttributeName(String attributeName) {
65 if (StringUtils.isBlank(attributeName)) {
66 throw new IllegalArgumentException("invalid (blank) attributeName");
67 }
68 if (attributeNames.size() != 0) {
69 throw new IllegalStateException("unable to set sort attributeName when sortAttributes have already been added");
70 }
71
72 attributeNames.add(attributeName);
73 }
74
75
76
77
78 public List<String> getAttributeNames() {
79 return this.attributeNames;
80 }
81
82
83
84
85
86 public boolean getSortAscending() {
87 return sortAscending;
88 }
89
90 public void setSortAscending(boolean sortAscending) {
91 this.sortAscending = sortAscending;
92 }
93
94
95
96
97
98
99
100 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
101 for ( String attributeName : attributeNames ) {
102 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeName)) {
103 throw new AttributeValidationException("unable to find sort attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
104 }
105 }
106 }
107
108
109
110
111
112 public String toString() {
113 StringBuffer attrList = new StringBuffer("[");
114 for (Iterator<String> i = attributeNames.iterator(); i.hasNext();) {
115 attrList.append(i.next());
116 if (i.hasNext()) {
117 attrList.append(",");
118 }
119 }
120 attrList.append("]");
121
122 return "SortDefinition : " + attrList.toString();
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136 public void setAttributeNames(List<String> attributeNames) {
137 this.attributeNames = attributeNames;
138 }
139
140 }