001/*
002 * (C) Copyright 2014 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 *     Thierry Martins
016 */
017
018package org.nuxeo.ecm.platform.web.common.requestcontroller.service;
019
020import java.util.HashMap;
021import java.util.Map;
022
023import org.nuxeo.runtime.model.ContributionFragmentRegistry;
024
025/**
026 * Header description registry model.
027 *
028 * @author <a href="mailto:tm@nuxeo.com">Thierry Martins</a>
029 * @since 6.0
030 */
031public class NuxeoHeaderDescriptorRegistry extends ContributionFragmentRegistry<NuxeoHeaderDescriptor> {
032
033    protected Map<String, NuxeoHeaderDescriptor> descs = new HashMap<>();
034
035    @Override
036    public String getContributionId(NuxeoHeaderDescriptor contrib) {
037        return contrib.name;
038    }
039
040    @Override
041    public void contributionUpdated(String id, NuxeoHeaderDescriptor contrib, NuxeoHeaderDescriptor newOrigContrib) {
042        if (descs.containsKey(id)) {
043            descs.remove(id);
044        }
045        if (contrib.enabled) {
046            descs.put(id, contrib);
047        }
048    }
049
050    @Override
051    public void contributionRemoved(String id, NuxeoHeaderDescriptor origContrib) {
052        if (descs.containsKey(id)) {
053            descs.remove(id);
054        }
055    }
056
057    @Override
058    public NuxeoHeaderDescriptor clone(NuxeoHeaderDescriptor orig) {
059        try {
060            return orig.clone();
061        } catch (CloneNotSupportedException e) {
062            // Should never happens...
063            return null;
064        }
065    }
066
067    @Override
068    public void merge(NuxeoHeaderDescriptor src, NuxeoHeaderDescriptor dst) {
069        dst.merge(src);
070    }
071
072}