001/* 002 * (C) Copyright 2010-2013 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 * Olivier Grisel 016 */ 017package org.nuxeo.ecm.platform.suggestbox.service.registries; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.ecm.core.api.NuxeoException; 023import org.nuxeo.ecm.platform.suggestbox.service.ComponentInitializationException; 024import org.nuxeo.ecm.platform.suggestbox.service.descriptors.SuggesterDescriptor; 025import org.nuxeo.runtime.model.ContributionFragmentRegistry; 026 027public class SuggesterRegistry extends ContributionFragmentRegistry<SuggesterDescriptor> { 028 029 protected final Map<String, SuggesterDescriptor> suggesterDescriptors = new HashMap<String, SuggesterDescriptor>(); 030 031 public SuggesterDescriptor getSuggesterDescriptor(String name) { 032 return suggesterDescriptors.get(name); 033 } 034 035 @Override 036 public void contributionRemoved(String id, SuggesterDescriptor descriptor) { 037 suggesterDescriptors.remove(id); 038 } 039 040 @Override 041 public String getContributionId(SuggesterDescriptor descriptor) { 042 return descriptor.getName(); 043 } 044 045 @Override 046 public void contributionUpdated(String id, SuggesterDescriptor contrib, SuggesterDescriptor newOrigContrib) { 047 suggesterDescriptors.put(id, contrib); 048 } 049 050 @Override 051 public SuggesterDescriptor clone(SuggesterDescriptor suggester) { 052 try { 053 return (SuggesterDescriptor) suggester.clone(); 054 } catch (CloneNotSupportedException e) { 055 // this should never occur since clone implements Cloneable 056 throw new RuntimeException(e); 057 } 058 } 059 060 @Override 061 public void merge(SuggesterDescriptor src, SuggesterDescriptor dst) { 062 try { 063 dst.mergeFrom(src); 064 } catch (ComponentInitializationException e) { 065 throw new NuxeoException(e); 066 } 067 } 068 069}