From 496cddd559be59f585671b69072abb1dd0c40ec2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 28 Feb 2014 13:15:33 +0000
Subject: [PATCH] OPENDJ-1308 Migrate schema support
---
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java | 11
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerFirstComponentEqualityMatchingRuleImpl.java | 18 -
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java | 23 -
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java | 11
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EnumSyntaxImpl.java | 12
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/GeneralizedTimeEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ProtocolInformationEqualityMatchingRuleImpl.java | 11
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListSubstringMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java | 5
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractApproximateMatchingRuleImpl.java | 48 ++++
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java | 6
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java | 22 +
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactSubstringMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreSubstringMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BitStringEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactOrderingMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/KeywordEqualityMatchingRuleImpl.java | 79 ++----
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BooleanEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java | 6
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerEqualityMatchingRuleImpl.java | 8
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java | 9
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractOrderingMatchingRuleImpl.java | 10
/dev/null | 155 ------------
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java | 31 +-
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractEqualityMatchingRuleImpl.java | 48 ++++
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreOrderingMatchingRuleImpl.java | 9
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EnumSyntaxTestCase.java | 44 +--
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/PresentationAddressEqualityMatchingRuleImpl.java | 11
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java | 10
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AuthPasswordExactEqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java | 2
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java | 6
44 files changed, 249 insertions(+), 421 deletions(-)
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java
index 6d9f84c..e736b20 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Assertion.java
@@ -24,7 +24,6 @@
* Copyright 2009 Sun Microsystems, Inc.
* Portions copyright 2014 ForgeRock AS
*/
-
package org.forgerock.opendj.ldap;
/**
@@ -35,11 +34,11 @@
* Indicates whether the provided attribute value should be considered a
* match for this assertion value according to the matching rule.
*
- * @param attributeValue
+ * @param normalizedAttributeValue
* The normalized attribute value.
* @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.
*/
- public abstract ConditionResult matches(ByteSequence attributeValue);
+ ConditionResult matches(ByteSequence normalizedAttributeValue);
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractApproximateMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractApproximateMatchingRuleImpl.java
new file mode 100644
index 0000000..a2319e0
--- /dev/null
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractApproximateMatchingRuleImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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.forgerock.opendj.ldap.schema;
+
+import org.forgerock.opendj.ldap.Assertion;
+import org.forgerock.opendj.ldap.ByteSequence;
+import org.forgerock.opendj.ldap.DecodeException;
+
+/**
+ * This class implements an approximate matching rule that matches normalized
+ * values in byte order.
+ */
+abstract class AbstractApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl {
+
+ AbstractApproximateMatchingRuleImpl() {
+ // Nothing to do.
+ }
+
+ @Override
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
+ throws DecodeException {
+ return new DefaultEqualityAssertion(normalizeAttributeValue(schema, assertionValue));
+ }
+
+}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractEqualityMatchingRuleImpl.java
new file mode 100644
index 0000000..d6af5b8
--- /dev/null
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractEqualityMatchingRuleImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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.forgerock.opendj.ldap.schema;
+
+import org.forgerock.opendj.ldap.Assertion;
+import org.forgerock.opendj.ldap.ByteSequence;
+import org.forgerock.opendj.ldap.DecodeException;
+
+/**
+ * This class implements an equality matching rule that matches normalized
+ * values in byte order.
+ */
+abstract class AbstractEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+
+ AbstractEqualityMatchingRuleImpl() {
+ // Nothing to do.
+ }
+
+ @Override
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
+ throws DecodeException {
+ return new DefaultEqualityAssertion(normalizeAttributeValue(schema, assertionValue));
+ }
+
+}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
index 4031b8c..d427f29 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
@@ -38,16 +38,15 @@
* matches normalized values in byte order.
*/
abstract class AbstractMatchingRuleImpl implements MatchingRuleImpl {
- static class DefaultEqualityAssertion implements Assertion {
- ByteSequence normalizedAssertionValue;
+ static final class DefaultEqualityAssertion implements Assertion {
+ private final ByteSequence normalizedAssertionValue;
- protected DefaultEqualityAssertion(final ByteSequence normalizedAssertionValue) {
+ DefaultEqualityAssertion(final ByteSequence normalizedAssertionValue) {
this.normalizedAssertionValue = normalizedAssertionValue;
}
public ConditionResult matches(final ByteSequence attributeValue) {
- return normalizedAssertionValue.equals(attributeValue) ? ConditionResult.TRUE
- : ConditionResult.FALSE;
+ return ConditionResult.valueOf(normalizedAssertionValue.equals(attributeValue));
}
}
@@ -72,9 +71,9 @@
return DEFAULT_COMPARATOR;
}
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
- return new DefaultEqualityAssertion(normalizeAttributeValue(schema, value));
+ return UNDEFINED_ASSERTION;
}
public Assertion getSubstringAssertion(final Schema schema, final ByteSequence subInitial,
@@ -92,4 +91,13 @@
throws DecodeException {
return UNDEFINED_ASSERTION;
}
+
+ static void trimConsecutiveSpaces(StringBuilder buffer) {
+ for (int pos = buffer.length() - 1; pos > 0; pos--) {
+ if (buffer.charAt(pos) == ' '
+ && buffer.charAt(pos - 1) == ' ') {
+ buffer.delete(pos, pos + 1);
+ }
+ }
+ }
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractOrderingMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractOrderingMatchingRuleImpl.java
index f416ac7..25e2ade 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractOrderingMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractOrderingMatchingRuleImpl.java
@@ -40,14 +40,12 @@
// Nothing to do.
}
- @Override
public Assertion getAssertion(final Schema schema, final ByteSequence value)
throws DecodeException {
final ByteString normAssertion = normalizeAttributeValue(schema, value);
return new Assertion() {
public ConditionResult matches(final ByteSequence attributeValue) {
- return attributeValue.compareTo(normAssertion) < 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE;
+ return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) < 0);
}
};
}
@@ -58,8 +56,7 @@
final ByteString normAssertion = normalizeAttributeValue(schema, value);
return new Assertion() {
public ConditionResult matches(final ByteSequence attributeValue) {
- return attributeValue.compareTo(normAssertion) >= 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE;
+ return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) >= 0);
}
};
}
@@ -70,8 +67,7 @@
final ByteString normAssertion = normalizeAttributeValue(schema, value);
return new Assertion() {
public ConditionResult matches(final ByteSequence attributeValue) {
- return attributeValue.compareTo(normAssertion) <= 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE;
+ return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) <= 0);
}
};
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
index b0af401..d3ea4a9 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
@@ -131,9 +131,9 @@
}
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
- if (value.length() == 0) {
+ if (assertionValue.length() == 0) {
throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_EMPTY.get());
}
@@ -141,7 +141,7 @@
ByteSequence finalString = null;
List<ByteSequence> anyStrings = null;
- final String valueString = value.toString();
+ final String valueString = assertionValue.toString();
if (valueString.length() == 1 && valueString.charAt(0) == '*') {
return getSubstringAssertion(schema, initialString, anyStrings, finalString);
@@ -155,7 +155,7 @@
initialString = normalizeSubString(schema, bytes);
}
if (reader.remaining() == 0) {
- throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_NO_WILDCARDS.get(value
+ throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_NO_WILDCARDS.get(assertionValue
.toString()));
}
while (true) {
@@ -164,7 +164,7 @@
if (reader.remaining() > 0) {
if (bytes.length() == 0) {
throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_CONSECUTIVE_WILDCARDS
- .get(value.toString(), reader.pos()));
+ .get(assertionValue.toString(), reader.pos()));
}
if (anyStrings == null) {
anyStrings = new LinkedList<ByteSequence>();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AuthPasswordExactEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AuthPasswordExactEqualityMatchingRuleImpl.java
index 9fb591a..69ff26f 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AuthPasswordExactEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AuthPasswordExactEqualityMatchingRuleImpl.java
@@ -33,7 +33,7 @@
* This class implements the authPasswordMatch matching rule defined in RFC
* 3112.
*/
-final class AuthPasswordExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class AuthPasswordExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
final StringBuilder[] authPWComponents =
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BitStringEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BitStringEqualityMatchingRuleImpl.java
index fdff25c..69e5d66 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BitStringEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BitStringEqualityMatchingRuleImpl.java
@@ -38,7 +38,7 @@
* This class defines the bitStringMatch matching rule defined in X.520 and
* referenced in RFC 2252.
*/
-final class BitStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class BitStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
final String valueString = value.toString().toUpperCase();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BooleanEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BooleanEqualityMatchingRuleImpl.java
index 64e6f2a..75ff976 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BooleanEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/BooleanEqualityMatchingRuleImpl.java
@@ -35,7 +35,7 @@
* This class defines the booleanMatch matching rule defined in X.520 and
* referenced in RFC 4519.
*/
-final class BooleanEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class BooleanEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
final String valueString = value.toString().toUpperCase();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java
index e84c2cd..67fc89e 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* This class defines the caseExactMatch matching rule defined in X.520 and
* referenced in RFC 4519.
*/
-final class CaseExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class CaseExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD);
@@ -53,14 +53,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java
index 020a22b..f6b1694 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java
@@ -39,7 +39,7 @@
* This class implements the caseExactIA5Match matching rule defined in RFC
* 2252.
*/
-final class CaseExactIA5EqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class CaseExactIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
final StringBuilder buffer = new StringBuilder();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactOrderingMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactOrderingMatchingRuleImpl.java
index 6576607..f2cf39e 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactOrderingMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactOrderingMatchingRuleImpl.java
@@ -53,14 +53,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactSubstringMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactSubstringMatchingRuleImpl.java
index fe13a21..d16664e 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactSubstringMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactSubstringMatchingRuleImpl.java
@@ -64,14 +64,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java
index 58fbf25..4c2bd81 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* This class defines the caseIgnoreMatch matching rule defined in X.520 and
* referenced in RFC 2252.
*/
-final class CaseIgnoreEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class CaseIgnoreEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, CASE_FOLD);
@@ -53,14 +53,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java
index ec39148..40a30ad 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java
@@ -39,7 +39,7 @@
* This class implements the caseIgnoreIA5Match matching rule defined in RFC
* 2252.
*/
-final class CaseIgnoreIA5EqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class CaseIgnoreIA5EqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
final StringBuilder buffer = new StringBuilder();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListEqualityMatchingRuleImpl.java
index a36eef4..67a0746 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* This class implements the caseIgnoreListMatch matching rule defined in X.520
* and referenced in RFC 2252.
*/
-final class CaseIgnoreListEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class CaseIgnoreListEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, CASE_FOLD);
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListSubstringMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListSubstringMatchingRuleImpl.java
index 3b6d605..15f52b4 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListSubstringMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreListSubstringMatchingRuleImpl.java
@@ -96,14 +96,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreOrderingMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreOrderingMatchingRuleImpl.java
index f679124..9bb7185 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreOrderingMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreOrderingMatchingRuleImpl.java
@@ -53,14 +53,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreSubstringMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreSubstringMatchingRuleImpl.java
index 3dd1ad7..5cb9ae7 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreSubstringMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreSubstringMatchingRuleImpl.java
@@ -66,14 +66,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
index b78ac06..3c6ffe9 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
@@ -811,7 +811,7 @@
.syntaxOID(SYNTAX_NAME_AND_OPTIONAL_UID_OID).extraProperties(RFC4512_ORIGIN)
.implementation(new UniqueMemberEqualityMatchingRuleImpl()).addToSchema();
builder.buildMatchingRule(EMR_WORD_OID).names(EMR_WORD_NAME).syntaxOID(SYNTAX_DIRECTORY_STRING_OID)
- .extraProperties(RFC4512_ORIGIN).implementation(new WordEqualityMatchingRuleImpl())
+ .extraProperties(RFC4512_ORIGIN).implementation(new KeywordEqualityMatchingRuleImpl())
.addToSchema();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java
index 092782b..0eb0d52 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java
@@ -47,15 +47,15 @@
* objectclass descriptions) in which the "first component" is the first item
* after the opening parenthesis.
*/
-final class DirectoryStringFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class DirectoryStringFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value) {
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) {
final StringBuilder buffer = new StringBuilder();
- prepareUnicode(buffer, value, TRIM, CASE_FOLD);
+ prepareUnicode(buffer, assertionValue, TRIM, CASE_FOLD);
final int bufferLength = buffer.length();
if (bufferLength == 0) {
- if (value.length() > 0) {
+ if (assertionValue.length() > 0) {
// This should only happen if the value is composed entirely of
// spaces. In that case, the normalized value is a single space.
return new DefaultEqualityAssertion(SchemaConstants.SINGLE_SPACE_VALUE);
@@ -65,14 +65,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return new DefaultEqualityAssertion(ByteString.valueOf(buffer.toString()));
}
@@ -95,8 +88,7 @@
}
// The next character must be an open parenthesis. If it is not,
- // then
- // that is an error.
+ // then that is an error.
final char c = reader.read();
if (c != '(') {
final LocalizableMessage message =
@@ -105,8 +97,7 @@
throw DecodeException.error(message);
}
- // Skip over any spaces immediately following the opening
- // parenthesis.
+ // Skip over any spaces immediately following the opening parenthesis.
reader.skipWhitespaces();
// The next set of characters must be the OID.
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java
index b2a7fb0..b6f1a30 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* This class defines the distinguishedNameMatch matching rule defined in X.520
* and referenced in RFC 2252.
*/
-final class DistinguishedNameEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class DistinguishedNameEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
/**
* {@inheritDoc}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java
index 5202ef8..3a97d89 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java
@@ -49,7 +49,7 @@
* redundant checks that aren't needed. It has also been updated to always only
* generate a single value rather than one or possibly two values.
*/
-final class DoubleMetaphoneApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class DoubleMetaphoneApproximateMatchingRuleImpl extends AbstractApproximateMatchingRuleImpl {
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EnumSyntaxImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EnumSyntaxImpl.java
index 0194f85..f3f61d2 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EnumSyntaxImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EnumSyntaxImpl.java
@@ -23,13 +23,14 @@
*
* Copyright 2009 Sun Microsystems, Inc.
*/
-
package org.forgerock.opendj.ldap.schema;
import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD;
import static com.forgerock.opendj.util.StringPrepProfile.TRIM;
import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode;
import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_INVALID_VALUE;
+
+import static org.forgerock.opendj.ldap.schema.AbstractMatchingRuleImpl.*;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.AMR_DOUBLE_METAPHONE_OID;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_CASE_IGNORE_OID;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_OID_GENERIC_ENUM;
@@ -131,14 +132,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return buffer.toString();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java
index 7659372..c213b55 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java
@@ -36,14 +36,14 @@
* consider two values approximately equal only if they have the same length. It
* is intended purely for testing purposes.
*/
-final class EqualLengthApproximateMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class EqualLengthApproximateMatchingRuleImpl extends AbstractApproximateMatchingRuleImpl {
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
return new Assertion() {
+ @Override
public ConditionResult matches(final ByteSequence attributeValue) {
- return attributeValue.length() == value.length() ? ConditionResult.TRUE
- : ConditionResult.FALSE;
+ return ConditionResult.valueOf(attributeValue.length() == assertionValue.length());
}
};
}
@@ -51,6 +51,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
return value.toByteString();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/GeneralizedTimeEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/GeneralizedTimeEqualityMatchingRuleImpl.java
index 6682e1f..03e7163 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/GeneralizedTimeEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/GeneralizedTimeEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* This class defines the generalizedTimeMatch matching rule defined in X.520
* and referenced in RFC 2252.
*/
-final class GeneralizedTimeEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class GeneralizedTimeEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
try {
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerEqualityMatchingRuleImpl.java
index fd8d203..b60b03e 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerEqualityMatchingRuleImpl.java
@@ -38,20 +38,18 @@
* This class defines the integerMatch matching rule defined in X.520 and
* referenced in RFC 2252.
*/
-final class IntegerEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class IntegerEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
+ @Override
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
try {
return ByteString.valueOf(Integer.parseInt(value.toString()));
} catch (final Exception e) {
logger.debug(LocalizableMessage.raw("%s", e));
-
- final LocalizableMessage message =
- WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString());
- throw DecodeException.error(message);
+ throw DecodeException.error(WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value));
}
}
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerFirstComponentEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerFirstComponentEqualityMatchingRuleImpl.java
index 781ff17..d62dddd 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerFirstComponentEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerFirstComponentEqualityMatchingRuleImpl.java
@@ -33,7 +33,6 @@
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 com.forgerock.opendj.util.SubstringReader;
@@ -45,30 +44,23 @@
* objectclass descriptions) in which the "first component" is the first item
* after the opening parenthesis.
*/
-final class IntegerFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class IntegerFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
try {
- final String definition = value.toString();
+ final String definition = assertionValue.toString();
final SubstringReader reader = new SubstringReader(definition);
final int intValue = SchemaUtils.readRuleID(reader);
-
- return new Assertion() {
- public ConditionResult matches(final ByteSequence attributeValue) {
- final int actualIntValue = attributeValue.toByteString().toInt();
- return intValue == actualIntValue ? ConditionResult.TRUE
- : ConditionResult.FALSE;
- }
- };
+ return new DefaultEqualityAssertion(ByteString.valueOf(intValue));
} catch (final Exception e) {
logger.debug(LocalizableMessage.raw("%s", e));
final LocalizableMessage message =
- ERR_EMR_INTFIRSTCOMP_FIRST_COMPONENT_NOT_INT.get(value.toString());
+ ERR_EMR_INTFIRSTCOMP_FIRST_COMPONENT_NOT_INT.get(assertionValue.toString());
throw DecodeException.error(message);
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java
index aa97d41..b7fb8c1 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java
@@ -42,16 +42,14 @@
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
+ @Override
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
try {
return ByteString.valueOf(Integer.parseInt(value.toString()));
} catch (final Exception e) {
logger.debug(LocalizableMessage.raw("%s", e));
-
- final LocalizableMessage message =
- WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value.toString());
- throw DecodeException.error(message);
+ throw DecodeException.error(WARN_ATTR_SYNTAX_ILLEGAL_INTEGER.get(value));
}
}
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/KeywordEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/KeywordEqualityMatchingRuleImpl.java
index a860ee4..ed0fd91 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/KeywordEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/KeywordEqualityMatchingRuleImpl.java
@@ -39,8 +39,8 @@
* This class implements the keywordMatch matching rule defined in X.520. That
* document defines "keyword" as implementation-specific, but in this case we
* will consider it a match if the assertion value is contained within the
- * attribute value and is bounded by the edge of the value or any of the
- * following characters: <BR>
+ * attribute value and is bounded by the start or the end of the attribute value
+ * or any of the following characters: <BR>
* <UL>
* <LI>A space</LI>
* <LI>A period</LI>
@@ -54,11 +54,11 @@
* <LI>An equal sign</LI>
* </UL>
*/
-final class KeywordEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class KeywordEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
- final String normalStr = normalize(value);
+ final String normalStr = normalize(assertionValue);
return new Assertion() {
public ConditionResult matches(final ByteSequence attributeValue) {
@@ -73,44 +73,14 @@
if (pos > 0) {
final char c = valueStr1.charAt(pos - 1);
- switch (c) {
- case ' ':
- case '.':
- case ',':
- case '/':
- case '$':
- case '+':
- case '-':
- case '_':
- case '#':
- case '=':
- // These are all acceptable.
- break;
-
- default:
- // Anything else is not.
+ if (!isAcceptable(c)) {
return ConditionResult.FALSE;
}
}
if (valueStr1.length() > pos + normalStr.length()) {
final char c = valueStr1.charAt(pos + normalStr.length());
- switch (c) {
- case ' ':
- case '.':
- case ',':
- case '/':
- case '$':
- case '+':
- case '-':
- case '_':
- case '#':
- case '=':
- // These are all acceptable.
- break;
-
- default:
- // Anything else is not.
+ if (!isAcceptable(c)) {
return ConditionResult.FALSE;
}
}
@@ -118,6 +88,25 @@
// If we've gotten here, then we can assume it is a match.
return ConditionResult.TRUE;
}
+
+ private boolean isAcceptable(final char c) {
+ switch (c) {
+ case ' ':
+ case '.':
+ case ',':
+ case '/':
+ case '$':
+ case '+':
+ case '-':
+ case '_':
+ case '#':
+ case '=':
+ return true;
+
+ default:
+ return false;
+ }
+ }
};
}
@@ -129,26 +118,18 @@
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, CASE_FOLD);
- final int bufferLength = buffer.length();
- if (bufferLength == 0) {
+ if (buffer.length() == 0) {
if (value.length() > 0) {
// This should only happen if the value is composed entirely of
// spaces. In that case, the normalized value is a single space.
- return " ".intern();
+ return " ";
} else {
// The value is empty, so it is already normalized.
- return "".intern();
+ return "";
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return buffer.toString();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
index 923ab0b..42f828d 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
@@ -47,23 +47,23 @@
* @return A comparator that can be used to compare the attribute values
* normalized by this matching rule.
*/
- public Comparator<ByteSequence> comparator(Schema schema);
+ Comparator<ByteSequence> comparator(Schema schema);
/**
* Retrieves the normalized form of the provided assertion value, which is
* best suited for efficiently performing matching operations on that value.
- * The assertion value is guarenteed to be valid against this matching
+ * The assertion value is guaranteed to be valid against this matching
* rule's assertion syntax.
*
* @param schema
* The schema in which this matching rule is defined.
- * @param value
+ * @param assertionValue
* The syntax checked assertion value to be normalized.
* @return The normalized version of the provided assertion value.
* @throws DecodeException
- * if an syntax error occured while parsing the value.
+ * if an syntax error occurred while parsing the value.
*/
- public Assertion getAssertion(Schema schema, ByteSequence value) throws DecodeException;
+ Assertion getAssertion(Schema schema, ByteSequence assertionValue) throws DecodeException;
/**
* Retrieves the normalized form of the provided assertion substring values,
@@ -83,16 +83,16 @@
* the end of the target value.
* @return The normalized version of the provided assertion value.
* @throws DecodeException
- * if an syntax error occured while parsing the value.
+ * if an syntax error occurred while parsing the value.
*/
- public Assertion getSubstringAssertion(Schema schema, ByteSequence subInitial,
+ Assertion getSubstringAssertion(Schema schema, ByteSequence subInitial,
List<? extends ByteSequence> subAnyElements, ByteSequence subFinal)
throws DecodeException;
/**
* Retrieves the normalized form of the provided assertion value, which is
* best suited for efficiently performing greater than or equal matching
- * operations on that value. The assertion value is guarenteed to be valid
+ * operations on that value. The assertion value is guaranteed to be valid
* against this matching rule's assertion syntax.
*
* @param schema
@@ -101,15 +101,15 @@
* The syntax checked assertion value to be normalized.
* @return The normalized version of the provided assertion value.
* @throws DecodeException
- * if an syntax error occured while parsing the value.
+ * if an syntax error occurred while parsing the value.
*/
- public Assertion getGreaterOrEqualAssertion(Schema schema, ByteSequence value)
+ Assertion getGreaterOrEqualAssertion(Schema schema, ByteSequence value)
throws DecodeException;
/**
* Retrieves the normalized form of the provided assertion value, which is
* best suited for efficiently performing greater than or equal matching
- * operations on that value. The assertion value is guarenteed to be valid
+ * operations on that value. The assertion value is guaranteed to be valid
* against this matching rule's assertion syntax.
*
* @param schema
@@ -118,9 +118,9 @@
* The syntax checked assertion value to be normalized.
* @return The normalized version of the provided assertion value.
* @throws DecodeException
- * if an syntax error occured while parsing the value.
+ * if an syntax error occurred while parsing the value.
*/
- public Assertion getLessOrEqualAssertion(Schema schema, ByteSequence value)
+ Assertion getLessOrEqualAssertion(Schema schema, ByteSequence value)
throws DecodeException;
/**
@@ -133,8 +133,9 @@
* The attribute value to be normalized.
* @return The normalized version of the provided attribute value.
* @throws DecodeException
- * if an syntax error occured while parsing the value.
+ * if an syntax error occurred while parsing the value.
*/
- public ByteString normalizeAttributeValue(Schema schema, ByteSequence value)
+ ByteString normalizeAttributeValue(Schema schema, ByteSequence value)
throws DecodeException;
+
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java
index db006d9..4756b15 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java
@@ -37,7 +37,7 @@
* and referenced in RFC 2252. It allows for values with numeric digits and
* spaces, but ignores spaces when performing matching.
*/
-final class NumericStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class NumericStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD);
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java
index 6435293..a29458f 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java
@@ -40,7 +40,7 @@
* either an attribute/objectclass name or a numeric OID. NOTE: This matching
* rule requires a schema to lookup object identifiers in the descriptor form.
*/
-final class ObjectIdentifierEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class ObjectIdentifierEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
static String resolveNames(final Schema schema, final String oid) {
if (!StaticUtils.isDigit(oid.charAt(0))) {
// Do an best effort attempt to normalize names to OIDs.
@@ -97,9 +97,9 @@
}
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
- final String definition = value.toString();
+ final String definition = assertionValue.toString();
final SubstringReader reader = new SubstringReader(definition);
final String normalized =
resolveNames(schema, SchemaUtils.readOID(reader, schema
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java
index 065880c..047c96b 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java
@@ -45,11 +45,11 @@
* objectclass descriptions) in which the "first component" is the first item
* after the opening parenthesis.
*/
-final class ObjectIdentifierFirstComponentEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class ObjectIdentifierFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
@Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
+ public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
throws DecodeException {
- final String definition = value.toString();
+ final String definition = assertionValue.toString();
final SubstringReader reader = new SubstringReader(definition);
final String normalized =
ObjectIdentifierEqualityMatchingRuleImpl.resolveNames(schema, SchemaUtils.readOID(
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringEqualityMatchingRuleImpl.java
index e76e5cb..945e0d8 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringEqualityMatchingRuleImpl.java
@@ -33,7 +33,7 @@
* will be used as the default equality matching rule for the binary and octet
* string syntaxes.
*/
-final class OctetStringEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class OctetStringEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
return value.toByteString();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/PresentationAddressEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/PresentationAddressEqualityMatchingRuleImpl.java
index a8a9793..6bf3a91 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/PresentationAddressEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/PresentationAddressEqualityMatchingRuleImpl.java
@@ -38,7 +38,7 @@
* associated syntax have been deprecated, this matching rule behaves exactly
* like the caseIgnoreMatch rule.
*/
-final class PresentationAddressEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class PresentationAddressEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, CASE_FOLD);
@@ -55,14 +55,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ProtocolInformationEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ProtocolInformationEqualityMatchingRuleImpl.java
index aa9cd7a..ec91b09 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ProtocolInformationEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ProtocolInformationEqualityMatchingRuleImpl.java
@@ -38,7 +38,7 @@
* associated syntax have been deprecated, this matching rule behaves exactly
* like the caseIgnoreMatch rule.
*/
-final class ProtocolInformationEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class ProtocolInformationEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final StringBuilder buffer = new StringBuilder();
prepareUnicode(buffer, value, TRIM, CASE_FOLD);
@@ -55,14 +55,7 @@
}
}
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
+ trimConsecutiveSpaces(buffer);
return ByteString.valueOf(buffer.toString());
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java
index 06dbe03..a98a5ed 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* very rigorous format, this is widely ignored so this matching will compare
* only numeric digits and strip out everything else.
*/
-final class TelephoneNumberEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class TelephoneNumberEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
final String valueString = value.toString();
final int valueLength = valueString.length();
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
index 8f15ea6..f2755a5 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
@@ -38,7 +38,7 @@
* This class defines the uuidMatch matching rule defined in RFC 4530. It will
* be used as the default equality matching rule for the UUID syntax.
*/
-final class UUIDEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class UUIDEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
if (value.length() != 36) {
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java
index 85a255a..73ad708 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java
@@ -34,7 +34,7 @@
* and will compare values with a distinguished name and optional bit string
* suffix.
*/
-final class UniqueMemberEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class UniqueMemberEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
return value.toByteString();
}
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java
index c41dea3..ad9f872 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java
@@ -36,7 +36,7 @@
* simply compare encoded hashed password values to see if they are exactly
* equal to each other.
*/
-final class UserPasswordExactEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
+final class UserPasswordExactEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
throws DecodeException {
// The normalized form of this matching rule is exactly equal to the
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/WordEqualityMatchingRuleImpl.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/WordEqualityMatchingRuleImpl.java
deleted file mode 100644
index 99144ae..0000000
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/WordEqualityMatchingRuleImpl.java
+++ /dev/null
@@ -1,155 +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.
- */
-package org.forgerock.opendj.ldap.schema;
-
-import static com.forgerock.opendj.util.StringPrepProfile.CASE_FOLD;
-import static com.forgerock.opendj.util.StringPrepProfile.TRIM;
-import static com.forgerock.opendj.util.StringPrepProfile.prepareUnicode;
-
-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;
-
-/**
- * This class implements the wordMatch matching rule defined in X.520. That
- * document defines "word" as implementation-specific, but in this case we will
- * consider it a match if the assertion value is contained within the attribute
- * value and is bounded by the edge of the value or any of the following
- * characters: <BR>
- * <UL>
- * <LI>A space</LI>
- * <LI>A period</LI>
- * <LI>A comma</LI>
- * <LI>A slash</LI>
- * <LI>A dollar sign</LI>
- * <LI>A plus sign</LI>
- * <LI>A dash</LI>
- * <LI>An underscore</LI>
- * <LI>An octothorpe</LI>
- * <LI>An equal sign</LI>
- * </UL>
- */
-final class WordEqualityMatchingRuleImpl extends AbstractMatchingRuleImpl {
- @Override
- public Assertion getAssertion(final Schema schema, final ByteSequence value)
- throws DecodeException {
- final String normalStr = normalize(value);
-
- return new Assertion() {
- public ConditionResult matches(final ByteSequence attributeValue) {
- // See if the assertion value is contained in the attribute
- // value. If not, then it isn't a match.
- final String valueStr1 = attributeValue.toString();
-
- final int pos = valueStr1.indexOf(normalStr);
- if (pos < 0) {
- return ConditionResult.FALSE;
- }
-
- if (pos > 0) {
- final char c = valueStr1.charAt(pos - 1);
- switch (c) {
- case ' ':
- case '.':
- case ',':
- case '/':
- case '$':
- case '+':
- case '-':
- case '_':
- case '#':
- case '=':
- // These are all acceptable.
- break;
-
- default:
- // Anything else is not.
- return ConditionResult.FALSE;
- }
- }
-
- if (valueStr1.length() > pos + normalStr.length()) {
- final char c = valueStr1.charAt(pos + normalStr.length());
- switch (c) {
- case ' ':
- case '.':
- case ',':
- case '/':
- case '$':
- case '+':
- case '-':
- case '_':
- case '#':
- case '=':
- // These are all acceptable.
- break;
-
- default:
- // Anything else is not.
- return ConditionResult.FALSE;
- }
- }
-
- // If we've gotten here, then we can assume it is a match.
- return ConditionResult.TRUE;
- }
- };
- }
-
- public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
- return ByteString.valueOf(normalize(value));
- }
-
- private String normalize(final ByteSequence value) {
- final StringBuilder buffer = new StringBuilder();
- prepareUnicode(buffer, value, TRIM, CASE_FOLD);
-
- final int bufferLength = buffer.length();
- if (bufferLength == 0) {
- if (value.length() > 0) {
- // This should only happen if the value is composed entirely of
- // spaces. In that case, the normalized value is a single space.
- return " ".intern();
- } else {
- // The value is empty, so it is already normalized.
- return "".intern();
- }
- }
-
- // Replace any consecutive spaces with a single space.
- for (int pos = bufferLength - 1; pos > 0; pos--) {
- if (buffer.charAt(pos) == ' ') {
- if (buffer.charAt(pos - 1) == ' ') {
- buffer.delete(pos, pos + 1);
- }
- }
- }
-
- return buffer.toString();
- }
-}
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EnumSyntaxTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EnumSyntaxTestCase.java
index f10fbf2..552e637 100644
--- a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EnumSyntaxTestCase.java
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EnumSyntaxTestCase.java
@@ -26,15 +26,15 @@
*/
package org.forgerock.opendj.ldap.schema;
-import static org.forgerock.opendj.ldap.schema.SchemaConstants.OMR_OID_GENERIC_ENUM;
-
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.opendj.ldap.DecodeException;
-import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import static org.forgerock.opendj.ldap.ConditionResult.*;
+import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
+import static org.testng.Assert.*;
+
/**
* Enum syntax tests.
*/
@@ -58,27 +58,21 @@
final Schema schema = builder.toSchema();
final Syntax syntax = schema.getSyntax("3.3.3");
final MatchingRule rule = syntax.getOrderingMatchingRule();
- Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("monday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("thursday"))), ConditionResult.TRUE);
- Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("monday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("thursday"))),
- ConditionResult.FALSE);
- Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.FALSE);
- Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.TRUE);
- Assert.assertEquals(rule.getGreaterOrEqualAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.TRUE);
- Assert.assertEquals(rule.getLessOrEqualAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.TRUE);
- Assert.assertEquals(rule.getAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("monday"))), ConditionResult.TRUE);
- Assert.assertEquals(rule.getAssertion(ByteString.valueOf("monday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("thursday"))),
- ConditionResult.FALSE);
- Assert.assertEquals(rule.getAssertion(ByteString.valueOf("tuesday")).matches(
- rule.normalizeAttributeValue(ByteString.valueOf("tuesday"))), ConditionResult.FALSE);
- Assert.assertNotNull(schema.getMatchingRule(OMR_OID_GENERIC_ENUM + ".3.3.3"));
+ final ByteString monday = ByteString.valueOf("monday");
+ final ByteString normMonday = rule.normalizeAttributeValue(monday);
+ final ByteString tuesday = ByteString.valueOf("tuesday");
+ final ByteString normTuesday = rule.normalizeAttributeValue(tuesday);
+ final ByteString normThursday = rule.normalizeAttributeValue(ByteString.valueOf("thursday"));
+ assertEquals(rule.getGreaterOrEqualAssertion(monday).matches(normThursday), TRUE);
+ assertEquals(rule.getLessOrEqualAssertion(monday).matches(normThursday), FALSE);
+ assertEquals(rule.getGreaterOrEqualAssertion(tuesday).matches(normMonday), FALSE);
+ assertEquals(rule.getLessOrEqualAssertion(tuesday).matches(normMonday), TRUE);
+ assertEquals(rule.getGreaterOrEqualAssertion(tuesday).matches(normTuesday), TRUE);
+ assertEquals(rule.getLessOrEqualAssertion(tuesday).matches(normTuesday), TRUE);
+ assertEquals(rule.getAssertion(tuesday).matches(normMonday), TRUE);
+ assertEquals(rule.getAssertion(monday).matches(normThursday), FALSE);
+ assertEquals(rule.getAssertion(tuesday).matches(normTuesday), FALSE);
+ assertNotNull(schema.getMatchingRule(OMR_OID_GENERIC_ENUM + ".3.3.3"));
}
@Test
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
index d8fe607..7caa25c 100644
--- a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
@@ -79,16 +79,13 @@
}
Assertion a = ruleInstance.getGreaterOrEqualAssertion(ByteString.valueOf(value2));
- Assert.assertEquals(a.matches(normalizedValue1), result >= 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE);
+ Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result >= 0));
a = ruleInstance.getLessOrEqualAssertion(ByteString.valueOf(value2));
- Assert.assertEquals(a.matches(normalizedValue1), result <= 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE);
+ Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result <= 0));
a = ruleInstance.getAssertion(ByteString.valueOf(value2));
- Assert.assertEquals(a.matches(normalizedValue1), result < 0 ? ConditionResult.TRUE
- : ConditionResult.FALSE);
+ Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result < 0));
}
/**
--
Gitblit v1.10.0