view artifact-database/src/main/java/de/intevation/artifactdatabase/state/FacetActivity.java @ 430:bedc87d11596

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:13 +0200
parents e1738650bfca
children 15179c77aa1d
line wrap: on
line source
package de.intevation.artifactdatabase.state;

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(
            Artifact artifact,
            Facet    facet,
            String   output
        ) {
            return Boolean.TRUE;
        }
    };

    public static final FacetActivity INACTIVE = new FacetActivity() {
        @Override
        public Boolean isInitialActive(
            Artifact artifact,
            Facet    facet,
            String   output
        ) {
            return Boolean.FALSE;
        }
    };

    Boolean isInitialActive(Artifact artifact, Facet facet, String output);

    public static final class Registry {

        private static final Registry INSTANCE = new Registry();

        private Map<String, List<FacetActivity>> activities;

        private Registry() {
            activities = new HashMap<String, List<FacetActivity>>();
        }

        public static Registry getInstance() {
            return INSTANCE;
        }

        public synchronized boolean isInitialActive(
            String   key,
            Artifact artifact,
            Facet    facet,
            String   output
        ) {
            List<FacetActivity> 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) {
            List<FacetActivity> activityList = activities.get(key);
            if (activityList == null) {
                activityList = new ArrayList<FacetActivity>(3);
                activities.put(key, activityList);
            }
            activityList.add(activity);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org