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