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

Implement ArtifactDatabase findUser method artifacts/trunk@5262 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 24 Aug 2012 14:08:31 +0000
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