MatchingRuleConfigManager.java revision 00870f7dc92907ec0b59c43b783cde7367071ff0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* This class defines a utility that will be used to manage the set of matching
* rules defined in the Directory Server. It wil initialize the rules when the
* server starts, and then will manage any additions, removals, or modifications
* to any matching rules while the server is running.
*/
public class MatchingRuleConfigManager
implements ConfigurationChangeListener<MatchingRuleCfg>,
{
// A mapping between the DNs of the config entries and the associated matching
// rules.
/**
* Creates a new instance of this matching rule config manager.
*/
public MatchingRuleConfigManager()
{
}
/**
* Initializes all matching rules currently defined in the Directory Server
* configuration. This should only be called at Directory Server startup.
*
* @throws ConfigException If a configuration problem causes the matching
* rule initialization process to fail.
*
* @throws InitializationException If a problem occurs while initializing
* the matching rules that is not related to
* the server configuration.
*/
public void initializeMatchingRules()
{
// Get the root configuration object.
// Register as an add and delete listener with the root configuration so we
// can be notified if any matching rule entries are added or removed.
//Initialize the existing matching rules.
{
mrConfiguration.addChangeListener(this);
if (mrConfiguration.isEnabled())
{
try
{
try
{
}
catch (DirectoryException de)
{
de.getErrorMessage());
continue;
}
}
catch (InitializationException ie)
{
continue;
}
}
}
}
/**
* {@inheritDoc}
*/
{
if (configuration.isEnabled())
{
// Get the name of the class and make sure we can instantiate it as a
// matching rule.
try
{
}
catch (InitializationException ie)
{
return false;
}
}
// If we've gotten here, then it's fine.
return true;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
configuration.addChangeListener(this);
if (! configuration.isEnabled())
{
}
// Get the name of the class and make sure we can instantiate it as a
// matching rule.
try
{
try
{
}
catch (DirectoryException de)
{
de.getErrorMessage());
{
}
}
}
catch (InitializationException ie)
{
{
}
}
}
/**
* {@inheritDoc}
*/
{
// If the matching rule is enabled, then check to see if there are any
// defined attribute types or matching rule uses that use the matching rule.
// If so, then don't allow it to be deleted.
boolean configAcceptable = true;
if (matchingRule != null)
{
{
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
}
{
{
configAcceptable = false;
continue;
}
}
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
if (matchingRule != null)
{
}
}
/**
* {@inheritDoc}
*/
{
boolean configAcceptable = true;
if (configuration.isEnabled())
{
// Get the name of the class and make sure we can instantiate it as a
// matching rule.
try
{
}
catch (InitializationException ie)
{
configAcceptable = false;
}
}
else
{
// If the matching rule is currently enabled and the change would make it
// disabled, then only allow it if the matching rule isn't already in use.
if (matchingRule != null)
{
{
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
{
at.getNameOrOID());
configAcceptable = false;
continue;
}
}
for (MatchingRuleUse mru :
{
{
configAcceptable = false;
continue;
}
}
}
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
// Get the existing matching rule if it's already enabled.
// If the new configuration has the matching rule disabled, then disable it
// if it is enabled, or do nothing if it's already disabled.
if (! configuration.isEnabled())
{
if (existingRule != null)
{
{
}
}
}
// Get the class for the matching rule. If the matching rule is already
// enabled, then we shouldn't do anything with it although if the class has
// changed then we'll at least need to indicate that administrative action
// is required. If the matching rule is disabled, then instantiate the
// class and initialize and register it as a matching rule.
if (existingRule != null)
{
{
adminActionRequired = true;
}
}
try
{
try
{
}
catch (DirectoryException de)
{
de.getErrorMessage());
{
}
}
}
catch (InitializationException ie)
{
{
}
}
}
/**
* Loads the specified class, instantiates it as an attribute syntax, and
* optionally initializes that instance.
*
* @param className The fully-qualified name of the attribute syntax
* class to load, instantiate, and initialize.
* @param configuration The configuration to use to initialize the attribute
* syntax, or {@code null} if the attribute syntax
* should not be initialized.
*
* @return The possibly initialized attribute syntax.
*
* @throws InitializationException If a problem occurred while attempting to
* initialize the attribute syntax.
*/
throws InitializationException
{
try
{
if (configuration instanceof ApproximateMatchingRuleCfg)
{
ApproximateMatchingRule.class);
}
else if (configuration instanceof EqualityMatchingRuleCfg)
{
EqualityMatchingRule.class);
}
else if (configuration instanceof OrderingMatchingRuleCfg)
{
OrderingMatchingRule.class);
}
else if (configuration instanceof SubstringMatchingRuleCfg)
{
SubstringMatchingRule.class);
}
else
{
throw new AssertionError("Unsupported matching rule type: " +
className + " with config type " +
}
if (configuration != null)
{
}
return matchingRule;
}
catch (Exception e)
{
}
}
}