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 */ 020 021package org.apache.directory.server.xdbm.impl.avl; 022 023 024import org.apache.directory.api.ldap.model.exception.LdapException; 025import org.apache.directory.api.ldap.model.exception.LdapOtherException; 026import org.apache.directory.api.ldap.model.schema.AttributeType; 027import org.apache.directory.api.ldap.model.schema.MatchingRule; 028import org.apache.directory.api.ldap.model.schema.SchemaManager; 029import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator; 030import org.apache.directory.server.i18n.I18n; 031import org.apache.directory.server.xdbm.ParentIdAndRdn; 032import org.apache.directory.server.xdbm.ParentIdAndRdnComparator; 033 034 035/** 036 * A special index which stores Rdn objects. 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public class AvlRdnIndex extends AvlIndex<ParentIdAndRdn> 041{ 042 public AvlRdnIndex() 043 { 044 super(); 045 } 046 047 048 public AvlRdnIndex( String attributeId ) 049 { 050 super( attributeId, true ); 051 } 052 053 054 public void init( SchemaManager schemaManager, AttributeType attributeType ) throws LdapException 055 { 056 this.attributeType = attributeType; 057 058 MatchingRule mr = attributeType.getEquality(); 059 060 if ( mr == null ) 061 { 062 mr = attributeType.getOrdering(); 063 } 064 065 if ( mr == null ) 066 { 067 mr = attributeType.getSubstring(); 068 } 069 070 normalizer = mr.getNormalizer(); 071 072 if ( normalizer == null ) 073 { 074 throw new LdapOtherException( I18n.err( I18n.ERR_212, attributeType ) ); 075 } 076 077 ParentIdAndRdnComparator<String> comp = new ParentIdAndRdnComparator<String>( mr.getOid() ); 078 079 UuidComparator.INSTANCE.setSchemaManager( schemaManager ); 080 081 /* 082 * The forward key/value map stores attribute values to master table 083 * primary keys. A value for an attribute can occur several times in 084 * different entries so the forward map can have more than one value. 085 */ 086 forward = new AvlTable<ParentIdAndRdn, String>( attributeType.getName(), comp, UuidComparator.INSTANCE, 087 false ); 088 reverse = new AvlTable<String, ParentIdAndRdn>( attributeType.getName(), UuidComparator.INSTANCE, comp, 089 false ); 090 } 091}