0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License, Version 1.0 only
0N/A * (the "License"). You may not use this file except in compliance
0N/A * with the License.
0N/A *
0N/A * You can obtain a copy of the license at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
0N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at
0N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
0N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
0N/A * Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A *
0N/A *
3231N/A * Copyright 2006-2008 Sun Microsystems, Inc.
5866N/A * Portions Copyright 2012 ForgeRock AS
0N/A */
0N/Apackage org.opends.server.schema;
2086N/Aimport org.opends.messages.Message;
0N/A
0N/A
0N/A
0N/Aimport java.util.List;
0N/A
1617N/Aimport org.opends.server.admin.server.ConfigurationChangeListener;
1617N/Aimport org.opends.server.admin.std.server.DirectoryStringAttributeSyntaxCfg;
0N/Aimport org.opends.server.api.ApproximateMatchingRule;
0N/Aimport org.opends.server.api.AttributeSyntax;
0N/Aimport org.opends.server.api.AttributeValueDecoder;
0N/Aimport org.opends.server.api.EqualityMatchingRule;
0N/Aimport org.opends.server.api.OrderingMatchingRule;
0N/Aimport org.opends.server.api.SubstringMatchingRule;
0N/Aimport org.opends.server.config.ConfigException;
0N/Aimport org.opends.server.core.DirectoryServer;
2086N/A
2086N/A
4134N/Aimport org.opends.server.types.*;
0N/A
1280N/Aimport static org.opends.server.loggers.ErrorLogger.*;
2086N/Aimport static org.opends.messages.SchemaMessages.*;
2086N/A
2086N/Aimport org.opends.messages.MessageBuilder;
0N/Aimport static org.opends.server.schema.SchemaConstants.*;
0N/A
0N/A
0N/A/**
0N/A * This class defines the directory string attribute syntax, which is simply a
0N/A * set of UTF-8 characters. By default, they will be treated in a
0N/A * case-insensitive manner, and equality, ordering, substring, and approximate
0N/A * matching will be allowed.
0N/A */
0N/Apublic class DirectoryStringSyntax
1617N/A extends AttributeSyntax<DirectoryStringAttributeSyntaxCfg>
1617N/A implements ConfigurationChangeListener<DirectoryStringAttributeSyntaxCfg>
0N/A{
0N/A // The default approximate matching rule for this syntax.
0N/A private ApproximateMatchingRule defaultApproximateMatchingRule;
0N/A
0N/A // Indicates whether we will allow zero-length values.
0N/A private boolean allowZeroLengthValues;
0N/A
1617N/A // The reference to the configuration for this directory string syntax.
1617N/A private DirectoryStringAttributeSyntaxCfg currentConfig;
0N/A
0N/A // The default equality matching rule for this syntax.
0N/A private EqualityMatchingRule defaultEqualityMatchingRule;
0N/A
0N/A // The default ordering matching rule for this syntax.
0N/A private OrderingMatchingRule defaultOrderingMatchingRule;
0N/A
0N/A // The default substring matching rule for this syntax.
0N/A private SubstringMatchingRule defaultSubstringMatchingRule;
0N/A
0N/A
0N/A
0N/A /**
0N/A * A {@link String} attribute value decoder for this syntax.
0N/A */
0N/A public static final AttributeValueDecoder<String> DECODER =
0N/A new AttributeValueDecoder<String>()
0N/A {
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A public String decode(AttributeValue value) throws DirectoryException
0N/A {
0N/A // Make sure that the value is valid.
0N/A value.getNormalizedValue();
4134N/A return value.getValue().toString();
0N/A }
0N/A };
0N/A
0N/A
0N/A
0N/A /**
0N/A * Creates a new instance of this syntax. Note that the only thing that
0N/A * should be done here is to invoke the default constructor for the
0N/A * superclass. All initialization should be performed in the
0N/A * <CODE>initializeSyntax</CODE> method.
0N/A */
0N/A public DirectoryStringSyntax()
0N/A {
0N/A super();
0N/A }
0N/A
0N/A
0N/A
0N/A /**
1617N/A * {@inheritDoc}
0N/A */
1617N/A public void initializeSyntax(DirectoryStringAttributeSyntaxCfg configuration)
0N/A throws ConfigException
0N/A {
0N/A defaultApproximateMatchingRule =
0N/A DirectoryServer.getApproximateMatchingRule(AMR_DOUBLE_METAPHONE_OID);
0N/A if (defaultApproximateMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_APPROXIMATE_MATCHING_RULE.get(
2086N/A AMR_DOUBLE_METAPHONE_OID, SYNTAX_DIRECTORY_STRING_NAME));
0N/A }
0N/A
0N/A defaultEqualityMatchingRule =
0N/A DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_OID);
0N/A if (defaultEqualityMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_EQUALITY_MATCHING_RULE.get(
2086N/A EMR_CASE_IGNORE_OID, SYNTAX_DIRECTORY_STRING_NAME));
0N/A }
0N/A
0N/A defaultOrderingMatchingRule =
0N/A DirectoryServer.getOrderingMatchingRule(OMR_CASE_IGNORE_OID);
0N/A if (defaultOrderingMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_ORDERING_MATCHING_RULE.get(
2086N/A OMR_CASE_IGNORE_OID, SYNTAX_DIRECTORY_STRING_NAME));
0N/A }
0N/A
0N/A defaultSubstringMatchingRule =
0N/A DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID);
0N/A if (defaultSubstringMatchingRule == null)
0N/A {
2086N/A logError(ERR_ATTR_SYNTAX_UNKNOWN_SUBSTRING_MATCHING_RULE.get(
2086N/A SMR_CASE_IGNORE_OID, SYNTAX_DIRECTORY_STRING_NAME));
0N/A }
0N/A
0N/A
0N/A // This syntax is one of the Directory Server's core syntaxes and therefore
0N/A // it may be instantiated at times without a configuration entry. If that
0N/A // is the case, then we'll exit now before doing anything that could require
0N/A // access to that entry.
1617N/A if (configuration == null)
0N/A {
0N/A return;
0N/A }
0N/A
1617N/A currentConfig = configuration;
1617N/A currentConfig.addDirectoryStringChangeListener(this);
1617N/A allowZeroLengthValues = currentConfig.isAllowZeroLengthValues();
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Performs any finalization that may be necessary for this attribute syntax.
0N/A */
0N/A public void finalizeSyntax()
0N/A {
1617N/A currentConfig.removeDirectoryStringChangeListener(this);
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the common name for this attribute syntax.
0N/A *
0N/A * @return The common name for this attribute syntax.
0N/A */
0N/A public String getSyntaxName()
0N/A {
0N/A return SYNTAX_DIRECTORY_STRING_NAME;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the OID for this attribute syntax.
0N/A *
0N/A * @return The OID for this attribute syntax.
0N/A */
0N/A public String getOID()
0N/A {
0N/A return SYNTAX_DIRECTORY_STRING_OID;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves a description for this attribute syntax.
0N/A *
0N/A * @return A description for this attribute syntax.
0N/A */
0N/A public String getDescription()
0N/A {
0N/A return SYNTAX_DIRECTORY_STRING_DESCRIPTION;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default equality matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default equality matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if equality
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public EqualityMatchingRule getEqualityMatchingRule()
0N/A {
0N/A return defaultEqualityMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default ordering matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default ordering matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if ordering
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public OrderingMatchingRule getOrderingMatchingRule()
0N/A {
0N/A return defaultOrderingMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default substring matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default substring matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if substring
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public SubstringMatchingRule getSubstringMatchingRule()
0N/A {
0N/A return defaultSubstringMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Retrieves the default approximate matching rule that will be used for
0N/A * attributes with this syntax.
0N/A *
0N/A * @return The default approximate matching rule that will be used for
0N/A * attributes with this syntax, or <CODE>null</CODE> if approximate
0N/A * matches will not be allowed for this type by default.
0N/A */
0N/A public ApproximateMatchingRule getApproximateMatchingRule()
0N/A {
0N/A return defaultApproximateMatchingRule;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the provided value is acceptable for use in an attribute
0N/A * with this syntax. If it is not, then the reason may be appended to the
0N/A * provided buffer.
0N/A *
0N/A * @param value The value for which to make the determination.
0N/A * @param invalidReason The buffer to which the invalid reason should be
0N/A * appended.
0N/A *
0N/A * @return <CODE>true</CODE> if the provided value is acceptable for use with
0N/A * this syntax, or <CODE>false</CODE> if not.
0N/A */
4134N/A public boolean valueIsAcceptable(ByteSequence value,
2086N/A MessageBuilder invalidReason)
0N/A {
4134N/A if (allowZeroLengthValues || (value.length() > 0))
0N/A {
0N/A return true;
0N/A }
0N/A else
0N/A {
2086N/A invalidReason.append(
2086N/A ERR_ATTR_SYNTAX_DIRECTORYSTRING_INVALID_ZEROLENGTH_VALUE.get());
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * Indicates whether zero-length values will be allowed. This is technically
0N/A * forbidden by the LDAP specification, but it was allowed in earlier versions
0N/A * of the server, and the discussion of the directory string syntax in RFC
0N/A * 2252 does not explicitly state that they are not allowed.
0N/A *
0N/A * @return <CODE>true</CODE> if zero-length values should be allowed for
0N/A * attributes with a directory string syntax, or <CODE>false</CODE>
0N/A * if not.
0N/A */
0N/A public boolean allowZeroLengthValues()
0N/A {
0N/A return allowZeroLengthValues;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
1617N/A * {@inheritDoc}
0N/A */
1617N/A public boolean isConfigurationChangeAcceptable(
1617N/A DirectoryStringAttributeSyntaxCfg configuration,
2086N/A List<Message> unacceptableReasons)
0N/A {
1617N/A // The configuration will always be acceptable.
1617N/A return true;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
1617N/A * {@inheritDoc}
0N/A */
1617N/A public ConfigChangeResult applyConfigurationChange(
1617N/A DirectoryStringAttributeSyntaxCfg configuration)
0N/A {
1617N/A currentConfig = configuration;
1617N/A allowZeroLengthValues = configuration.isAllowZeroLengthValues();
0N/A
1617N/A return new ConfigChangeResult(ResultCode.SUCCESS, false);
0N/A }
3853N/A
3853N/A
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public boolean isBinary()
3853N/A {
3853N/A return false;
3853N/A }
5866N/A
5866N/A
5866N/A
5866N/A /**
5866N/A * {@inheritDoc}
5866N/A */
5866N/A public boolean isHumanReadable()
5866N/A {
5866N/A return true;
5866N/A }
0N/A}
0N/A