1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.api.cache;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
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 java.util.Collection;
30
31 @XmlRootElement(name = CacheTarget.Constants.ROOT_ELEMENT_NAME)
32 @XmlAccessorType(XmlAccessType.NONE)
33 @XmlType(name = CacheTarget.Constants.TYPE_NAME, propOrder = {
34 CacheTarget.Elements.CACHE,
35 CacheTarget.Elements.KEY,
36 CoreConstants.CommonElements.FUTURE_ELEMENTS
37 })
38
39
40
41
42
43
44
45 public final class CacheTarget extends AbstractDataTransferObject {
46
47 private static final long serialVersionUID = -7143135771254777648L;
48
49 @XmlElement(name = Elements.CACHE, required = true)
50 private final String cache;
51
52 @XmlElement(name = Elements.KEY, required = false)
53 private final String key;
54
55 @SuppressWarnings("unused")
56 @XmlAnyElement
57 private final Collection<Element> _futureElements = null;
58
59
60
61
62 @SuppressWarnings("unused")
63 private CacheTarget() {
64 this.cache = null;
65 this.key = null;
66 }
67
68 private CacheTarget(String cache, String key) {
69 if (StringUtils.isBlank(cache)) {
70 throw new IllegalArgumentException("cache is blank or null");
71 }
72 this.cache = cache;
73 this.key = key;
74 }
75
76
77
78
79
80
81
82
83
84
85 public static CacheTarget entireCache(String cache) {
86 return new CacheTarget(cache, null);
87 }
88
89
90
91
92
93
94
95
96
97
98
99 public static CacheTarget singleEntry(String cache, String key) {
100 if (StringUtils.isBlank(key)) {
101 throw new IllegalArgumentException("a blank or null key does not target a single entry");
102 }
103 return new CacheTarget(cache, key);
104 }
105
106
107
108
109
110
111 public boolean containsKey() {
112 return key != null;
113 }
114
115
116
117
118
119
120 public String getCache() {
121 return cache;
122 }
123
124
125
126
127
128
129
130 public String getKey() {
131 return key;
132 }
133
134
135
136
137 static class Constants {
138 final static String ROOT_ELEMENT_NAME = "cacheTarget";
139 final static String TYPE_NAME = "CacheTargetType";
140 }
141
142
143
144
145
146 static class Elements {
147 final static String CACHE = "cache";
148 final static String KEY = "key";
149 }
150
151 }