From 4ea973407d1bb879a8490ff2d9635612945166c6 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 14 Nov 2014 09:35:04 +0000
Subject: [PATCH] OPENDJ-1591 (CR-5206) Switch to SDK matching rules
---
/dev/null | 134 --------------------------------------------
1 files changed, 0 insertions(+), 134 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/AbstractMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/AbstractMatchingRule.java
deleted file mode 100644
index cbf2c28..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/AbstractMatchingRule.java
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.schema.Schema;
-import org.forgerock.opendj.ldap.schema.Syntax;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-
-/**
- * This class provides default implementation of MatchingRule. A
- * matching rule implemented by a Directory Server module must extend
- * this class.
- */
-@org.opends.server.types.PublicAPI(
- stability = org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate = false,
- mayExtend = true,
- mayInvoke = false)
-public abstract class AbstractMatchingRule implements MatchingRule
-{
-
- /**
- * Default implementation of assertion.
- */
- public static final class DefaultAssertion implements Assertion
- {
- /** The ID of the DB index to use with this assertion. */
- private final String indexID;
- private final ByteSequence normalizedAssertionValue;
-
- /**
- * Returns the equality assertion.
- *
- * @param normalizedAssertionValue
- * The value on which the assertion is built.
- * @return the equality assertion
- */
- public static DefaultAssertion equality(final ByteSequence normalizedAssertionValue)
- {
- return new DefaultAssertion("equality", normalizedAssertionValue);
- }
-
- /**
- * Returns the approximate assertion.
- *
- * @param normalizedAssertionValue
- * The value on which the assertion is built.
- * @return the approximate assertion
- */
- static DefaultAssertion approximate(final ByteSequence normalizedAssertionValue)
- {
- return new DefaultAssertion("approximate", normalizedAssertionValue);
- }
-
- private DefaultAssertion(final String indexID, final ByteSequence normalizedAssertionValue)
- {
- this.indexID = indexID;
- this.normalizedAssertionValue = normalizedAssertionValue;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ConditionResult matches(final ByteSequence normalizedAttributeValue)
- {
- return ConditionResult.valueOf(normalizedAssertionValue.equals(normalizedAttributeValue));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory)
- throws DecodeException
- {
- return factory.createExactMatchQuery(indexID, normalizedAssertionValue);
- }
- }
-
- private static final Assertion UNDEFINED_ASSERTION = new Assertion()
- {
- @Override
- public ConditionResult matches(final ByteSequence normalizedAttributeValue)
- {
- return ConditionResult.UNDEFINED;
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory)
- throws DecodeException
- {
- // Subclassing this class will always work, albeit inefficiently.
- // This is better than throwing an exception for no good reason.
- return factory.createMatchAllQuery();
- }
- };
-
- /**
- * Returns the normalized form of the assertion value.
- *
- * @param value
- * The assertion value to normalize.
- * @return the normalized value
- * @throws DecodeException
- * If a problem occurs.
- */
- public ByteString normalizeAssertionValue(ByteSequence value)
- throws DecodeException
- {
- // Default implementation is to use attribute value normalization.
- return normalizeAttributeValue(value);
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final String getNameOrOID()
- {
- Collection<String> names = getNames();
- if (names != null && !names.isEmpty())
- {
- return names.iterator().next();
- }
- return getOID();
- }
-
- /**
- * Retrieves the OID of the syntax with which this matching rule is
- * associated.
- *
- * @return The OID of the syntax with which this matching rule is
- * associated.
- */
- public abstract String getSyntaxOID();
-
- /** {@inheritDoc} */
- @Override
- public Syntax getSyntax()
- {
- return Schema.getCoreSchema().getSyntax(getSyntaxOID());
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getAssertion(final ByteSequence value)
- throws DecodeException
- {
- final ByteString assertionValue = normalizeAssertionValue(value);
- return new Assertion()
- {
- /** {@inheritDoc} */
- @Override
- public ConditionResult matches(ByteSequence attributeValue)
- {
- return valuesMatch(attributeValue, assertionValue);
- }
-
- /** {@inheritDoc} */
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory)
- throws DecodeException
- {
- throw new RuntimeException("Not implemented");
- }
- };
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getGreaterOrEqualAssertion(ByteSequence value)
- throws DecodeException
- {
- return UNDEFINED_ASSERTION;
- }
-
-
-
- /** {@inheritDoc} */
- @Override
- public Assertion getLessOrEqualAssertion(ByteSequence value)
- throws DecodeException
- {
- return UNDEFINED_ASSERTION;
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getSubstringAssertion(ByteSequence subInitial,
- List<? extends ByteSequence> subAnyElements, ByteSequence subFinal) throws DecodeException
- {
- return UNDEFINED_ASSERTION;
- }
-
-
-
- /** {@inheritDoc} */
- @Override
- public boolean isObsolete()
- {
- return false;
- }
-
- /**
- * Indicates whether the provided attribute value should be
- * considered a match for the given assertion value. This will only
- * be used for the purpose of extensible matching. Subclasses
- * should define more specific methods that are appropriate to the
- * matching rule type.
- *
- * @param attributeValue
- * The attribute value in a form that has been normalized
- * according to this matching rule.
- * @param assertionValue
- * The assertion value in a form that has been normalized
- * according to this matching rule.
- * @return {@code TRUE} if the attribute value should be considered
- * a match for the provided assertion value, {@code FALSE}
- * if it does not match, or {@code UNDEFINED} if the result
- * is undefined.
- */
- protected ConditionResult valuesMatch(
- ByteSequence attributeValue, ByteSequence assertionValue)
- {
- //Default implementation of most rule types.
- return ConditionResult.UNDEFINED;
- }
-
- private static final Comparator<ByteSequence> DEFAULT_COMPARATOR =
- new Comparator<ByteSequence>()
- {
- @Override
- public int compare(final ByteSequence o1, final ByteSequence o2)
- {
- return o1.compareTo(o2);
- }
- };
-
- /** {@inheritDoc} */
- @Override
- public Comparator<ByteSequence> comparator()
- {
- return DEFAULT_COMPARATOR;
- }
-
-
-
- /**
- * Retrieves the hash code for this matching rule. It will be
- * calculated as the sum of the characters in the OID.
- *
- * @return The hash code for this matching rule.
- */
- @Override
- public final int hashCode()
- {
- int hashCode = 0;
-
- String oidString = getOID();
- int oidLength = oidString.length();
- for (int i = 0; i < oidLength; i++)
- {
- hashCode += oidString.charAt(i);
- }
-
- return hashCode;
- }
-
-
-
- /**
- * Indicates whether the provided object is equal to this matching
- * rule. The provided object will be considered equal to this
- * matching rule only if it is a matching rule with the same OID.
- *
- * @param o
- * The object for which to make the determination.
- * @return {@code true} if the provided object is equal to this
- * matching rule, or {@code false} if it is not.
- */
- @Override
- public final boolean equals(Object o)
- {
- if (o == null)
- {
- return false;
- }
-
- if (this == o)
- {
- return true;
- }
-
- if (!(o instanceof MatchingRule))
- {
- return false;
- }
-
- return getOID().equals(((MatchingRule) o).getOID());
- }
-
-
-
- /**
- * Retrieves a string representation of this matching rule in the
- * format defined in RFC 2252.
- *
- * @return A string representation of this matching rule in the
- * format defined in RFC 2252.
- */
- @Override
- public final String toString()
- {
- StringBuilder buffer = new StringBuilder();
- toString(buffer);
- return buffer.toString();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final void toString(StringBuilder buffer)
- {
- buffer.append("( ");
- buffer.append(getOID());
- buffer.append(" NAME ");
- Collection<String> names = getNames();
- if(names.size()>1)
- {
- buffer.append("(");
- for(String name: names)
- {
- buffer.append(" '");
- buffer.append(name);
- buffer.append('\'');
- }
- buffer.append(" )");
- }
- else if (names.size() == 1)
- {
- buffer.append('\'');
- buffer.append(names.iterator().next());
- buffer.append('\'');
- }
-
- String description = getDescription();
- if ((description != null) && (description.length() > 0))
- {
- buffer.append(" DESC '");
- buffer.append(description);
- buffer.append('\'');
- }
-
- if (isObsolete())
- {
- buffer.append("' OBSOLETE SYNTAX ");
- }
- else
- {
- buffer.append(" SYNTAX ");
- }
-
- buffer.append(getSyntax().getOID());
- buffer.append(" )");
- }
-}
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/ApproximateMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/ApproximateMatchingRule.java
deleted file mode 100644
index 93e114e..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/ApproximateMatchingRule.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-
-/**
- * This class defines the set of methods and structures that must be
- * implemented by a Directory Server module that implements a matching
- * rule used for approximate matching.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=false,
- mayExtend=true,
- mayInvoke=false)
-public abstract class ApproximateMatchingRule
- extends AbstractMatchingRule
- implements MatchingRule
-{
- /**
- * Indicates whether the two provided normalized values are
- * approximately equal to each other.
- *
- * @param value1 The normalized form of the first value to
- * compare.
- * @param value2 The normalized form of the second value to
- * compare.
- *
- * @return {@code true} if the provided values are approximately
- * equal, or {@code false} if not.
- */
- public abstract boolean approximatelyMatch(ByteSequence value1,
- ByteSequence value2);
-
-
-
- /**
- * Indicates whether the provided attribute value should be
- * considered a match for the given assertion value. This will only
- * be used for the purpose of extensible matching. Other forms of
- * matching against approximate matching rules should use the
- * {@code areEqual} method.
- *
- * @param attributeValue The attribute value in a form that has
- * been normalized according to this
- * matching rule.
- * @param assertionValue The assertion value in a form that has
- * been normalized according to this
- * matching rule.
- *
- * @return {@code TRUE} if the attribute value should be considered
- * a match for the provided assertion value, {@code FALSE}
- * if it does not match, or {@code UNDEFINED} if the result
- * is undefined.
- */
- @Override
- public ConditionResult valuesMatch(ByteSequence attributeValue,
- ByteSequence assertionValue)
- {
- return ConditionResult.valueOf(
- approximatelyMatch(attributeValue, assertionValue));
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getAssertion(ByteSequence assertionValue) throws DecodeException
- {
- final ByteString normAssertionValue = normalizeAttributeValue(assertionValue);
- final DefaultAssertion approxAssertion = DefaultAssertion.approximate(normAssertionValue);
- return new Assertion()
- {
- @Override
- public ConditionResult matches(ByteSequence normalizedAttributeValue)
- {
- return valuesMatch(normalizedAttributeValue, normAssertionValue);
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory)
- throws DecodeException
- {
- return approxAssertion.createIndexQuery(factory);
- }
- };
- }
-
-}
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/EqualityMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/EqualityMatchingRule.java
deleted file mode 100644
index 7ba3b39..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/EqualityMatchingRule.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-
-/**
- * This class defines the set of methods and structures that must be
- * implemented by a Directory Server module that implements a matching
- * rule used for equality matching.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=false,
- mayExtend=true,
- mayInvoke=false)
-public abstract class EqualityMatchingRule
- extends AbstractMatchingRule
- implements MatchingRule
-{
- /**
- * Indicates whether the two provided normalized values are equal to
- * each other.
- *
- * @param value1 The normalized form of the first value to
- * compare.
- * @param value2 The normalized form of the second value to
- * compare.
- *
- * @return {@code true} if the provided values are equal, or
- * {@code false} if not.
- */
- public boolean areEqual(ByteSequence value1, ByteSequence value2)
- {
- return value1.equals(value2);
- }
-
- /**
- * Indicates whether the provided attribute value should be
- * considered a match for the given assertion value. This will only
- * be used for the purpose of extensible matching. Other forms of
- * matching against equality matching rules should use the
- * {@code areEqual} method.
- *
- * @param attributeValue The attribute value in a form that has
- * been normalized according to this
- * matching rule.
- * @param assertionValue The assertion value in a form that has
- * been normalized according to this
- * matching rule.
- *
- * @return {@code true} if the attribute value should be considered
- * a match for the provided assertion value, or
- * {@code false} if not.
- */
- @Override
- public ConditionResult valuesMatch(ByteSequence attributeValue,
- ByteSequence assertionValue)
- {
- return ConditionResult.valueOf(areEqual(attributeValue, assertionValue));
- }
-
-
-
- /**
- * Generates a hash code for the provided attribute value. This
- * version of the method will simply create a hash code from the
- * normalized form of the attribute value. For matching rules
- * explicitly designed to work in cases where byte-for-byte
- * comparisons of normalized values is not sufficient for
- * determining equality (e.g., if the associated attribute syntax is
- * based on hashed or encrypted values), then this method must be
- * overridden to provide an appropriate implementation for that
- * case.
- *
- * @param attributeValue The attribute value for which to generate
- * the hash code.
- *
- * @return The hash code generated for the provided attribute
- * value.
- */
- public int generateHashCode(ByteSequence attributeValue)
- {
- return attributeValue.hashCode();
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getAssertion(ByteSequence assertionValue) throws DecodeException
- {
- final ByteString normAssertionValue = normalizeAttributeValue(assertionValue);
- return getEqualityAssertion(normAssertionValue);
- }
-
- /**
- * Return the equality assertion for the matching rule.
- *
- * @param normAssertionValue
- * The normalized assertion value.
- * @return the assertion
- */
- protected Assertion getEqualityAssertion(final ByteString normAssertionValue)
- {
- final DefaultAssertion eqAssertion = DefaultAssertion.equality(normAssertionValue);
- return new Assertion()
- {
- @Override
- public ConditionResult matches(ByteSequence normalizedAttributeValue)
- {
- return valuesMatch(normalizedAttributeValue, normAssertionValue);
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory)
- throws DecodeException
- {
- return eqAssertion.createIndexQuery(factory);
- }
- };
- }
-
-}
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleMatchingRule.java
deleted file mode 100644
index c273c34..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleMatchingRule.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import java.util.Collection;
-
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-import org.forgerock.opendj.ldap.spi.Indexer;
-
-/**
- * This interface defines the set of methods that must be
- * implemented by a Directory Server module that implements an
- * Extensible matching rule.
- */
-@org.opends.server.types.PublicAPI(
- stability = org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate = false,
- mayExtend = true,
- mayInvoke = false)
-public interface ExtensibleMatchingRule extends MatchingRule
-{
- /**
- * Returns a collection of extensible indexers associated with this matching
- * rule.
- *
- * @return The collection of extensible indexers associated with this matching
- * rule.
- */
- Collection<Indexer> getIndexers();
-
- /**
- * Returns an index query appropriate for the provided attribute
- * value assertion.
- *
- * @param <T>
- * The type of index query created by the {@code factory}.
- * @param assertionValue
- * The attribute value assertion.
- * @param factory
- * The index query factory which should be used to
- * construct the index query.
- * @return The index query appropriate for the provided attribute
- * value assertion.
- * @throws DecodeException
- * If an error occurs while generating the index query.
- */
- <T> T createIndexQuery(ByteSequence assertionValue,
- IndexQueryFactory<T> factory) throws DecodeException;
-}
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/MatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/MatchingRule.java
deleted file mode 100644
index e0aeb2a..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/MatchingRule.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.schema.Syntax;
-
-/**
- * This interface defines the set of methods that must be implemented
- * by a Directory Server module that implements a matching rule.
- */
-@org.opends.server.types.PublicAPI(
- stability = org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate = false,
- mayExtend = true,
- mayInvoke = false)
-public interface MatchingRule
-{
-
- /**
- * Retrieves all names for this matching rule.
- *
- * @return All names for this matching rule.
- */
- Collection<String> getNames();
-
-
-
- /**
- * Retrieves the OID for this matching rule.
- *
- * @return The OID for this matching rule.
- */
- String getOID();
-
- /**
- * Retrieves the name or OID for this matching rule. If it has a
- * name, then it will be returned. Otherwise, the OID will be
- * returned.
- *
- * @return The name or OID for this matching rule.
- */
- String getNameOrOID();
-
-
-
- /**
- * Retrieves the description for this matching rule.
- *
- * @return The description for this matching rule, or {@code null}
- * if there is none.
- */
- String getDescription();
-
- /**
- * Whole class to be replaced by the equivalent SDK class.
- *
- * @return SDK syntax
- */
- Syntax getSyntax();
-
- /**
- * Whole class to be replaced by the equivalent SDK class.
- *
- * @param assertionValue
- * the value
- * @return SDK syntax
- * @throws DecodeException
- * if problem
- */
- Assertion getAssertion(ByteSequence assertionValue) throws DecodeException;
-
- /**
- * Returns the normalized form of the provided assertion value, which is
- * best suited for efficiently performing greater than or equal ordering
- * matching operations on that value. The assertion value is guaranteed to
- * be valid against this matching rule's assertion syntax.
- *
- * @param assertionValue
- * The syntax checked assertion value to be normalized.
- * @return The normalized version of the provided assertion value.
- * @throws DecodeException
- * if the syntax of the value is not valid.
- */
- Assertion getGreaterOrEqualAssertion(ByteSequence assertionValue) throws DecodeException;
-
- /**
- * Returns the normalized form of the provided assertion value, which is
- * best suited for efficiently performing greater than or equal ordering
- * matching operations on that value. The assertion value is guaranteed to
- * be valid against this matching rule's assertion syntax.
- *
- * @param assertionValue
- * The syntax checked assertion value to be normalized.
- * @return The normalized version of the provided assertion value.
- * @throws DecodeException
- * if the syntax of the value is not valid.
- */
- Assertion getLessOrEqualAssertion(ByteSequence assertionValue) throws DecodeException;
-
- /**
- * Returns the normalized form of the provided assertion substring values,
- * which is best suited 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.
- * @param subAnyElements
- * 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.
- * @return The normalized version of the provided assertion value.
- * @throws DecodeException
- * if the syntax of the value is not valid.
- */
- Assertion getSubstringAssertion(ByteSequence subInitial, List<? extends ByteSequence> subAnyElements,
- ByteSequence subFinal) throws DecodeException;
-
- /**
- * Indicates whether this matching rule is declared "OBSOLETE". The
- * default implementation will always return {@code false}. If that
- * is not acceptable for a particular matching rule implementation,
- * then it should override this method and perform the appropriate
- * processing to return the correct value.
- *
- * @return {@code true} if this matching rule is declared
- * "OBSOLETE", or {@code false} if not.
- */
- boolean isObsolete();
-
-
-
- /**
- * Retrieves the normalized form of the provided value, which is
- * best suite for efficiently performing matching operations on
- * that value.
- *
- * @param value
- * The value to be normalized.
- * @return The normalized version of the provided value.
- * @throws DecodeException
- * If the provided value is invalid according to the
- * associated attribute syntax.
- */
- ByteString normalizeAttributeValue(ByteSequence value)
- throws DecodeException;
-
- /**
- * Appends a string representation of this matching rule in the
- * format defined in RFC 2252 to the provided buffer.
- *
- * @param buffer
- * The buffer to which the information should be appended.
- */
- void toString(StringBuilder buffer);
-
- /**
- * 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.
- */
- Comparator<ByteSequence> comparator();
-}
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/OrderingMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/OrderingMatchingRule.java
deleted file mode 100644
index b9d641e..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/OrderingMatchingRule.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-
-
-import java.io.Serializable;
-import java.util.Comparator;
-import org.forgerock.opendj.ldap.ByteSequence;
-
-
-
-/**
- * This interface defines the set of methods that must be implemented
- * by a Directory Server module that implements a matching
- * rule used for determining the correct order of values when sorting
- * or processing range filters.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=false,
- mayExtend=true,
- mayInvoke=false)
-public interface OrderingMatchingRule
- extends MatchingRule,Comparator<byte[]>,Serializable
-{
- /**
- * Compares the first value to the second and returns a value that
- * indicates their relative order.
- *
- * @param value1 The normalized form of the first value to
- * compare.
- * @param value2 The normalized form of the second value to
- * compare.
- *
- * @return A negative integer if {@code value1} should come before
- * {@code value2} in ascending order, a positive integer if
- * {@code value1} should come after {@code value2} in
- * ascending order, or zero if there is no difference
- * between the values with regard to ordering.
- */
- public abstract int compareValues(ByteSequence value1,
- ByteSequence value2);
-}
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/SubstringMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/api/SubstringMatchingRule.java
deleted file mode 100644
index 8eaec37..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/api/SubstringMatchingRule.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.api;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.TreeSet;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-
-/**
- * This class defines the set of methods and structures that must be
- * implemented by a Directory Server module that implements a matching
- * rule used for substring matching.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.VOLATILE,
- mayInstantiate=false,
- mayExtend=true,
- mayInvoke=false)
-public abstract class SubstringMatchingRule
- extends AbstractMatchingRule
- implements MatchingRule
-{
- /**
- * Normalizes the provided value fragment into a form that can be
- * used to efficiently compare values.
- *
- * @param substring The value fragment to be normalized.
- *
- * @return The normalized form of the value fragment.
- *
- * @throws DecodeException If the provided value fragment is
- * not acceptable according to the
- * associated syntax.
- */
- public abstract ByteString normalizeSubstring(
- ByteSequence substring) throws DecodeException;
-
-
-
- /**
- * Determines whether the provided value matches the given substring
- * filter components. Note that any of the substring filter
- * components may be {@code null} but at least one of them must be
- * non-{@code null}.
- *
- * @param value The normalized value against which to
- * compare the substring components.
- * @param subInitial 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.
- * @param subFinal The normalized substring value fragment
- * that should appear at the end of the
- * target value.
- *
- * @return {@code true} if the provided value does match the given
- * substring components, or {@code false} if not.
- */
- public boolean valueMatchesSubstring(ByteSequence value,
- ByteSequence subInitial,
- List<ByteSequence> subAnyElements,
- ByteSequence subFinal)
- {
- int valueLength = value.length();
-
- int pos = 0;
- if (subInitial != null)
- {
- int initialLength = subInitial.length();
- if (initialLength > valueLength)
- {
- return false;
- }
-
- for (; pos < initialLength; pos++)
- {
- if (subInitial.byteAt(pos) != value.byteAt(pos))
- {
- return false;
- }
- }
- }
-
-
- if ((subAnyElements != null) && (! subAnyElements.isEmpty()))
- {
- for (ByteSequence element : subAnyElements)
- {
- int anyLength = element.length();
- if(anyLength == 0)
- continue;
- int end = valueLength - anyLength;
- boolean match = false;
- for (; pos <= end; pos++)
- {
- if (element.byteAt(0) == value.byteAt(pos))
- {
- boolean subMatch = true;
- for (int i=1; i < anyLength; i++)
- {
- if (element.byteAt(i) != value.byteAt(pos+i))
- {
- subMatch = false;
- break;
- }
- }
-
- if (subMatch)
- {
- match = subMatch;
- break;
- }
- }
- }
-
- if (match)
- {
- pos += anyLength;
- }
- else
- {
- return false;
- }
- }
- }
-
-
- if (subFinal != null)
- {
- int finalLength = subFinal.length();
-
- if ((valueLength - finalLength) < pos)
- {
- return false;
- }
-
- pos = valueLength - finalLength;
- for (int i=0; i < finalLength; i++,pos++)
- {
- if (subFinal.byteAt(i) != value.byteAt(pos))
- {
- return false;
- }
- }
- }
-
-
- return true;
- }
-
- /**
- * Default assertion implementation for substring matching rules.
- * For example, with the assertion value "initial*any1*any2*any3*final",
- * the assertion will be decomposed like this:
- * <ul>
- * <li>normInitial will contain "initial"</li>
- * <li>normAnys will contain [ "any1", "any2", "any3" ]</li>
- * <li>normFinal will contain "final"</li>
- * </ul>
- */
- static final class DefaultSubstringAssertion implements Assertion {
- /** Normalized substring for the text before the first '*' character. */
- private final ByteString normInitial;
- /** Normalized substrings for all text chunks in between '*' characters. */
- private final ByteString[] normAnys;
- /** Normalized substring for the text after the last '*' character. */
- private final ByteString normFinal;
-
- private DefaultSubstringAssertion(final ByteString normInitial,
- final ByteString[] normAnys, final ByteString normFinal) {
- this.normInitial = normInitial;
- this.normAnys = normAnys;
- this.normFinal = normFinal;
- }
-
- /** {@inheritDoc} */
- @Override
- public ConditionResult matches(final ByteSequence normalizedAttributeValue) {
- final int valueLength = normalizedAttributeValue.length();
-
- int pos = 0;
- if (normInitial != null) {
- final int initialLength = normInitial.length();
- if (initialLength > valueLength) {
- return ConditionResult.FALSE;
- }
-
- for (; pos < initialLength; pos++) {
- if (normInitial.byteAt(pos) != normalizedAttributeValue.byteAt(pos)) {
- return ConditionResult.FALSE;
- }
- }
- }
-
- if (normAnys != null) {
- matchEachSubstring:
- for (final ByteSequence element : normAnys) {
- final int anyLength = element.length();
- final int end = valueLength - anyLength;
- matchCurrentSubstring:
- for (; pos <= end; pos++) {
- // Try to match all characters from the substring
- for (int i = 0; i < anyLength; i++) {
- if (element.byteAt(i) != normalizedAttributeValue.byteAt(pos + i)) {
- // not a match,
- // try to find a match in the rest of this value
- continue matchCurrentSubstring;
- }
- }
- // we just matched current substring,
- // go try to match the next substring
- pos += anyLength;
- continue matchEachSubstring;
- }
- // Could not match current substring
- return ConditionResult.FALSE;
- }
- }
-
- if (normFinal != null) {
- final int finalLength = normFinal.length();
-
- if (valueLength - finalLength < pos) {
- return ConditionResult.FALSE;
- }
-
- pos = valueLength - finalLength;
- for (int i = 0; i < finalLength; i++, pos++) {
- if (normFinal.byteAt(i) != normalizedAttributeValue.byteAt(pos)) {
- return ConditionResult.FALSE;
- }
- }
- }
-
- return ConditionResult.TRUE;
- }
-
- /** {@inheritDoc} */
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
- final Collection<T> subqueries = new LinkedList<T>();
- if (normInitial != null) {
- // relies on the fact that equality indexes are also ordered
- subqueries.add(rangeMatch(factory, "equality", normInitial));
- }
- if (normAnys != null) {
- for (ByteString normAny : normAnys) {
- substringMatch(factory, normAny, subqueries);
- }
- }
- if (normFinal != null) {
- substringMatch(factory, normFinal, subqueries);
- }
- if (normInitial != null) {
- // Add this one last to minimize the risk to run the same search twice
- // (possible overlapping with the use of equality index at the start of this method)
- substringMatch(factory, normInitial, subqueries);
- }
- return factory.createIntersectionQuery(subqueries);
- }
-
- private <T> T rangeMatch(IndexQueryFactory<T> factory, String indexID, ByteSequence lower) {
- // Iterate through all the keys that have this value as the prefix.
-
- // Set the upper bound for a range search.
- // We need a key for the upper bound that is of equal length
- // but slightly greater than the lower bound.
- final ByteStringBuilder upper = new ByteStringBuilder(lower);
-
- for (int i = upper.length() - 1; i >= 0; i--) {
- if (upper.byteAt(i) == (byte) 0xFF) {
- // We have to carry the overflow to the more significant byte.
- upper.setByte(i, (byte) 0);
- } else {
- // No overflow, we can stop.
- upper.setByte(i, (byte) (upper.byteAt(i) + 1));
- break;
- }
- }
-
- // Read the range: lower <= keys < upper.
- return factory.createRangeMatchQuery(indexID, lower, upper, true, false);
- }
-
- private <T> void substringMatch(final IndexQueryFactory<T> factory, final ByteString normSubstring,
- final Collection<T> subqueries) {
- int substrLength = factory.getIndexingOptions().substringKeySize();
-
- // There are two cases, depending on whether the user-provided
- // substring is smaller than the configured index substring length or not.
- if (normSubstring.length() < substrLength) {
- subqueries.add(rangeMatch(factory, "substring", normSubstring));
- } else {
- // Break the value up into fragments of length equal to the
- // index substring length, and read those keys.
-
- // Eliminate duplicates by putting the keys into a set.
- final TreeSet<ByteSequence> substringKeys = new TreeSet<ByteSequence>();
-
- // Example: The value is ABCDE and the substring length is 3.
- // We produce the keys ABC BCD CDE.
- for (int first = 0, last = substrLength;
- last <= normSubstring.length(); first++, last++) {
- substringKeys.add(normSubstring.subSequence(first, first + substrLength));
- }
-
- for (ByteSequence key : substringKeys) {
- subqueries.add(factory.createExactMatchQuery("substring", key));
- }
- }
- }
-
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getSubstringAssertion(ByteSequence subInitial,
- List<? extends ByteSequence> subAnyElements, ByteSequence subFinal)
- throws DecodeException
- {
- final ByteString normInitial = subInitial == null ? null : normalizeSubstring(subInitial);
-
- ByteString[] normAnys = null;
- if (subAnyElements != null && !subAnyElements.isEmpty())
- {
- normAnys = new ByteString[subAnyElements.size()];
- for (int i = 0; i < subAnyElements.size(); i++)
- {
- normAnys[i] = normalizeSubstring(subAnyElements.get(i));
- }
- }
- final ByteString normFinal = subFinal == null ? null : normalizeSubstring(subFinal);
-
- return new DefaultSubstringAssertion(normInitial, normAnys, normFinal);
- }
-
-}
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/schema/AbstractOrderingMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/schema/AbstractOrderingMatchingRule.java
deleted file mode 100644
index df653d9..0000000
--- a/opendj3-server-dev/src/server/org/opends/server/schema/AbstractOrderingMatchingRule.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- * Copyright 2014 ForgeRock AS
- */
-package org.opends.server.schema;
-
-
-import java.util.Comparator;
-
-import org.forgerock.opendj.ldap.*;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-import org.opends.server.api.AbstractMatchingRule;
-import org.opends.server.api.OrderingMatchingRule;
-
-/**
- * This class defines the set of methods and structures that must be implemented
- * by a Directory Server module that implements a matching rule used for
- * ordering matching.
- */
-public abstract class AbstractOrderingMatchingRule
- extends AbstractMatchingRule
- implements OrderingMatchingRule
-{
-
- /**
- * Retrieves the description for this matching rule.
- *
- * @return The description for this matching rule, or <CODE>null</CODE> if
- * there is none.
- */
- @Override
- public String getDescription()
- {
- // There is no standard description for this matching rule.
- return null;
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getAssertion(final ByteSequence assertionValue) throws DecodeException
- {
- final ByteString normAssertionValue = normalizeAttributeValue(assertionValue);
- return new Assertion()
- {
- @Override
- public ConditionResult matches(final ByteSequence attributeValue)
- {
- return ConditionResult.valueOf(compareValues(attributeValue, normAssertionValue) < 0);
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException
- {
- return factory.createRangeMatchQuery("ordering", ByteString.empty(), normAssertionValue, false, false);
- }
- };
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getGreaterOrEqualAssertion(final ByteSequence assertionValue) throws DecodeException
- {
- final ByteString normAssertionValue = normalizeAttributeValue(assertionValue);
- return new Assertion()
- {
- @Override
- public ConditionResult matches(final ByteSequence normalizedAttributeValue) {
- return ConditionResult.valueOf(compareValues(normalizedAttributeValue, normAssertionValue) >= 0);
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
- return factory.createRangeMatchQuery("ordering", normAssertionValue, ByteString.empty(), true, false);
- }
- };
- }
-
- /** {@inheritDoc} */
- @Override
- public Assertion getLessOrEqualAssertion(final ByteSequence assertionValue) throws DecodeException
- {
- final ByteString normAssertionValue = normalizeAttributeValue(assertionValue);
- return new Assertion()
- {
- @Override
- public ConditionResult matches(final ByteSequence normalizedAttributeValue)
- {
- return ConditionResult.valueOf(compareValues(normalizedAttributeValue, normAssertionValue) <= 0);
- }
-
- @Override
- public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException
- {
- return factory.createRangeMatchQuery("ordering", ByteString.empty(), normAssertionValue, false, true);
- }
- };
- }
-
- /** {@inheritDoc} */
- @Override
- public Comparator<ByteSequence> comparator()
- {
- return new Comparator<ByteSequence>()
- {
- @Override
- public int compare(ByteSequence o1, ByteSequence o2)
- {
- return AbstractOrderingMatchingRule.this.compare(o1.toByteArray(), o2.toByteArray());
- }
- };
- }
-
-
-}
--
Gitblit v1.10.0