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 *      Vladimir Pasquier <vpasquier@nuxeo.com>
016 */
017package org.nuxeo.binary.metadata.internals;
018
019import java.util.Comparator;
020import java.util.Set;
021import java.util.TreeSet;
022
023import org.nuxeo.runtime.model.SimpleContributionRegistry;
024
025/**
026 * Registry for {@link org.nuxeo.binary.metadata.internals.MetadataRuleDescriptor} descriptors.
027 *
028 * @since 7.1
029 */
030public class MetadataRuleRegistry extends SimpleContributionRegistry<MetadataRuleDescriptor> {
031
032    protected final Set<MetadataRuleDescriptor> contribs = new TreeSet<>(new Comparator<MetadataRuleDescriptor>() {
033
034        @Override
035        public int compare(MetadataRuleDescriptor o1, MetadataRuleDescriptor o2) {
036            int order = o1.getOrder().compareTo(o2.getOrder());
037            if (order != 0) {
038                return order;
039            }
040            return o1.getId().compareTo(o2.getId());
041        }
042
043    });
044
045    @Override
046    public String getContributionId(MetadataRuleDescriptor metadataRuleDescriptor) {
047        return metadataRuleDescriptor.getId();
048    }
049
050    protected void handleApplicationStarted() {
051        contribs.addAll(currentContribs.values());
052    }
053
054}