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.apache.commons.lang.builder.EqualsBuilder;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.apache.commons.lang.builder.ToStringBuilder;
21 import org.joda.time.DateTime;
22 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
23
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import javax.xml.bind.annotation.XmlType;
28 import javax.xml.bind.annotation.XmlValue;
29 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30 import java.util.Calendar;
31 import java.util.Date;
32
33
34
35
36
37
38
39 @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME)
40 @XmlAccessorType(XmlAccessType.NONE)
41 @XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME)
42 public final class CriteriaDateTimeValue implements CriteriaValue<DateTime> {
43
44 @XmlValue
45 @XmlJavaTypeAdapter(DateTimeAdapter.class)
46 private final DateTime value;
47
48 CriteriaDateTimeValue() {
49 this.value = null;
50 }
51
52 CriteriaDateTimeValue(DateTime value) {
53 validateValue(value);
54 this.value = value;
55 }
56
57 CriteriaDateTimeValue(Calendar value) {
58 validateValue(value);
59 this.value = new DateTime(value.getTimeInMillis());
60 }
61
62 CriteriaDateTimeValue(Date value) {
63 validateValue(value);
64 this.value = new DateTime(value.getTime());
65 }
66
67 private static void validateValue(Object value) {
68 if (value == null) {
69 throw new IllegalArgumentException("Value cannot be null.");
70 }
71 }
72
73 @Override
74 public DateTime getValue() {
75
76 return value;
77 }
78
79 @Override
80 public int hashCode() {
81 return HashCodeBuilder.reflectionHashCode(this);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 return EqualsBuilder.reflectionEquals(obj, this);
87 }
88
89 @Override
90 public String toString() {
91 return ToStringBuilder.reflectionToString(this);
92 }
93
94
95
96
97 static class Constants {
98 final static String ROOT_ELEMENT_NAME = "dateTimeValue";
99 final static String TYPE_NAME = "CriteriaDateTimeValueType";
100 }
101
102 }