Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CacheTarget |
|
| 1.5714285714285714;1.571 | ||||
CacheTarget$Constants |
|
| 1.5714285714285714;1.571 | ||||
CacheTarget$Elements |
|
| 1.5714285714285714;1.571 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | * A class that represents a target of a cache operation. If the cache key | |
40 | * is not specified then the entire cache is the target. | |
41 | */ | |
42 | public final class CacheTarget extends AbstractDataTransferObject { | |
43 | ||
44 | @XmlElement(name = Elements.CACHE, required = true) | |
45 | private final String cache; | |
46 | @XmlElement(name = Elements.KEY, required = false) | |
47 | private final String key; | |
48 | 0 | @SuppressWarnings("unused") |
49 | @XmlAnyElement | |
50 | private final Collection<Element> _futureElements = null; | |
51 | ||
52 | /** | |
53 | * This constructor should never be called except during JAXB unmarshalling. | |
54 | */ | |
55 | 0 | private CacheTarget() { |
56 | 0 | this.cache = null; |
57 | 0 | this.key = null; |
58 | 0 | } |
59 | ||
60 | 0 | private CacheTarget(String cache, String key) { |
61 | 0 | if (StringUtils.isBlank(cache)) { |
62 | 0 | throw new IllegalArgumentException("cache is blank or null"); |
63 | } | |
64 | ||
65 | 0 | this.cache = cache; |
66 | 0 | this.key = key; |
67 | 0 | } |
68 | ||
69 | /** | |
70 | * Creates an instance targeting a entire cache. | |
71 | * @param cache the name of the cache. cannot be a null of blank string. | |
72 | * @return an instance | |
73 | * @throws IllegalArgumentException if the cache is null or blank | |
74 | */ | |
75 | public static CacheTarget entireCache(String cache) { | |
76 | 0 | return new CacheTarget(cache, null); |
77 | } | |
78 | ||
79 | /** | |
80 | * Creates an instance targeting a single item in a cache. | |
81 | * @param cache The name of the cache. cannot be a null of blank string. | |
82 | * @param key The key of the item in the cache. cannot be a null of blank string. | |
83 | * @return an instance | |
84 | * @throws IllegalArgumentException if the cache or key is null or blank | |
85 | */ | |
86 | public static CacheTarget singleEntry(String cache, String key) { | |
87 | 0 | if (StringUtils.isBlank(key)) { |
88 | 0 | throw new IllegalArgumentException("a blank or null key does not target a single entry"); |
89 | } | |
90 | ||
91 | 0 | return new CacheTarget(cache, key); |
92 | } | |
93 | ||
94 | /** | |
95 | * Checks if an instance contains a key. | |
96 | * @return true if a key exists | |
97 | */ | |
98 | public boolean containsKey() { | |
99 | 0 | return key != null; |
100 | } | |
101 | ||
102 | /** | |
103 | * The name of the cache to target. will not return a null of blank string. | |
104 | * @return the name. | |
105 | */ | |
106 | public String getCache() { | |
107 | 0 | return cache; |
108 | } | |
109 | ||
110 | /** | |
111 | * The key of an item in the cache. optional. can return null or blank string. | |
112 | * @return the key | |
113 | */ | |
114 | public String getKey() { | |
115 | 0 | return key; |
116 | } | |
117 | ||
118 | /** | |
119 | * Defines some internal constants used on this class. | |
120 | */ | |
121 | 0 | static class Constants { |
122 | final static String ROOT_ELEMENT_NAME = "cacheTarget"; | |
123 | final static String TYPE_NAME = "CacheTargetType"; | |
124 | } | |
125 | ||
126 | /** | |
127 | * A private class which exposes constants which define the XML element names to use | |
128 | * when this object is marshalled to XML. | |
129 | */ | |
130 | 0 | static class Elements { |
131 | final static String CACHE = "cache"; | |
132 | final static String KEY = "key"; | |
133 | } | |
134 | } |