001/* 002 * (C) Copyright 2012 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 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.query.core; 020 021import java.util.HashMap; 022import java.util.Map; 023 024import org.apache.commons.logging.Log; 025import org.apache.commons.logging.LogFactory; 026import org.nuxeo.ecm.platform.query.api.PageProviderDefinition; 027import org.nuxeo.runtime.model.ContributionFragmentRegistry; 028 029/** 030 * Registry for page provider contributions. 031 * 032 * @since 5.6 033 */ 034public class PageProviderRegistry extends ContributionFragmentRegistry<PageProviderDefinition> { 035 036 private static final Log log = LogFactory.getLog(PageProviderRegistry.class); 037 038 protected Map<String, PageProviderDefinition> providers = new HashMap<String, PageProviderDefinition>(); 039 040 @Override 041 public String getContributionId(PageProviderDefinition contrib) { 042 return contrib.getName(); 043 } 044 045 @Override 046 public void contributionUpdated(String id, PageProviderDefinition desc, PageProviderDefinition newOrigContrib) { 047 String name = desc.getName(); 048 if (name == null) { 049 log.error("Cannot register page provider without a name"); 050 return; 051 } 052 boolean enabled = desc.isEnabled(); 053 if (enabled) { 054 log.info("Registering page provider with name " + name); 055 providers.put(name, desc); 056 } else { 057 contributionRemoved(id, desc); 058 } 059 } 060 061 @Override 062 public void contributionRemoved(String id, PageProviderDefinition origContrib) { 063 providers.remove(id); 064 log.info("Unregistering page provider with name " + id); 065 } 066 067 @Override 068 public boolean isSupportingMerge() { 069 return false; 070 } 071 072 @Override 073 public PageProviderDefinition clone(PageProviderDefinition orig) { 074 throw new UnsupportedOperationException(); 075 } 076 077 @Override 078 public void merge(PageProviderDefinition src, PageProviderDefinition dst) { 079 throw new UnsupportedOperationException(); 080 } 081 082 // API 083 084 public PageProviderDefinition getPageProvider(String id) { 085 return providers.get(id); 086 } 087 088}