|
48 | 48 | */ |
49 | 49 | class CacheAdviceParser extends AbstractSingleBeanDefinitionParser { |
50 | 50 |
|
51 | | - /** |
52 | | - * Simple, reusable class used for overriding defaults. |
53 | | - * |
54 | | - * @author Costin Leau |
55 | | - */ |
56 | | - private static class Props { |
57 | | - |
58 | | - private String key; |
59 | | - private String condition; |
60 | | - private String method; |
61 | | - private String[] caches = null; |
62 | | - |
63 | | - Props(Element root) { |
64 | | - String defaultCache = root.getAttribute("cache"); |
65 | | - key = root.getAttribute("key"); |
66 | | - condition = root.getAttribute("condition"); |
67 | | - method = root.getAttribute(METHOD_ATTRIBUTE); |
68 | | - |
69 | | - if (StringUtils.hasText(defaultCache)) { |
70 | | - caches = StringUtils.commaDelimitedListToStringArray(defaultCache.trim()); |
71 | | - } |
72 | | - } |
73 | | - |
74 | | - <T extends CacheOperation> T merge(Element element, ReaderContext readerCtx, T op) { |
75 | | - String cache = element.getAttribute("cache"); |
76 | | - |
77 | | - // sanity check |
78 | | - String[] localCaches = caches; |
79 | | - if (StringUtils.hasText(cache)) { |
80 | | - localCaches = StringUtils.commaDelimitedListToStringArray(cache.trim()); |
81 | | - } else { |
82 | | - if (caches == null) { |
83 | | - readerCtx.error("No cache specified specified for " + element.getNodeName(), element); |
84 | | - } |
85 | | - } |
86 | | - op.setCacheNames(localCaches); |
87 | | - |
88 | | - op.setKey(getAttributeValue(element, "key", this.key)); |
89 | | - op.setCondition(getAttributeValue(element, "condition", this.condition)); |
90 | | - |
91 | | - return op; |
92 | | - } |
93 | | - |
94 | | - String merge(Element element, ReaderContext readerCtx) { |
95 | | - String m = element.getAttribute(METHOD_ATTRIBUTE); |
96 | | - |
97 | | - if (StringUtils.hasText(m)) { |
98 | | - return m.trim(); |
99 | | - } |
100 | | - if (StringUtils.hasText(method)) { |
101 | | - return method; |
102 | | - } |
103 | | - readerCtx.error("No method specified for " + element.getNodeName(), element); |
104 | | - return null; |
105 | | - } |
106 | | - } |
107 | | - |
108 | 51 | private static final String CACHEABLE_ELEMENT = "cacheable"; |
| 52 | + |
109 | 53 | private static final String CACHE_EVICT_ELEMENT = "cache-evict"; |
| 54 | + |
110 | 55 | private static final String CACHE_PUT_ELEMENT = "cache-put"; |
| 56 | + |
111 | 57 | private static final String METHOD_ATTRIBUTE = "method"; |
| 58 | + |
112 | 59 | private static final String DEFS_ELEMENT = "caching"; |
113 | 60 |
|
| 61 | + |
114 | 62 | @Override |
115 | 63 | protected Class<?> getBeanClass(Element element) { |
116 | 64 | return CacheInterceptor.class; |
@@ -226,4 +174,66 @@ private static String getAttributeValue(Element element, String attributeName, S |
226 | 174 | return defaultValue; |
227 | 175 | } |
228 | 176 |
|
| 177 | + |
| 178 | + /** |
| 179 | + * Simple, reusable class used for overriding defaults. |
| 180 | + * |
| 181 | + * @author Costin Leau |
| 182 | + */ |
| 183 | + private static class Props { |
| 184 | + |
| 185 | + private String key; |
| 186 | + |
| 187 | + private String condition; |
| 188 | + |
| 189 | + private String method; |
| 190 | + |
| 191 | + private String[] caches = null; |
| 192 | + |
| 193 | + |
| 194 | + Props(Element root) { |
| 195 | + String defaultCache = root.getAttribute("cache"); |
| 196 | + key = root.getAttribute("key"); |
| 197 | + condition = root.getAttribute("condition"); |
| 198 | + method = root.getAttribute(METHOD_ATTRIBUTE); |
| 199 | + |
| 200 | + if (StringUtils.hasText(defaultCache)) { |
| 201 | + caches = StringUtils.commaDelimitedListToStringArray(defaultCache.trim()); |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + |
| 206 | + <T extends CacheOperation> T merge(Element element, ReaderContext readerCtx, T op) { |
| 207 | + String cache = element.getAttribute("cache"); |
| 208 | + |
| 209 | + // sanity check |
| 210 | + String[] localCaches = caches; |
| 211 | + if (StringUtils.hasText(cache)) { |
| 212 | + localCaches = StringUtils.commaDelimitedListToStringArray(cache.trim()); |
| 213 | + } else { |
| 214 | + if (caches == null) { |
| 215 | + readerCtx.error("No cache specified specified for " + element.getNodeName(), element); |
| 216 | + } |
| 217 | + } |
| 218 | + op.setCacheNames(localCaches); |
| 219 | + |
| 220 | + op.setKey(getAttributeValue(element, "key", this.key)); |
| 221 | + op.setCondition(getAttributeValue(element, "condition", this.condition)); |
| 222 | + |
| 223 | + return op; |
| 224 | + } |
| 225 | + |
| 226 | + String merge(Element element, ReaderContext readerCtx) { |
| 227 | + String m = element.getAttribute(METHOD_ATTRIBUTE); |
| 228 | + |
| 229 | + if (StringUtils.hasText(m)) { |
| 230 | + return m.trim(); |
| 231 | + } |
| 232 | + if (StringUtils.hasText(method)) { |
| 233 | + return method; |
| 234 | + } |
| 235 | + readerCtx.error("No method specified for " + element.getNodeName(), element); |
| 236 | + return null; |
| 237 | + } |
| 238 | + } |
229 | 239 | } |
0 commit comments