001/* 002 * (C) Copyright 2015 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-2.1.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.theme.styling.service.registries; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.nuxeo.runtime.model.ContributionFragmentRegistry; 023import org.nuxeo.theme.styling.service.descriptors.NegotiationDescriptor; 024 025/** 026 * Registry for negotiations. 027 * 028 * @since 7.4 029 */ 030public class NegotiationRegistry extends ContributionFragmentRegistry<NegotiationDescriptor> { 031 032 protected Map<String, NegotiationDescriptor> negotations = new HashMap<String, NegotiationDescriptor>(); 033 034 @Override 035 public String getContributionId(NegotiationDescriptor contrib) { 036 return contrib.getTarget(); 037 } 038 039 @Override 040 public void contributionUpdated(String id, NegotiationDescriptor contrib, NegotiationDescriptor newOrigContrib) { 041 negotations.put(id, contrib); 042 } 043 044 @Override 045 public synchronized void removeContribution(NegotiationDescriptor contrib) { 046 removeContribution(contrib, true); 047 } 048 049 @Override 050 public void contributionRemoved(String id, NegotiationDescriptor origContrib) { 051 negotations.remove(id); 052 } 053 054 @Override 055 public NegotiationDescriptor clone(NegotiationDescriptor orig) { 056 if (orig == null) { 057 return null; 058 } 059 return orig.clone(); 060 } 061 062 @Override 063 public void merge(NegotiationDescriptor src, NegotiationDescriptor dst) { 064 dst.merge(src); 065 } 066 067 public NegotiationDescriptor getNegotiation(String id) { 068 return negotations.get(id); 069 } 070 071}