# HG changeset patch # User Sascha L. Teichmann # Date 1343561920 0 # Node ID e1738650bfcac090755d366face1c68a7da18d0f # Parent 4c78c5d2b367b939ca9624a1cd2a1f155e2fffec FacetActivity: use Chain-of-responsibility pattern to figure out if facet should be active. artifacts/trunk@5154 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4c78c5d2b367 -r e1738650bfca ChangeLog --- a/ChangeLog Sun Jul 29 09:48:05 2012 +0000 +++ b/ChangeLog Sun Jul 29 11:38:40 2012 +0000 @@ -1,3 +1,9 @@ +2012-07-29 Sascha L. Teichmann + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java: + Refactored registry to use a Chain-of-responsibility pattern. This allows + de-centralized facet activity treatment like in the facet producing states. + 2012-07-29 Sascha L. Teichmann * artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java: diff -r 4c78c5d2b367 -r e1738650bfca artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java Sun Jul 29 09:48:05 2012 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java Sun Jul 29 11:38:40 2012 +0000 @@ -2,56 +2,78 @@ import de.intevation.artifacts.Artifact; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; public interface FacetActivity { public static final FacetActivity ACTIVE = new FacetActivity() { @Override - public boolean isInitialActive( + public Boolean isInitialActive( Artifact artifact, Facet facet, String output ) { - return true; + return Boolean.TRUE; } }; public static final FacetActivity INACTIVE = new FacetActivity() { @Override - public boolean isInitialActive( + public Boolean isInitialActive( Artifact artifact, Facet facet, String output ) { - return false; + return Boolean.FALSE; } }; - boolean isInitialActive(Artifact artifact, Facet facet, String output); + Boolean isInitialActive(Artifact artifact, Facet facet, String output); public static final class Registry { private static final Registry INSTANCE = new Registry(); - private Map activities; + private Map> activities; private Registry() { - activities = new HashMap(); + activities = new HashMap>(); } public static Registry getInstance() { return INSTANCE; } - public synchronized FacetActivity getActivity(String key) { - FacetActivity activity = activities.get(key); - return activity != null ? activity : ACTIVE; + public synchronized boolean isInitialActive( + String key, + Artifact artifact, + Facet facet, + String output + ) { + List activityList = activities.get(key); + if (activityList == null) { + return true; + } + for (FacetActivity activity: activityList) { + Boolean isActive = + activity.isInitialActive(artifact, facet, output); + if (isActive != null) { + return isActive; + } + } + return true; } public synchronized void register(String key, FacetActivity activity) { - activities.put(key, activity); + List activityList = activities.get(key); + if (activityList == null) { + activityList = new ArrayList(3); + activities.put(key, activityList); + } + activityList.add(activity); } } }