annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CacheInvalidationService.java @ 2204:45f7762767e2

Bugfix: use correct order of parameters to call DefaultStateData constructor. flys-artifacts/trunk@3828 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Jan 2012 13:23:40 +0000
parents 0ccabd82ec76
children 247f3e98a14b
rev   line source
2092
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import de.intevation.artifacts.CallMeta;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import de.intevation.artifacts.GlobalContext;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import de.intevation.artifacts.common.utils.XMLUtils;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import de.intevation.artifactdatabase.DefaultService;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.cache.CacheFactory;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import net.sf.ehcache.Cache;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import org.w3c.dom.Document;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import org.w3c.dom.Element;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.w3c.dom.NodeList;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class CacheInvalidationService
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 extends DefaultService
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 @Override
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public Document process(
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 Document data,
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 GlobalContext globalContext,
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 CallMeta callMeta
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 ) {
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 Document result = XMLUtils.newDocument();
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 Element all = result.createElement("caches");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 NodeList caches = data.getElementsByTagName("cache");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 for (int i = 0, C = caches.getLength(); i < C; ++i) {
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 Element c = (Element)caches.item(i);
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 String name = c.getAttribute("name");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 Element e = result.createElement("cache");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 e.setAttribute("name", name);
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 Cache cache = CacheFactory.getCache(name);
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 if (cache != null) {
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 cache.removeAll();
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 e.setTextContent("All elements removed.");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 else {
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 e.setTextContent("Error: Cache not found.");
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 all.appendChild(e);
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 result.appendChild(all);
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return result;
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
0ccabd82ec76 Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org