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