001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id: ActionFilterRegistry.java 20637 2007-06-17 12:37:03Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.actions; 023 024import java.io.Serializable; 025import java.util.Collection; 026import java.util.Collections; 027import java.util.HashMap; 028import java.util.Map; 029 030import org.apache.commons.logging.Log; 031import org.apache.commons.logging.LogFactory; 032 033/** 034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 035 */ 036public class ActionFilterRegistry implements Serializable { 037 038 private static final Log log = LogFactory.getLog(ActionFilterRegistry.class); 039 040 private static final long serialVersionUID = 1L; 041 042 private final Map<String, ActionFilter> filters; 043 044 public ActionFilterRegistry() { 045 filters = new HashMap<String, ActionFilter>(); 046 } 047 048 public synchronized void addFilter(ActionFilter filter) { 049 String id = filter.getId(); 050 if (log.isDebugEnabled()) { 051 if (filters.containsKey(id)) { 052 log.debug("Overriding action filter: " + id); 053 } else { 054 log.debug("Registering action filter: " + id); 055 } 056 } 057 filters.put(id, filter); 058 } 059 060 public synchronized ActionFilter removeFilter(String id) { 061 if (log.isDebugEnabled()) { 062 log.debug("Un-Registering action filter: " + id); 063 } 064 065 return filters.remove(id); 066 } 067 068 public synchronized Collection<ActionFilter> getFilters() { 069 return Collections.unmodifiableCollection(filters.values()); 070 } 071 072 public synchronized ActionFilter getFilter(String id) { 073 return filters.get(id); 074 } 075 076}