001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.schema.registries.helper; 021 022 023import java.util.List; 024 025import org.apache.directory.api.ldap.model.exception.LdapException; 026import org.apache.directory.api.ldap.model.schema.MatchingRuleUse; 027import org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry; 028import org.apache.directory.api.ldap.model.schema.registries.Registries; 029 030 031/** 032 * An helper class used to store all the methods associated with a MatchingRuleUse 033 * in relation with the Registries and SchemaManager. 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037public class MatchingRuleUseHelper 038{ 039 /** 040 * Inject the MatchingRuleUse into the registries, updating the references to 041 * other SchemaObject 042 * 043 * @param matchingRuleUse The MatchingRuleUse to add to the Registries 044 * @param errors The errors we got while adding the MatchingRuleUse to the Registries 045 * @param registries The Registries 046 * @exception If the addition failed 047 */ 048 public static void addToRegistries( MatchingRuleUse matchingRuleUse, List<Throwable> errors, Registries registries ) 049 throws LdapException 050 { 051 if ( registries != null ) 052 { 053 try 054 { 055 matchingRuleUse.unlock(); 056 057 AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry(); 058 059 matchingRuleUse.getApplicableAttributes().clear(); 060 061 for ( String oid : matchingRuleUse.getApplicableAttributeOids() ) 062 { 063 matchingRuleUse.getApplicableAttributes().add( atRegistry.lookup( oid ) ); 064 } 065 } 066 finally 067 { 068 matchingRuleUse.lock(); 069 } 070 } 071 } 072}