1 | |
package org.kuali.rice.core.api.cache; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.kuali.rice.core.api.CoreConstants; |
5 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
6 | |
import org.w3c.dom.Element; |
7 | |
|
8 | |
import javax.xml.bind.annotation.XmlAccessType; |
9 | |
import javax.xml.bind.annotation.XmlAccessorType; |
10 | |
import javax.xml.bind.annotation.XmlAnyElement; |
11 | |
import javax.xml.bind.annotation.XmlElement; |
12 | |
import javax.xml.bind.annotation.XmlRootElement; |
13 | |
import javax.xml.bind.annotation.XmlType; |
14 | |
import java.util.Collection; |
15 | |
|
16 | |
@XmlRootElement(name = CacheTarget.Constants.ROOT_ELEMENT_NAME) |
17 | |
@XmlAccessorType(XmlAccessType.NONE) |
18 | |
@XmlType(name = CacheTarget.Constants.TYPE_NAME, propOrder = { |
19 | |
CacheTarget.Elements.CACHE, |
20 | |
CacheTarget.Elements.KEY, |
21 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
22 | |
}) |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public final class CacheTarget extends AbstractDataTransferObject { |
28 | |
|
29 | |
@XmlElement(name = Elements.CACHE, required = true) |
30 | |
private final String cache; |
31 | |
@XmlElement(name = Elements.KEY, required = false) |
32 | |
private final String key; |
33 | 0 | @SuppressWarnings("unused") |
34 | |
@XmlAnyElement |
35 | |
private final Collection<Element> _futureElements = null; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | private CacheTarget() { |
41 | 0 | this.cache = null; |
42 | 0 | this.key = null; |
43 | 0 | } |
44 | |
|
45 | 0 | private CacheTarget(String cache, String key) { |
46 | 0 | if (StringUtils.isBlank(cache)) { |
47 | 0 | throw new IllegalArgumentException("cache is blank or null"); |
48 | |
} |
49 | |
|
50 | 0 | this.cache = cache; |
51 | 0 | this.key = key; |
52 | 0 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public static CacheTarget entireCache(String cache) { |
61 | 0 | return new CacheTarget(cache, null); |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public static CacheTarget singleEntry(String cache, String key) { |
72 | 0 | if (StringUtils.isBlank(key)) { |
73 | 0 | throw new IllegalArgumentException("a blank or null key does not target a single entry"); |
74 | |
} |
75 | |
|
76 | 0 | return new CacheTarget(cache, key); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public boolean containsKey() { |
84 | 0 | return key != null; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public String getCache() { |
92 | 0 | return cache; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public String getKey() { |
100 | 0 | return key; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | 0 | static class Constants { |
107 | |
final static String ROOT_ELEMENT_NAME = "cacheTarget"; |
108 | |
final static String TYPE_NAME = "CacheTargetType"; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | 0 | static class Elements { |
116 | |
final static String CACHE = "cache"; |
117 | |
final static String KEY = "key"; |
118 | |
} |
119 | |
} |