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