| | |
| | | */ |
| | | package org.opends.server.schema; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.SchemaMessages.*; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | |
| | | import org.opends.server.admin.std.server.CollationMatchingRuleCfg; |
| | | import org.opends.server.api.MatchingRuleFactory; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ServerContext; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.util.CollectionUtils; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.SchemaMessages.*; |
| | | |
| | | /** |
| | | * This class is a factory class for Collation matching rules. It |
| | | * creates different matching rules based on the configuration entries. |
| | |
| | | /** Map of OID and the Matching Rule. */ |
| | | private final Map<String, MatchingRule> matchingRules = new HashMap<>(); |
| | | |
| | | private ServerContext serverContext; |
| | | |
| | | |
| | | /** Creates a new instance of CollationMatchingRuleFactory. */ |
| | | public CollationMatchingRuleFactory() |
| | | { |
| | | super(); |
| | | } |
| | | |
| | | /** |
| | | * Sets the server context. |
| | | * |
| | | * @param serverContext |
| | | * The server context. |
| | | */ |
| | | public void setServerContext(ServerContext serverContext) |
| | | { |
| | | this.serverContext = serverContext; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final Collection<org.forgerock.opendj.ldap.schema.MatchingRule> getMatchingRules() |
| | | public final Collection<MatchingRule> getMatchingRules() |
| | | { |
| | | return Collections.unmodifiableCollection(matchingRules.values()); |
| | | } |
| | |
| | | matchingRules.put(oid, matchingRule); |
| | | } |
| | | |
| | | /** |
| | | * Clears the Map containing matching Rules. |
| | | */ |
| | | private void resetRules() |
| | | { |
| | | matchingRules.clear(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void initializeMatchingRule(CollationMatchingRuleCfg configuration) |
| | | throws ConfigException, InitializationException |
| | |
| | | currentConfig.addCollationChangeListener(this); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void finalizeMatchingRule() |
| | | { |
| | |
| | | currentConfig.removeCollationChangeListener(this); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange( |
| | | CollationMatchingRuleCfg configuration) |
| | |
| | | } |
| | | |
| | | // Since we have come here it means that this Factory is enabled and |
| | | // there is a change in the CollationMatchingRuleFactory's |
| | | // configuration. |
| | | // there is a change in the CollationMatchingRuleFactory's configuration. |
| | | // Deregister all the Matching Rule corresponding to this factory. |
| | | for (MatchingRule rule : getMatchingRules()) |
| | | { |
| | | DirectoryServer.deregisterMatchingRule(rule); |
| | | } |
| | | |
| | | // Clear the associated matching rules. |
| | | resetRules(); |
| | | matchingRules.clear(); |
| | | |
| | | final Schema schema = serverContext.getSchemaNG(); |
| | | final Schema schema = DirectoryServer.getSchema().getSchemaNG(); |
| | | for (String collation : configuration.getCollation()) |
| | | { |
| | | // validation has already been performed in isConfigurationChangeAcceptable() |
| | |
| | | return ccr; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable( |
| | | CollationMatchingRuleCfg configuration, |
| | |
| | | { |
| | | boolean configAcceptable = true; |
| | | |
| | | // If the new configuration disables this factory, don't do |
| | | // anything. |
| | | // If the new configuration disables this factory, don't do anything. |
| | | if (!configuration.isEnabled()) |
| | | { |
| | | return configAcceptable; |
| | | } |
| | | |
| | | // If it comes here we don't need to verify MatchingRuleType; it |
| | | // should be okay as its syntax is verified by the admin framework. |
| | | // If it comes here we don't need to verify MatchingRuleType; |
| | | // it should be okay as its syntax is verified by the admin framework. |
| | | // Iterate over the collations and verify if the format is okay. |
| | | // Also, verify if the locale is allowed by the JVM. |
| | | for (String collation : configuration.getCollation()) |
| | |
| | | return configAcceptable; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Verifies if the locale is supported by the JVM. |
| | | * |
| | |
| | | return locale; |
| | | } |
| | | |
| | | /** |
| | | * A utility class for extracting the OID and Language Tag from the |
| | | * configuration entry. |
| | | */ |
| | | /** A utility class for extracting the OID and Language Tag from the configuration entry. */ |
| | | private final class CollationMapper |
| | | { |
| | | /** OID of the collation rule. */ |