mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
28.47.2010 cc556edc003e4fb8df13611167fab0d9fd3890f9
opendj-sdk/sdk/src/org/opends/sdk/schema/MatchingRule.java
@@ -22,14 +22,15 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 */
package org.opends.sdk.schema;
import static com.sun.opends.sdk.messages.Messages.*;
import static com.sun.opends.sdk.messages.Messages.ERR_ATTR_SYNTAX_MR_UNKNOWN_SYNTAX;
import static com.sun.opends.sdk.messages.Messages.WARN_MATCHING_RULE_NOT_IMPLEMENTED;
import java.util.Comparator;
import java.util.Iterator;
@@ -43,20 +44,19 @@
/**
 * This class defines a data structure for storing and interacting with
 * matching rules, which are used by servers to compare attribute values
 * against assertion values when performing Search and Compare
 * operations. They are also used to identify the value to be added or
 * deleted when modifying entries, and are used when comparing a
 * purported distinguished name with the name of an entry.
 * This class defines a data structure for storing and interacting with matching
 * rules, which are used by servers to compare attribute values against
 * assertion values when performing Search and Compare operations. They are also
 * used to identify the value to be added or deleted when modifying entries, and
 * are used when comparing a purported distinguished name with the name of an
 * entry.
 * <p>
 * Matching rule implementations must extend the
 * <code>MatchingRuleImplementation</code> class so they can be used by
 * OpenDS.
 * <code>MatchingRuleImplementation</code> class so they can be used by OpenDS.
 * <p>
 * Where ordered sets of names, or extra properties are provided, the
 * ordering will be preserved when the associated fields are accessed
 * via their getters or via the {@link #toString()} methods.
 * Where ordered sets of names, or extra properties are provided, the ordering
 * will be preserved when the associated fields are accessed via their getters
 * or via the {@link #toString()} methods.
 */
