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 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.api;
018
019
020import java.util.Collection;
021import java.util.List;
022
023import org.forgerock.opendj.server.config.server.MatchingRuleCfg;
024import org.forgerock.opendj.config.server.ConfigException;
025import org.forgerock.opendj.ldap.schema.MatchingRule;
026import org.forgerock.i18n.LocalizableMessage;
027import org.opends.server.types.InitializationException;
028
029/**
030 * This class defines the set of methods and structures that must be
031 * implemented by a Directory Server module that implements a matching
032 * rule factory.
033 *
034 * @param  <T>  The type of configuration handled by this matching
035 *              rule.
036 */
037@org.opends.server.types.PublicAPI(
038     stability=org.opends.server.types.StabilityLevel.VOLATILE,
039     mayInstantiate=false,
040     mayExtend=true,
041     mayInvoke=false)
042public abstract class MatchingRuleFactory<T extends MatchingRuleCfg>
043{
044
045  /**
046   * Initializes the matching rule(s) based on the information in the
047   * provided configuration entry.
048   *
049   * @param  configuration  The configuration to use to intialize this
050   *                        matching rule.
051   *
052   * @throws  ConfigException  If an unrecoverable problem arises in
053   *                           the process of performing the
054   *                           initialization.
055   *
056   * @throws  InitializationException  If a problem that is not
057   *                                   configuration-related occurs
058   *                                   during initialization.
059   */
060  public abstract void initializeMatchingRule(T configuration)
061         throws ConfigException, InitializationException;
062
063
064
065  /**
066   * Performs any finalization that may be needed whenever this
067   * matching rule factory is taken out of service.
068   */
069  public  void finalizeMatchingRule()
070  {
071    //No implementation is required by default.
072  }
073
074
075
076  /**
077   * Indicates whether the provided configuration is acceptable for
078   * this matching rule.  It should be possible to call this method on
079   * an uninitialized matching rule instance in order to determine
080   * whether the matching rule would be able to use the provided
081   * configuration.
082   * <BR><BR>
083   * Note that implementations which use a subclass of the provided
084   * configuration class will likely need to cast the configuration
085   * to the appropriate subclass type.
086   *
087   * @param  configuration        The matching rule configuration for
088   *                              which to make the determination.
089   * @param  unacceptableReasons  A list that may be used to hold the
090   *                              reasons that the provided
091   *                              configuration is not acceptable.
092   *
093   * @return  {@code true} if the provided configuration is acceptable
094   *          for this matching rule, or {@code false} if not.
095   */
096  public  boolean isConfigurationAcceptable(
097                      T configuration,
098                      List<LocalizableMessage> unacceptableReasons)
099  {
100    // This default implementation does not perform any special
101    // validation.  It should be overridden by matching rule
102    // implementations that wish to perform more detailed validation.
103    return true;
104  }
105
106
107
108  /**
109   * Returns an umodifiable view of Collection of associated
110   * MatchingRules.
111   *
112   * @return  An unmodifiable view of Collection of
113   *          MatchingRule instances.
114   */
115  public abstract Collection<MatchingRule> getMatchingRules();
116}