annotate artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java @ 471:1a87cb24a446

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 10:50:31 +0200
parents f503374f516c
children
rev   line source
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.artifactdatabase.state;
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import de.intevation.artifacts.Artifact;
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
5 import java.util.ArrayList;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.HashMap;
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
7 import java.util.List;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.util.Map;
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
10 import org.apache.log4j.Logger;
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
11
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
12
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
13 /**
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
14 * System used in practice used by AttributeWriter in flys-artifacts to decide
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
15 * whether a facet is initially active.
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
16 * Provides a singleton Registry into which FacetActivities can be registered
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
17 * under a key (in practice the artifacts name. This Registry is queried for
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
18 * new Facets in order to find whether they are active or inactive.
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
19 */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public interface FacetActivity
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 {
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
22 /** Static 'activity' that lets all facets be active. */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public static final FacetActivity ACTIVE = new FacetActivity() {
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 @Override
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
25 public Boolean isInitialActive(
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 Artifact artifact,
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 Facet facet,
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 String output
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 ) {
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
30 return Boolean.TRUE;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 };
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
34 /** Static 'activity' that lets all facets be inactive. */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public static final FacetActivity INACTIVE = new FacetActivity() {
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 @Override
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
37 public Boolean isInitialActive(
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 Artifact artifact,
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 Facet facet,
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 String output
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 ) {
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
42 return Boolean.FALSE;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 };
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
46 Boolean isInitialActive(Artifact artifact, Facet facet, String output);
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
48 /** Singleton registry, that maps artifact names to the activities, which
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
49 * decide whether or not a facet should be (initially) active. */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public static final class Registry {
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
52 /** The logger for this class. */
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
53 private static Logger logger = Logger.getLogger(Registry.class);
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
54
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
55 /** Singleton instance. */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 private static final Registry INSTANCE = new Registry();
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
58 /** Map of keys (artifact names) to the activities. */
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
59 private Map<String, List<FacetActivity>> activities;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
61 /** Private singleton constructor for the Facet-Activity-Registry. */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 private Registry() {
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
63 activities = new HashMap<String, List<FacetActivity>>();
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
66 /** Access Singleton instance. */
404
4c78c5d2b367 FacetActivity: Made Registry.getInstance() access static.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 403
diff changeset
67 public static Registry getInstance() {
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return INSTANCE;
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
436
15179c77aa1d Documentation, so that readers know a tiny bit more what is going on.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 405
diff changeset
71 /** Queries whether a given facet should be active or not. */
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
72 public synchronized boolean isInitialActive(
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
73 String key,
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
74 Artifact artifact,
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
75 Facet facet,
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
76 String output
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
77 ) {
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
78 List<FacetActivity> activityList = activities.get(key);
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
79 if (activityList == null) {
443
f503374f516c Make it compile again by syntax fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 438
diff changeset
80 logger.debug("FacetActivity.Registry: No activity " +
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
81 "registered for " + key);
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
82 return true;
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
83 }
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
84 if (activityList.size() != 1) {
443
f503374f516c Make it compile again by syntax fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 438
diff changeset
85 logger.warn("FacetActivity.Registry: More than one " +
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
86 "FacetActivity registered for " + key);
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
87 }
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
88 for (FacetActivity activity: activityList) {
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
89 Boolean isActive =
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
90 activity.isInitialActive(artifact, facet, output);
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
91 // Nice. Only, in practice they never return NULL.
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
92 if (isActive != null) {
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
93 return isActive;
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
94 }
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
95 }
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
96 return true;
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
438
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
99
f3bf22423c95 More documentation and debugging output for FacetActivity System.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 436
diff changeset
100 /** Add a FacetActivity under given key (usually artifacts name). */
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 public synchronized void register(String key, FacetActivity activity) {
405
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
102 List<FacetActivity> activityList = activities.get(key);
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
103 if (activityList == null) {
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
104 activityList = new ArrayList<FacetActivity>(3);
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
105 activities.put(key, activityList);
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
106 }
e1738650bfca FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 404
diff changeset
107 activityList.add(activity);
403
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 }
bd76529d612b FacetActivity: Added interface and registry to decide if a facet should initially active or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org