public final class MatchingRule extends SchemaElement
{
@@ -71,10 +71,10 @@
  MatchingRule(String oid, List<String> names, String description,
      boolean obsolete, String syntax,
      Map<String, List<String>> extraProperties, String definition,
      MatchingRuleImpl implementation)
  MatchingRule(final String oid, final List<String> names,
      final String description, final boolean obsolete, final String syntax,
      final Map<String, List<String>> extraProperties, final String definition,
      final MatchingRuleImpl implementation)
  {
    super(description, extraProperties);
@@ -102,8 +102,8 @@
   * Get a comparator that can be used to compare the attribute values
   * normalized by this matching rule.
   *
   * @return A comparator that can be used to compare the attribute
   *         values normalized by this matching rule.
   * @return A comparator that can be used to compare the attribute values
   *         normalized by this matching rule.
   */
  public Comparator<ByteSequence> comparator()
  {
@@ -113,10 +113,36 @@
  /**
   * Retrieves the normalized form of the provided assertion value,
   * which is best suite for efficiently performing matching operations
   * on that value. The assertion value is guarenteed to be valid
   * against this matching rule's assertion syntax.
   * {@inheritDoc}
   */
  @Override
  public boolean equals(final Object o)
  {
    if (o == null)
    {
      return false;
    }
    if (this == o)
    {
      return true;
    }
    if (!(o instanceof MatchingRule))
    {
      return false;
    }
    return getOID().equals(((MatchingRule) o).getOID());
  }
  /**
   * Returns the normalized form of the provided assertion value, which is best
   * suite for efficiently performing matching operations on that value. The
   * assertion value is guarenteed to be valid against this matching rule's
   * assertion syntax.
   *
   * @param value
   *          The syntax checked assertion value to be normalized.
@@ -124,7 +150,7 @@
   * @throws DecodeException
   *           if the syntax of the value is not valid.
   */
  public Assertion getAssertion(ByteSequence value)
  public Assertion getAssertion(final ByteSequence value)
      throws DecodeException
  {
    return impl.getAssertion(schema, value);
@@ -133,39 +159,37 @@
  /**
   * Retrieves the normalized form of the provided assertion substring
   * values, which is best suite for efficiently performing matching
   * operations on that value.
   * Returns the normalized form of the provided assertion substring values,
   * which is best suite for efficiently performing matching operations on that
   * value.
   *
   * @param subInitial
   *          The normalized substring value fragment that should appear
   *          at the beginning of the target value.
   *          The normalized substring value fragment that should appear at the
   *          beginning of the target value.
   * @param subAnyElements
   *          The normalized substring value fragments that should
   *          appear in the middle of the target value.
   *          The normalized substring value fragments that should appear in the
   *          middle of the target value.
   * @param subFinal
   *          The normalized substring value fragment that should appear
   *          at the end of the target value.
   *          The normalized substring value fragment that should appear at the
   *          end of the target value.
   * @return The normalized version of the provided assertion value.
   * @throws DecodeException
   *           if the syntax of the value is not valid.
   */
  public Assertion getAssertion(ByteSequence subInitial,
      List<? extends ByteSequence> subAnyElements, ByteSequence subFinal)
      throws DecodeException
  public Assertion getAssertion(final ByteSequence subInitial,
      final List<? extends ByteSequence> subAnyElements,
      final ByteSequence subFinal) throws DecodeException
  {
    return impl.getAssertion(schema, subInitial, subAnyElements,
        subFinal);
    return impl.getAssertion(schema, subInitial, subAnyElements, subFinal);
  }
  /**
   * Retrieves the normalized form of the provided assertion value,
   * which is best suite for efficiently performing greater than or
   * equal ordering matching operations on that value. The assertion
   * value is guarenteed to be valid against this matching rule's
   * assertion syntax.
   * Returns the normalized form of the provided assertion value, which is best
   * suite for efficiently performing greater than or equal ordering matching
   * operations on that value. The assertion value is guarenteed to be valid
   * against this matching rule's assertion syntax.
   *
   * @param value
   *          The syntax checked assertion value to be normalized.
@@ -173,7 +197,7 @@
   * @throws DecodeException
   *           if the syntax of the value is not valid.
   */
  public Assertion getGreaterOrEqualAssertion(ByteSequence value)
  public Assertion getGreaterOrEqualAssertion(final ByteSequence value)
      throws DecodeException
  {
    return impl.getGreaterOrEqualAssertion(schema, value);
@@ -182,11 +206,10 @@
  /**
   * Retrieves the normalized form of the provided assertion value,
   * which is best suite for efficiently performing greater than or
   * equal ordering matching operations on that value. The assertion
   * value is guarenteed to be valid against this matching rule's
   * assertion syntax.
   * Returns the normalized form of the provided assertion value, which is best
   * suite for efficiently performing greater than or equal ordering matching
   * operations on that value. The assertion value is guarenteed to be valid
   * against this matching rule's assertion syntax.
   *
   * @param value
   *          The syntax checked assertion value to be normalized.
@@ -194,7 +217,7 @@
   * @throws DecodeException
   *           if the syntax of the value is not valid.
   */
  public Assertion getLessOrEqualAssertion(ByteSequence value)
  public Assertion getLessOrEqualAssertion(final ByteSequence value)
      throws DecodeException
  {
    return impl.getLessOrEqualAssertion(schema, value);
@@ -203,9 +226,9 @@
  /**
   * Retrieves the name or OID for this schema definition. If it has one
   * or more names, then the primary name will be returned. If it does
   * not have any names, then the OID will be returned.
   * Returns the name or OID for this schema definition. If it has one or more
   * names, then the primary name will be returned. If it does not have any
   * names, then the OID will be returned.
   *
   * @return The name or OID for this schema definition.
   */
@@ -221,13 +244,13 @@
  /**
   * Retrieves an iterable over the set of user-defined names that may
   * be used to reference this schema definition.
   * Returns an unmodifiable list containing the user-defined names that may be
   * used to reference this schema definition.
   *
   * @return Returns an iterable over the set of user-defined names that
   * @return Returns an unmodifiable list containing the user-defined names that
   *         may be used to reference this schema definition.
   */
  public Iterable<String> getNames()
  public List<String> getNames()
  {
    return names;
  }
@@ -235,7 +258,7 @@
  /**
   * Retrieves the OID for this schema definition.
   * Returns the OID for this schema definition.
   *
   * @return The OID for this schema definition.
   */
@@ -248,11 +271,11 @@
  /**
   * Retrieves the OID of the assertion value syntax with which this
   * matching rule is associated.
   * Returns the OID of the assertion value syntax with which this matching rule
   * is associated.
   *
   * @return The OID of the assertion value syntax with which this
   *         matching rule is associated.
   * @return The OID of the assertion value syntax with which this matching rule
   *         is associated.
   */
  public Syntax getSyntax()
  {
@@ -261,6 +284,9 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public int hashCode()
  {
@@ -274,10 +300,10 @@
   *
   * @param name
   *          The name for which to make the determination.
   * @return <code>true</code> if the specified name is assigned to this
   *         schema definition, or <code>false</code> if not.
   * @return <code>true</code> if the specified name is assigned to this schema
   *         definition, or <code>false</code> if not.
   */
  public boolean hasName(String name)
  public boolean hasName(final String name)
  {
    for (final String n : names)
    {
@@ -292,16 +318,15 @@
  /**
   * Indicates whether this schema definition has the specified name or
   * OID.
   * Indicates whether this schema definition has the specified name or OID.
   *
   * @param value
   *          The value for which to make the determination.
   * @return <code>true</code> if the provided value matches the OID or
   *         one of the names assigned to this schema definition, or
   *         <code>false</code> if not.
   * @return <code>true</code> if the provided value matches the OID or one of
   *         the names assigned to this schema definition, or <code>false</code>
   *         if not.
   */
  public boolean hasNameOrOID(String value)
  public boolean hasNameOrOID(final String value)
  {
    return hasName(value) || getOID().equals(value);
  }
@@ -311,8 +336,8 @@
  /**
   * Indicates whether this schema definition is declared "obsolete".
   *
   * @return <code>true</code> if this schema definition is declared
   *         "obsolete", or <code>false</code> if not.
   * @return <code>true</code> if this schema definition is declared "obsolete",
   *         or <code>false</code> if not.
   */
  public boolean isObsolete()
  {
@@ -322,9 +347,8 @@
  /**
   * Retrieves the normalized form of the provided attribute value,
   * which is best suite for efficiently performing matching operations
   * on that value.
   * Returns the normalized form of the provided attribute value, which is best
   * suite for efficiently performing matching operations on that value.
   *
   * @param value
   *          The attribute value to be normalized.
@@ -332,7 +356,7 @@
   * @throws DecodeException
   *           if the syntax of the value is not valid.
   */
  public ByteString normalizeAttributeValue(ByteSequence value)
  public ByteString normalizeAttributeValue(final ByteSequence value)
      throws DecodeException
  {
    return impl.normalizeAttributeValue(schema, value);
@@ -341,11 +365,11 @@
  /**
   * Retrieves the string representation of this schema definition in
   * the form specified in RFC 2252.
   * Returns the string representation of this schema definition in the form
   * specified in RFC 2252.
   *
   * @return The string representation of this schema definition in the
   *         form specified in RFC 2252.
   * @return The string representation of this schema definition in the form
   *         specified in RFC 2252.
   */
  @Override
  public String toString()
@@ -357,14 +381,14 @@
  MatchingRule duplicate()
  {
    return new MatchingRule(oid, names, description, isObsolete,
        syntaxOID, extraProperties, definition, impl);
    return new MatchingRule(oid, names, description, isObsolete, syntaxOID,
        extraProperties, definition, impl);
  }
  @Override
  void toStringContent(StringBuilder buffer)
  void toStringContent(final StringBuilder buffer)
  {
    buffer.append(oid);
@@ -413,7 +437,7 @@
  @Override
  void validate(List<LocalizableMessage> warnings, Schema schema)
  void validate(final List<LocalizableMessage> warnings, final Schema schema)
      throws SchemaException
  {
    // Try finding an implementation in the core schema
@@ -429,9 +453,8 @@
    if (impl == null)
    {
      impl = Schema.getDefaultMatchingRule().impl;
      final LocalizableMessage message =
          WARN_MATCHING_RULE_NOT_IMPLEMENTED.get(oid, Schema
              .getDefaultMatchingRule().getOID());
      final LocalizableMessage message = WARN_MATCHING_RULE_NOT_IMPLEMENTED
          .get(oid, Schema.getDefaultMatchingRule().getOID());
      warnings.add(message);
    }
@@ -442,9 +465,8 @@
    }
    catch (final UnknownSchemaElementException e)
    {
      final LocalizableMessage message =
          ERR_ATTR_SYNTAX_MR_UNKNOWN_SYNTAX.get(getNameOrOID(),
              syntaxOID);
      final LocalizableMessage message = ERR_ATTR_SYNTAX_MR_UNKNOWN_SYNTAX.get(
          getNameOrOID(), syntaxOID);
      throw new SchemaException(message, e);
    }