001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.query.core; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.commons.logging.Log; 023import org.apache.commons.logging.LogFactory; 024import org.nuxeo.ecm.platform.query.api.PageProviderDefinition; 025import org.nuxeo.runtime.model.ContributionFragmentRegistry; 026 027/** 028 * Registry for page provider contributions. 029 * 030 * @since 5.6 031 */ 032public class PageProviderRegistry extends ContributionFragmentRegistry<PageProviderDefinition> { 033 034 private static final Log log = LogFactory.getLog(PageProviderRegistry.class); 035 036 protected Map<String, PageProviderDefinition> providers = new HashMap<String, PageProviderDefinition>(); 037 038 @Override 039 public String getContributionId(PageProviderDefinition contrib) { 040 return contrib.getName(); 041 } 042 043 @Override 044 public void contributionUpdated(String id, PageProviderDefinition desc, PageProviderDefinition newOrigContrib) { 045 String name = desc.getName(); 046 if (name == null) { 047 log.error("Cannot register page provider without a name"); 048 return; 049 } 050 boolean enabled = desc.isEnabled(); 051 if (enabled) { 052 log.info("Registering page provider with name " + name); 053 providers.put(name, desc); 054 } else { 055 contributionRemoved(id, desc); 056 } 057 } 058 059 @Override 060 public void contributionRemoved(String id, PageProviderDefinition origContrib) { 061 providers.remove(id); 062 log.info("Unregistering page provider with name " + id); 063 } 064 065 @Override 066 public boolean isSupportingMerge() { 067 return false; 068 } 069 070 @Override 071 public PageProviderDefinition clone(PageProviderDefinition orig) { 072 throw new UnsupportedOperationException(); 073 } 074 075 @Override 076 public void merge(PageProviderDefinition src, PageProviderDefinition dst) { 077 throw new UnsupportedOperationException(); 078 } 079 080 // API 081 082 public PageProviderDefinition getPageProvider(String id) { 083 return providers.get(id); 084 } 085 086}