| | |
| | | * 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; |
| | |
| | | |
| | | |
| | | /** |
| | | * 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 |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | 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); |
| | | |
| | |
| | | * 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() |
| | | { |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | * @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); |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | * @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); |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | * @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); |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | */ |
| | |
| | | |
| | | |
| | | /** |
| | | * 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; |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the OID for this schema definition. |
| | | * Returns the OID for this schema definition. |
| | | * |
| | | * @return The OID for this schema definition. |
| | | */ |
| | |
| | | |
| | | |
| | | /** |
| | | * 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() |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public int hashCode() |
| | | { |
| | |
| | | * |
| | | * @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) |
| | | { |
| | |
| | | |
| | | |
| | | /** |
| | | * 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); |
| | | } |
| | |
| | | /** |
| | | * 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() |
| | | { |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | * @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); |
| | |
| | | |
| | | |
| | | /** |
| | | * 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() |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | |
| | | |
| | | @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 |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | } |
| | | 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); |
| | | } |
| | | |