1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.api.criteria;
17
18 import org.kuali.rice.core.api.CoreConstants;
19 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20 import org.kuali.rice.core.api.mo.ModelBuilder;
21 import org.kuali.rice.core.api.util.collect.CollectionUtils;
22 import org.w3c.dom.Element;
23
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAnyElement;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlElementWrapper;
29 import javax.xml.bind.annotation.XmlElements;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import javax.xml.bind.annotation.XmlType;
32 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33 import java.io.Serializable;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.Collection;
37 import java.util.List;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 @XmlRootElement(name = OrderByField.Constants.ROOT_ELEMENT_NAME)
62 @XmlAccessorType(XmlAccessType.NONE)
63 @XmlType(name = OrderByField.Constants.TYPE_NAME, propOrder = {
64 OrderByField.Elements.FIELD_NAME,
65 OrderByField.Elements.ORDER_DIRECTION,
66 CoreConstants.CommonElements.FUTURE_ELEMENTS })
67 public final class OrderByField extends AbstractDataTransferObject {
68
69 private static final long serialVersionUID = 2210627777648920185L;
70
71 @XmlElement(name = Elements.FIELD_NAME, required = true)
72 private final String fieldName;
73
74 @XmlJavaTypeAdapter(OrderDirection.Adapter.class)
75 @XmlElement(name = Elements.ORDER_DIRECTION, required = true)
76 private final String orderDirection;
77
78 @SuppressWarnings("unused")
79 @XmlAnyElement
80 private final Collection<Element> _futureElements = null;
81
82 private OrderByField() {
83 this.fieldName = null;
84 this.orderDirection = null;
85 }
86
87 private OrderByField(Builder builder) {
88 this.fieldName = builder.getFieldName();
89 this.orderDirection = builder.getOrderDirection() == null ? null : builder.getOrderDirection().getDirection();
90 }
91
92
93
94
95
96
97
98 public String getFieldName() {
99 return this.fieldName;
100 }
101
102
103
104
105
106
107 public OrderDirection getOrderDirection() {
108 return this.orderDirection == null ? null : OrderDirection.valueOf(this.orderDirection);
109 }
110
111
112 public static final class Builder implements ModelBuilder, Serializable {
113
114 private String fieldName;
115 private OrderDirection orderDirection;
116
117 private Builder() {
118 setOrderDirection(OrderDirection.ASCENDING);
119 }
120
121 private Builder(String fieldName, OrderDirection orderDirection) {
122 setOrderDirection(orderDirection);
123 setFieldName(fieldName);
124 }
125
126 public static Builder create() {
127 return new Builder();
128 }
129
130 public static Builder create(String fieldName, OrderDirection orderDirection) {
131 return new Builder(fieldName, orderDirection);
132 }
133
134 public OrderDirection getOrderDirection() {
135 return this.orderDirection;
136 }
137
138 public void setOrderDirection(OrderDirection orderDirection) {
139 if (orderDirection == null) {
140 throw new IllegalArgumentException("orderDirection was null");
141 }
142 this.orderDirection = orderDirection;
143 }
144
145 public String getFieldName() {
146 return this.fieldName;
147 }
148
149 public void setFieldName(String fieldName) {
150 if (fieldName == null) {
151 throw new IllegalArgumentException("fieldName was null");
152 }
153 this.fieldName = fieldName;
154 }
155
156
157
158 @Override
159 public OrderByField build() {
160 return new OrderByField(this);
161 }
162
163 }
164
165
166
167
168 static class Constants {
169 final static String ROOT_ELEMENT_NAME = "orderByField";
170 final static String TYPE_NAME = "OrderByFieldType";
171 }
172
173
174
175
176
177 static class Elements {
178 final static String FIELD_NAME = "fieldName";
179 final static String ORDER_DIRECTION = "orderDirection";
180 }
181
182 }