001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2009 Sun Microsystems, Inc. 015 * Portions copyright 2014-2015 ForgeRock AS. 016 */ 017package org.forgerock.opendj.ldap.spi; 018 019import java.util.Collection; 020 021import org.forgerock.opendj.ldap.ByteSequence; 022import org.forgerock.opendj.ldap.ByteString; 023import org.forgerock.opendj.ldap.DecodeException; 024import org.forgerock.opendj.ldap.schema.Schema; 025 026/** 027 * This class is registered with a Backend and it provides callbacks 028 * for indexing attribute values. An index implementation will use 029 * this interface to create the keys for an attribute value. 030 */ 031public interface Indexer { 032 033 /** 034 * Returns an index identifier associated with this indexer. An identifier 035 * should be selected based on the matching rule type. A unique identifier 036 * will map to a unique index database in the backend implementation. If 037 * multiple matching rules need to share the index database, the 038 * corresponding indexers should always use the same identifier. 039 * 040 * @return index ID A String containing the ID associated with this indexer. 041 */ 042 String getIndexID(); 043 044 /** 045 * Generates the set of index keys for an attribute. 046 * 047 * @param schema 048 * The schema in which the associated matching rule is defined. 049 * @param value 050 * The attribute value for which keys are required. 051 * @param keys 052 * A collection where to add the created keys. 053 * @throws DecodeException if an error occurs while normalizing the value 054 */ 055 void createKeys(Schema schema, ByteSequence value, Collection<ByteString> keys) throws DecodeException; 056 057 /** 058 * Returns a human readable representation of the key. 059 * Does a best effort conversion from an index key to a string that can be printed, as 060 * used by the diagnostic tools, which are the only users of the method. 061 * It is not necessary for the resulting string to exactly match the value it was 062 * generated from. 063 * 064 * @param key the byte string for the index key. 065 * @return a human readable representation of the key 066 */ 067 String keyToHumanReadableString(ByteSequence key); 068}