View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  
21  package org.apache.directory.server.xdbm.impl.avl;
22  
23  
24  import org.apache.directory.api.ldap.model.exception.LdapException;
25  import org.apache.directory.api.ldap.model.exception.LdapOtherException;
26  import org.apache.directory.api.ldap.model.schema.AttributeType;
27  import org.apache.directory.api.ldap.model.schema.MatchingRule;
28  import org.apache.directory.api.ldap.model.schema.SchemaManager;
29  import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator;
30  import org.apache.directory.server.i18n.I18n;
31  import org.apache.directory.server.xdbm.ParentIdAndRdn;
32  import org.apache.directory.server.xdbm.ParentIdAndRdnComparator;
33  
34  
35  /**
36   * A special index which stores Rdn objects.
37   * 
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public class AvlRdnIndex extends AvlIndex<ParentIdAndRdn>
41  {
42      public AvlRdnIndex()
43      {
44          super();
45      }
46  
47  
48      public AvlRdnIndex( String attributeId )
49      {
50          super( attributeId, true );
51      }
52  
53  
54      @Override
55      public void init( SchemaManager schemaManager, AttributeType attributeType ) throws LdapException
56      {
57          this.attributeType = attributeType;
58  
59          MatchingRule mr = attributeType.getEquality();
60  
61          if ( mr == null )
62          {
63              mr = attributeType.getOrdering();
64          }
65  
66          if ( mr == null )
67          {
68              mr = attributeType.getSubstring();
69          }
70  
71          normalizer = mr.getNormalizer();
72  
73          if ( normalizer == null )
74          {
75              throw new LdapOtherException( I18n.err( I18n.ERR_212, attributeType ) );
76          }
77  
78          ParentIdAndRdnComparator<String> comp = new ParentIdAndRdnComparator<>( mr.getOid() );
79  
80          UuidComparator.INSTANCE.setSchemaManager( schemaManager );
81  
82          /*
83           * The forward key/value map stores attribute values to master table
84           * primary keys.  A value for an attribute can occur several times in
85           * different entries so the forward map can have more than one value.
86           */
87          forward = new AvlTable<ParentIdAndRdn, String>( attributeType.getName(), comp, UuidComparator.INSTANCE,
88              false );
89          reverse = new AvlTable<String, ParentIdAndRdn>( attributeType.getName(), UuidComparator.INSTANCE, comp,
90              false );
91      }
92  }