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 org.apache.directory.api.ldap.model.exception.LdapException; 024import org.apache.directory.api.ldap.model.schema.MatchingRuleUse; 025import org.apache.directory.api.ldap.model.schema.SchemaErrorHandler; 026import org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry; 027import org.apache.directory.api.ldap.model.schema.registries.Registries; 028 029 030/** 031 * An helper class used to store all the methods associated with a MatchingRuleUse 032 * in relation with the Registries and SchemaManager. 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 */ 036public final class MatchingRuleUseHelper 037{ 038 private MatchingRuleUseHelper() 039 { 040 } 041 042 043 /** 044 * Inject the MatchingRuleUse into the registries, updating the references to 045 * other SchemaObject 046 * 047 * @param matchingRuleUse The MatchingRuleUse to add to the Registries 048 * @param errorHandler Error handler 049 * @param registries The Registries 050 * @throws LdapException If the addition failed 051 */ 052 public static void addToRegistries( MatchingRuleUse matchingRuleUse, SchemaErrorHandler errorHandler, Registries registries ) 053 throws LdapException 054 { 055 if ( registries != null ) 056 { 057 try 058 { 059 matchingRuleUse.unlock(); 060 061 AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry(); 062 063 matchingRuleUse.getApplicableAttributes().clear(); 064 065 for ( String oid : matchingRuleUse.getApplicableAttributeOids() ) 066 { 067 matchingRuleUse.getApplicableAttributes().add( atRegistry.lookup( oid ) ); 068 } 069 } 070 finally 071 { 072 matchingRuleUse.lock(); 073 } 074 } 075 } 076}