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

Jean-Noel Rouvignac
18.28.2015 4f3f49d8c31f9c5bcc46b7902a160e733c274573
ObjectIdentifier*EqualityMatchingRuleImpl.java:
Removed duplicated code


ObjectIdentifierEqualityMatchingRuleImpl.java:
Removed getAssertion() and now use AbstractEqualityMatchingRuleImpl.getAssertion() implementation.
In normalizeAttributeValue(), extracted static method normalizeAttributeValuePrivate() for code reuse.

ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java:
Used ObjectIdentifierEqualityMatchingRuleImpl.normalizeAttributeValuePrivate().
Used static imports.
2 files modified
55 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java 23 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java 32 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java
@@ -22,11 +22,13 @@
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions copyright 2011-2014 ForgeRock AS
 *      Portions copyright 2011-2015 ForgeRock AS
 */
package org.forgerock.opendj.ldap.schema;
import org.forgerock.opendj.ldap.Assertion;
import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
@@ -34,9 +36,6 @@
import com.forgerock.opendj.util.StaticUtils;
import com.forgerock.opendj.util.SubstringReader;
import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
/**
 * This class defines the objectIdentifierMatch matching rule defined in X.520
 * and referenced in RFC 2252. This expects to work on OIDs and will match
@@ -80,21 +79,15 @@
    }
    @Override
    public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
            throws DecodeException {
        final String definition = assertionValue.toString();
        final SubstringReader reader = new SubstringReader(definition);
        final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS));
        final String normalized = resolveNames(schema, oid);
        return DefaultAssertion.equality(ByteString.valueOf(normalized));
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) throws DecodeException {
        return normalizeAttributeValuePrivate(schema, value);
    }
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
    static ByteString normalizeAttributeValuePrivate(final Schema schema, final ByteSequence value)
            throws DecodeException {
        final String definition = value.toString();
        final SubstringReader reader = new SubstringReader(definition);
        final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS));
        final String normalized = resolveNames(schema, oid);
        return ByteString.valueOf(normalized);
        return ByteString.valueOf(resolveNames(schema, oid));
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierFirstComponentEqualityMatchingRuleImpl.java
@@ -22,12 +22,15 @@
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions copyright 2011-2014 ForgeRock AS
 *      Portions copyright 2011-2015 ForgeRock AS
 */
package org.forgerock.opendj.ldap.schema;
import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_EMPTY_VALUE;
import static com.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_EXPECTED_OPEN_PARENTHESIS;
import static com.forgerock.opendj.ldap.CoreMessages.*;
import static org.forgerock.opendj.ldap.schema.ObjectIdentifierEqualityMatchingRuleImpl.*;
import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Assertion;
@@ -37,9 +40,6 @@
import com.forgerock.opendj.util.SubstringReader;
import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
/**
 * This class implements the objectIdentifierFirstComponentMatch matching rule
 * defined in X.520 and referenced in RFC 2252. This rule is intended for use
@@ -51,23 +51,16 @@
final class ObjectIdentifierFirstComponentEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
    @Override
    public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
            throws DecodeException {
        final String definition = assertionValue.toString();
        final SubstringReader reader = new SubstringReader(definition);
        final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS));
        final String normalized = ObjectIdentifierEqualityMatchingRuleImpl.resolveNames(schema, oid);
        return DefaultAssertion.equality(ByteString.valueOf(normalized));
    public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) throws DecodeException {
        return DefaultAssertion.equality(normalizeAttributeValuePrivate(schema, assertionValue));
    }
    @Override
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value)
            throws DecodeException {
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) throws DecodeException {
        final String definition = value.toString();
        final SubstringReader reader = new SubstringReader(definition);
        // We'll do this a character at a time. First, skip over any leading
        // whitespace.
        // We'll do this a character at a time. First, skip over any leading whitespace.
        reader.skipWhitespaces();
        if (reader.remaining() <= 0) {
@@ -88,8 +81,7 @@
        reader.skipWhitespaces();
        // The next set of characters must be the OID.
        final String normalized = ObjectIdentifierEqualityMatchingRuleImpl.resolveNames(schema,
            readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS)));
        return ByteString.valueOf(normalized);
        final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS));
        return ByteString.valueOf(resolveNames(schema, oid));
    }
}