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