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.DitContentRule; 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.ObjectClassRegistry; 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 an DitContentRule 033 * in relation with the Registries and SchemaManager. 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037public final class DitContentRuleHelper 038{ 039 private DitContentRuleHelper() 040 { 041 } 042 043 044 /** 045 * Inject the DitContentRule into the registries, updating the references to 046 * other SchemaObject 047 * 048 * @param ditContentRule The DitContentRule to add to the Registries 049 * @param errorHandler Error handler 050 * @param registries The Registries 051 * @throws LdapException If the addition failed 052 */ 053 public static void addToRegistries( DitContentRule ditContentRule, SchemaErrorHandler errorHandler, Registries registries ) 054 throws LdapException 055 { 056 if ( registries != null ) 057 { 058 try 059 { 060 ditContentRule.unlock(); 061 AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry(); 062 ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry(); 063 064 if ( ditContentRule.getMayAttributeTypeOids() != null ) 065 { 066 ditContentRule.getMayAttributeTypes().clear(); 067 068 for ( String oid : ditContentRule.getMayAttributeTypeOids() ) 069 { 070 ditContentRule.getMayAttributeTypes().add( atRegistry.lookup( oid ) ); 071 } 072 } 073 074 if ( ditContentRule.getMustAttributeTypeOids() != null ) 075 { 076 ditContentRule.getMustAttributeTypes().clear(); 077 078 for ( String oid : ditContentRule.getMustAttributeTypeOids() ) 079 { 080 ditContentRule.getMustAttributeTypes().add( atRegistry.lookup( oid ) ); 081 } 082 } 083 084 if ( ditContentRule.getNotAttributeTypeOids() != null ) 085 { 086 ditContentRule.getNotAttributeTypes().clear(); 087 088 for ( String oid : ditContentRule.getNotAttributeTypeOids() ) 089 { 090 ditContentRule.getNotAttributeTypes().add( atRegistry.lookup( oid ) ); 091 } 092 } 093 094 if ( ditContentRule.getAuxObjectClassOids() != null ) 095 { 096 ditContentRule.getAuxObjectClasses().clear(); 097 098 for ( String oid : ditContentRule.getAuxObjectClassOids() ) 099 { 100 ditContentRule.getAuxObjectClasses().add( ocRegistry.lookup( oid ) ); 101 } 102 } 103 } 104 finally 105 { 106 ditContentRule.lock(); 107 } 108 } 109 } 110}