From 08aed6ad0915199523910454dc3c5d3685277baf Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 17 Feb 2014 14:02:11 +0000
Subject: [PATCH] ModificationType.java, ResultCode.java, SearchScope.java: Added asEnum() + added an actual inner enum called Enum to match all the cases. In valueOf(int), fixed a bug for ResultCode + implemented it the same as ResultCode for the other classes.
---
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ResultCodeTestCase.java | 71 +++++
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DataProviderIterator.java | 76 ++++++
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/SearchScopeTestCase.java | 44 +++
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultCode.java | 328 ++++++++++++++++++++-------
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ModificationType.java | 60 ++++
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/SearchScope.java | 59 ++++
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ModificationTypeTestCase.java | 55 ++++
7 files changed, 583 insertions(+), 110 deletions(-)
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ModificationType.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ModificationType.java
index f921607..331e05c 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ModificationType.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ModificationType.java
@@ -23,7 +23,6 @@
*
* Copyright 2009 Sun Microsystems, Inc.
*/
-
package org.forgerock.opendj.ldap;
import java.util.Arrays;
@@ -40,6 +39,26 @@
* Directory Access Protocol (LDAP) Modify-Increment Extension </a>
*/
public final class ModificationType {
+
+ /**
+ * Contains equivalent values for the ModificationType values.
+ * This allows easily using ModificationType values with switch statements.
+ */
+ public static enum Enum {
+ //@Checkstyle:off
+ /** @see ModificationType#ADD */
+ ADD,
+ /** @see ModificationType#DELETE */
+ DELETE,
+ /** @see ModificationType#REPLACE */
+ REPLACE,
+ /** @see ModificationType#INCREMENT */
+ INCREMENT,
+ /** Used for unknown modification types. */
+ UNKNOWN;
+ //@Checkstyle:on
+ }
+
private static final ModificationType[] ELEMENTS = new ModificationType[4];
private static final List<ModificationType> IMMUTABLE_ELEMENTS = Collections
@@ -49,14 +68,14 @@
* Add the values listed in the modification to the attribute, creating the
* attribute if necessary.
*/
- public static final ModificationType ADD = register(0, "add");
+ public static final ModificationType ADD = register(0, "add", Enum.ADD);
/**
* Delete the values listed in the modification from the attribute. If no
* values are listed, or if all current values of the attribute are listed,
* the entire attribute is removed.
*/
- public static final ModificationType DELETE = register(1, "delete");
+ public static final ModificationType DELETE = register(1, "delete", Enum.DELETE);
/**
* Replace all existing values of the attribute with the new values listed
@@ -64,13 +83,13 @@
* A replace with no listed values will delete the entire attribute if it
* exists, and it is ignored if the attribute does not exist.
*/
- public static final ModificationType REPLACE = register(2, "replace");
+ public static final ModificationType REPLACE = register(2, "replace", Enum.REPLACE);
/**
* Increment all existing values of the attribute by the amount specified in
* the modification value.
*/
- public static final ModificationType INCREMENT = register(3, "increment");
+ public static final ModificationType INCREMENT = register(3, "increment", Enum.INCREMENT);
/**
* Returns the modification change type having the specified integer value
@@ -82,10 +101,14 @@
* modification change type associated with {@code intValue}.
*/
public static ModificationType valueOf(final int intValue) {
- if (intValue < 0 || intValue >= ELEMENTS.length) {
- return null;
+ ModificationType result = null;
+ if (0 <= intValue && intValue < ELEMENTS.length) {
+ result = ELEMENTS[intValue];
}
- return ELEMENTS[intValue];
+ if (result == null) {
+ result = new ModificationType(intValue, "unknown(" + intValue + ")", Enum.UNKNOWN);
+ }
+ return result;
}
/**
@@ -109,10 +132,12 @@
* in RFC 4511 section 4.6.
* @param name
* The name of the modification change type.
+ * @param modificationTypeEnum
+ * The enum equivalent for this modification type
* @return The new modification change type.
*/
- private static ModificationType register(final int intValue, final String name) {
- final ModificationType t = new ModificationType(intValue, name);
+ private static ModificationType register(final int intValue, final String name, final Enum modificationTypeEnum) {
+ final ModificationType t = new ModificationType(intValue, name, modificationTypeEnum);
ELEMENTS[intValue] = t;
return t;
}
@@ -121,10 +146,13 @@
private final String name;
+ private final Enum modificationTypeEnum;
+
// Prevent direct instantiation.
- private ModificationType(final int intValue, final String name) {
+ private ModificationType(final int intValue, final String name, final Enum modificationTypeEnum) {
this.intValue = intValue;
this.name = name;
+ this.modificationTypeEnum = modificationTypeEnum;
}
/**
@@ -160,6 +188,16 @@
}
/**
+ * Returns the enum equivalent for this modification type.
+ *
+ * @return The enum equivalent for this modification type when a known mapping exists,
+ * or {@link Enum#UNKNOWN} if this is an unknown modification type.
+ */
+ public Enum asEnum() {
+ return this.modificationTypeEnum;
+ }
+
+ /**
* Returns the string representation of this modification change type.
*
* @return The string representation of this modification change type.
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultCode.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultCode.java
index 4e48e38..4f499cd 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultCode.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ResultCode.java
@@ -27,14 +27,14 @@
package org.forgerock.opendj.ldap;
-import static com.forgerock.opendj.ldap.CoreMessages.*;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
+import static com.forgerock.opendj.ldap.CoreMessages.*;
+
/**
* An operation result code as defined in RFC 4511 section 4.1.9 is used to
* indicate the final status of an operation. If a server detects multiple
@@ -47,6 +47,150 @@
* Lightweight Directory Access Protocol (LDAP): The Protocol </a>
*/
public final class ResultCode {
+
+ /**
+ * Contains equivalent values for the ResultCode values.
+ * This allows easily using ResultCode values with switch statements.
+ */
+ public static enum Enum {
+ //@Checkstyle:off
+ /** @see ResultCode#SUCCESS */
+ SUCCESS,
+ /** @see ResultCode#OPERATIONS_ERROR */
+ OPERATIONS_ERROR,
+ /** @see ResultCode#PROTOCOL_ERROR */
+ PROTOCOL_ERROR,
+ /** @see ResultCode#TIME_LIMIT_EXCEEDED */
+ TIME_LIMIT_EXCEEDED,
+ /** @see ResultCode#SIZE_LIMIT_EXCEEDED */
+ SIZE_LIMIT_EXCEEDED,
+ /** @see ResultCode#COMPARE_FALSE */
+ COMPARE_FALSE,
+ /** @see ResultCode#COMPARE_TRUE */
+ COMPARE_TRUE,
+ /** @see ResultCode#AUTH_METHOD_NOT_SUPPORTED */
+ AUTH_METHOD_NOT_SUPPORTED,
+ /** @see ResultCode#STRONG_AUTH_REQUIRED */
+ STRONG_AUTH_REQUIRED,
+ /** @see ResultCode#REFERRAL */
+ REFERRAL,
+ /** @see ResultCode#ADMIN_LIMIT_EXCEEDED */
+ ADMIN_LIMIT_EXCEEDED,
+ /** @see ResultCode#UNAVAILABLE_CRITICAL_EXTENSION */
+ UNAVAILABLE_CRITICAL_EXTENSION,
+ /** @see ResultCode#CONFIDENTIALITY_REQUIRED */
+ CONFIDENTIALITY_REQUIRED,
+ /** @see ResultCode#SASL_BIND_IN_PROGRESS */
+ SASL_BIND_IN_PROGRESS,
+ /** @see ResultCode#NO_SUCH_ATTRIBUTE */
+ NO_SUCH_ATTRIBUTE,
+ /** @see ResultCode#UNDEFINED_ATTRIBUTE_TYPE */
+ UNDEFINED_ATTRIBUTE_TYPE,
+ /** @see ResultCode#INAPPROPRIATE_MATCHING */
+ INAPPROPRIATE_MATCHING,
+ /** @see ResultCode#CONSTRAINT_VIOLATION */
+ CONSTRAINT_VIOLATION,
+ /** @see ResultCode#ATTRIBUTE_OR_VALUE_EXISTS */
+ ATTRIBUTE_OR_VALUE_EXISTS,
+ /** @see ResultCode#INVALID_ATTRIBUTE_SYNTAX */
+ INVALID_ATTRIBUTE_SYNTAX,
+ /** @see ResultCode#NO_SUCH_OBJECT */
+ NO_SUCH_OBJECT,
+ /** @see ResultCode#ALIAS_PROBLEM */
+ ALIAS_PROBLEM,
+ /** @see ResultCode#INVALID_DN_SYNTAX */
+ INVALID_DN_SYNTAX,
+ /** @see ResultCode#ALIAS_DEREFERENCING_PROBLEM */
+ ALIAS_DEREFERENCING_PROBLEM,
+ /** @see ResultCode#INAPPROPRIATE_AUTHENTICATION */
+ INAPPROPRIATE_AUTHENTICATION,
+ /** @see ResultCode#INVALID_CREDENTIALS */
+ INVALID_CREDENTIALS,
+ /** @see ResultCode#INSUFFICIENT_ACCESS_RIGHTS */
+ INSUFFICIENT_ACCESS_RIGHTS,
+ /** @see ResultCode#BUSY */
+ BUSY,
+ /** @see ResultCode#UNAVAILABLE */
+ UNAVAILABLE,
+ /** @see ResultCode#UNWILLING_TO_PERFORM */
+ UNWILLING_TO_PERFORM,
+ /** @see ResultCode#LOOP_DETECT */
+ LOOP_DETECT,
+ /** @see ResultCode#SORT_CONTROL_MISSING */
+ SORT_CONTROL_MISSING,
+ /** @see ResultCode#OFFSET_RANGE_ERROR */
+ OFFSET_RANGE_ERROR,
+ /** @see ResultCode#NAMING_VIOLATION */
+ NAMING_VIOLATION,
+ /** @see ResultCode#OBJECTCLASS_VIOLATION */
+ OBJECTCLASS_VIOLATION,
+ /** @see ResultCode#NOT_ALLOWED_ON_NONLEAF */
+ NOT_ALLOWED_ON_NONLEAF,
+ /** @see ResultCode#NOT_ALLOWED_ON_RDN */
+ NOT_ALLOWED_ON_RDN,
+ /** @see ResultCode#ENTRY_ALREADY_EXISTS */
+ ENTRY_ALREADY_EXISTS,
+ /** @see ResultCode#OBJECTCLASS_MODS_PROHIBITED */
+ OBJECTCLASS_MODS_PROHIBITED,
+ /** @see ResultCode#AFFECTS_MULTIPLE_DSAS */
+ AFFECTS_MULTIPLE_DSAS,
+ /** @see ResultCode#VIRTUAL_LIST_VIEW_ERROR */
+ VIRTUAL_LIST_VIEW_ERROR,
+ /** @see ResultCode#OTHER */
+ OTHER,
+ /** @see ResultCode#CLIENT_SIDE_SERVER_DOWN */
+ CLIENT_SIDE_SERVER_DOWN,
+ /** @see ResultCode#CLIENT_SIDE_LOCAL_ERROR */
+ CLIENT_SIDE_LOCAL_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_ENCODING_ERROR */
+ CLIENT_SIDE_ENCODING_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_DECODING_ERROR */
+ CLIENT_SIDE_DECODING_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_TIMEOUT */
+ CLIENT_SIDE_TIMEOUT,
+ /** @see ResultCode#CLIENT_SIDE_AUTH_UNKNOWN */
+ CLIENT_SIDE_AUTH_UNKNOWN,
+ /** @see ResultCode#CLIENT_SIDE_FILTER_ERROR */
+ CLIENT_SIDE_FILTER_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_USER_CANCELLED */
+ CLIENT_SIDE_USER_CANCELLED,
+ /** @see ResultCode#CLIENT_SIDE_PARAM_ERROR */
+ CLIENT_SIDE_PARAM_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_NO_MEMORY */
+ CLIENT_SIDE_NO_MEMORY,
+ /** @see ResultCode#CLIENT_SIDE_CONNECT_ERROR */
+ CLIENT_SIDE_CONNECT_ERROR,
+ /** @see ResultCode#CLIENT_SIDE_NOT_SUPPORTED */
+ CLIENT_SIDE_NOT_SUPPORTED,
+ /** @see ResultCode#CLIENT_SIDE_CONTROL_NOT_FOUND */
+ CLIENT_SIDE_CONTROL_NOT_FOUND,
+ /** @see ResultCode#CLIENT_SIDE_NO_RESULTS_RETURNED */
+ CLIENT_SIDE_NO_RESULTS_RETURNED,
+ /** @see ResultCode#CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED */
+ CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED,
+ /** @see ResultCode#CLIENT_SIDE_CLIENT_LOOP */
+ CLIENT_SIDE_CLIENT_LOOP,
+ /** @see ResultCode#CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED */
+ CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED,
+ /** @see ResultCode#CANCELLED */
+ CANCELLED,
+ /** @see ResultCode#NO_SUCH_OPERATION */
+ NO_SUCH_OPERATION,
+ /** @see ResultCode#TOO_LATE */
+ TOO_LATE,
+ /** @see ResultCode#CANNOT_CANCEL */
+ CANNOT_CANCEL,
+ /** @see ResultCode#ASSERTION_FAILED */
+ ASSERTION_FAILED,
+ /** @see ResultCode#AUTHORIZATION_DENIED */
+ AUTHORIZATION_DENIED,
+ /** @see ResultCode#NO_OPERATION */
+ NO_OPERATION,
+ /** Used for unknown search scopes. */
+ UNKNOWN;
+ //@Checkstyle:on
+ }
+
private static final ResultCode[] ELEMENTS = new ResultCode[16655];
private static final List<ResultCode> IMMUTABLE_ELEMENTS = Collections.unmodifiableList(Arrays
@@ -58,7 +202,7 @@
* This result code corresponds to the LDAP result code value of {@code 0}.
*/
public static final ResultCode SUCCESS =
- registerSuccessResultCode(0, INFO_RESULT_SUCCESS.get());
+ registerSuccessResultCode(0, INFO_RESULT_SUCCESS.get(), Enum.SUCCESS);
/**
* The result code that indicates that an internal error prevented the
@@ -67,7 +211,7 @@
* This result code corresponds to the LDAP result code value of {@code 1}.
*/
public static final ResultCode OPERATIONS_ERROR = registerErrorResultCode(1,
- INFO_RESULT_OPERATIONS_ERROR.get());
+ INFO_RESULT_OPERATIONS_ERROR.get(), Enum.OPERATIONS_ERROR);
/**
* The result code that indicates that the client sent a malformed or
@@ -76,7 +220,7 @@
* This result code corresponds to the LDAP result code value of {@code 2}.
*/
public static final ResultCode PROTOCOL_ERROR = registerErrorResultCode(2,
- INFO_RESULT_PROTOCOL_ERROR.get());
+ INFO_RESULT_PROTOCOL_ERROR.get(), Enum.PROTOCOL_ERROR);
/**
* The result code that indicates that a time limit was exceeded while
@@ -85,7 +229,7 @@
* This result code corresponds to the LDAP result code value of {@code 3}.
*/
public static final ResultCode TIME_LIMIT_EXCEEDED = registerErrorResultCode(3,
- INFO_RESULT_TIME_LIMIT_EXCEEDED.get());
+ INFO_RESULT_TIME_LIMIT_EXCEEDED.get(), Enum.TIME_LIMIT_EXCEEDED);
/**
* The result code that indicates that a size limit was exceeded while
@@ -94,7 +238,7 @@
* This result code corresponds to the LDAP result code value of {@code 4}.
*/
public static final ResultCode SIZE_LIMIT_EXCEEDED = registerErrorResultCode(4,
- INFO_RESULT_SIZE_LIMIT_EXCEEDED.get());
+ INFO_RESULT_SIZE_LIMIT_EXCEEDED.get(), Enum.SIZE_LIMIT_EXCEEDED);
/**
* The result code that indicates that the attribute value assertion
@@ -103,7 +247,7 @@
* This result code corresponds to the LDAP result code value of {@code 5}.
*/
public static final ResultCode COMPARE_FALSE = registerSuccessResultCode(5,
- INFO_RESULT_COMPARE_FALSE.get());
+ INFO_RESULT_COMPARE_FALSE.get(), Enum.COMPARE_FALSE);
/**
* The result code that indicates that the attribute value assertion
@@ -112,7 +256,7 @@
* This result code corresponds to the LDAP result code value of {@code 6}.
*/
public static final ResultCode COMPARE_TRUE = registerSuccessResultCode(6,
- INFO_RESULT_COMPARE_TRUE.get());
+ INFO_RESULT_COMPARE_TRUE.get(), Enum.COMPARE_TRUE);
/**
* The result code that indicates that the requested authentication attempt
@@ -121,7 +265,7 @@
* This result code corresponds to the LDAP result code value of {@code 7}.
*/
public static final ResultCode AUTH_METHOD_NOT_SUPPORTED = registerErrorResultCode(7,
- INFO_RESULT_AUTH_METHOD_NOT_SUPPORTED.get());
+ INFO_RESULT_AUTH_METHOD_NOT_SUPPORTED.get(), Enum.AUTH_METHOD_NOT_SUPPORTED);
/**
* The result code that indicates that the requested operation could not be
@@ -131,7 +275,7 @@
* This result code corresponds to the LDAP result code value of {@code 8}.
*/
public static final ResultCode STRONG_AUTH_REQUIRED = registerErrorResultCode(8,
- INFO_RESULT_STRONG_AUTH_REQUIRED.get());
+ INFO_RESULT_STRONG_AUTH_REQUIRED.get(), Enum.STRONG_AUTH_REQUIRED);
/**
* The result code that indicates that a referral was encountered.
@@ -145,7 +289,7 @@
* This result code corresponds to the LDAP result code value of {@code 10}.
*/
public static final ResultCode REFERRAL = registerErrorResultCode(10, INFO_RESULT_REFERRAL
- .get());
+ .get(), Enum.REFERRAL);
/**
* The result code that indicates that processing on the requested operation
@@ -154,7 +298,7 @@
* This result code corresponds to the LDAP result code value of {@code 11}.
*/
public static final ResultCode ADMIN_LIMIT_EXCEEDED = registerErrorResultCode(11,
- INFO_RESULT_ADMIN_LIMIT_EXCEEDED.get());
+ INFO_RESULT_ADMIN_LIMIT_EXCEEDED.get(), Enum.ADMIN_LIMIT_EXCEEDED);
/**
* The result code that indicates that the requested operation failed
@@ -164,7 +308,7 @@
* This result code corresponds to the LDAP result code value of {@code 12}.
*/
public static final ResultCode UNAVAILABLE_CRITICAL_EXTENSION = registerErrorResultCode(12,
- INFO_RESULT_UNAVAILABLE_CRITICAL_EXTENSION.get());
+ INFO_RESULT_UNAVAILABLE_CRITICAL_EXTENSION.get(), Enum.UNAVAILABLE_CRITICAL_EXTENSION);
/**
* The result code that indicates that the requested operation could not be
@@ -174,7 +318,7 @@
* This result code corresponds to the LDAP result code value of {@code 13}.
*/
public static final ResultCode CONFIDENTIALITY_REQUIRED = registerErrorResultCode(13,
- INFO_RESULT_CONFIDENTIALITY_REQUIRED.get());
+ INFO_RESULT_CONFIDENTIALITY_REQUIRED.get(), Enum.CONFIDENTIALITY_REQUIRED);
/**
* The result code that should be used for intermediate responses in
@@ -183,7 +327,7 @@
* This result code corresponds to the LDAP result code value of {@code 14}.
*/
public static final ResultCode SASL_BIND_IN_PROGRESS = registerSuccessResultCode(14,
- INFO_RESULT_SASL_BIND_IN_PROGRESS.get());
+ INFO_RESULT_SASL_BIND_IN_PROGRESS.get(), Enum.SASL_BIND_IN_PROGRESS);
/**
* The result code that indicates that the requested operation failed
@@ -193,7 +337,7 @@
* This result code corresponds to the LDAP result code value of {@code 16}.
*/
public static final ResultCode NO_SUCH_ATTRIBUTE = registerErrorResultCode(16,
- INFO_RESULT_NO_SUCH_ATTRIBUTE.get());
+ INFO_RESULT_NO_SUCH_ATTRIBUTE.get(), Enum.NO_SUCH_ATTRIBUTE);
/**
* The result code that indicates that the requested operation failed
@@ -203,7 +347,7 @@
* This result code corresponds to the LDAP result code value of {@code 17}.
*/
public static final ResultCode UNDEFINED_ATTRIBUTE_TYPE = registerErrorResultCode(17,
- INFO_RESULT_UNDEFINED_ATTRIBUTE_TYPE.get());
+ INFO_RESULT_UNDEFINED_ATTRIBUTE_TYPE.get(), Enum.UNDEFINED_ATTRIBUTE_TYPE);
/**
* The result code that indicates that the requested operation failed
@@ -213,7 +357,7 @@
* This result code corresponds to the LDAP result code value of {@code 18}.
*/
public static final ResultCode INAPPROPRIATE_MATCHING = registerErrorResultCode(18,
- INFO_RESULT_INAPPROPRIATE_MATCHING.get());
+ INFO_RESULT_INAPPROPRIATE_MATCHING.get(), Enum.INAPPROPRIATE_MATCHING);
/**
* The result code that indicates that the requested operation failed
@@ -222,7 +366,7 @@
* This result code corresponds to the LDAP result code value of {@code 19}.
*/
public static final ResultCode CONSTRAINT_VIOLATION = registerErrorResultCode(19,
- INFO_RESULT_CONSTRAINT_VIOLATION.get());
+ INFO_RESULT_CONSTRAINT_VIOLATION.get(), Enum.CONSTRAINT_VIOLATION);
/**
* The result code that indicates that the requested operation failed
@@ -232,7 +376,7 @@
* This result code corresponds to the LDAP result code value of {@code 20}.
*/
public static final ResultCode ATTRIBUTE_OR_VALUE_EXISTS = registerErrorResultCode(20,
- INFO_RESULT_ATTRIBUTE_OR_VALUE_EXISTS.get());
+ INFO_RESULT_ATTRIBUTE_OR_VALUE_EXISTS.get(), Enum.ATTRIBUTE_OR_VALUE_EXISTS);
/**
* The result code that indicates that the requested operation failed
@@ -241,7 +385,7 @@
* This result code corresponds to the LDAP result code value of {@code 21}.
*/
public static final ResultCode INVALID_ATTRIBUTE_SYNTAX = registerErrorResultCode(21,
- INFO_RESULT_INVALID_ATTRIBUTE_SYNTAX.get());
+ INFO_RESULT_INVALID_ATTRIBUTE_SYNTAX.get(), Enum.INVALID_ATTRIBUTE_SYNTAX);
/**
* The result code that indicates that the requested operation failed
@@ -250,7 +394,7 @@
* This result code corresponds to the LDAP result code value of {@code 32}.
*/
public static final ResultCode NO_SUCH_OBJECT = registerErrorResultCode(32,
- INFO_RESULT_NO_SUCH_OBJECT.get());
+ INFO_RESULT_NO_SUCH_OBJECT.get(), Enum.NO_SUCH_OBJECT);
/**
* The result code that indicates that the requested operation failed
@@ -259,7 +403,7 @@
* This result code corresponds to the LDAP result code value of {@code 33}.
*/
public static final ResultCode ALIAS_PROBLEM = registerErrorResultCode(33,
- INFO_RESULT_ALIAS_PROBLEM.get());
+ INFO_RESULT_ALIAS_PROBLEM.get(), Enum.ALIAS_PROBLEM);
/**
* The result code that indicates that the requested operation failed
@@ -269,7 +413,7 @@
* This result code corresponds to the LDAP result code value of {@code 34}.
*/
public static final ResultCode INVALID_DN_SYNTAX = registerErrorResultCode(34,
- INFO_RESULT_INVALID_DN_SYNTAX.get());
+ INFO_RESULT_INVALID_DN_SYNTAX.get(), Enum.INVALID_DN_SYNTAX);
/**
* The result code that indicates that a problem was encountered while
@@ -278,7 +422,7 @@
* This result code corresponds to the LDAP result code value of {@code 36}.
*/
public static final ResultCode ALIAS_DEREFERENCING_PROBLEM = registerErrorResultCode(36,
- INFO_RESULT_ALIAS_DEREFERENCING_PROBLEM.get());
+ INFO_RESULT_ALIAS_DEREFERENCING_PROBLEM.get(), Enum.ALIAS_DEREFERENCING_PROBLEM);
/**
* The result code that indicates that an authentication attempt failed
@@ -288,7 +432,7 @@
* This result code corresponds to the LDAP result code value of {@code 48}.
*/
public static final ResultCode INAPPROPRIATE_AUTHENTICATION = registerErrorResultCode(48,
- INFO_RESULT_INAPPROPRIATE_AUTHENTICATION.get());
+ INFO_RESULT_INAPPROPRIATE_AUTHENTICATION.get(), Enum.INAPPROPRIATE_AUTHENTICATION);
/**
* The result code that indicates that an authentication attempt failed
@@ -297,7 +441,7 @@
* This result code corresponds to the LDAP result code value of {@code 49}.
*/
public static final ResultCode INVALID_CREDENTIALS = registerErrorResultCode(49,
- INFO_RESULT_INVALID_CREDENTIALS.get());
+ INFO_RESULT_INVALID_CREDENTIALS.get(), Enum.INVALID_CREDENTIALS);
/**
* The result code that indicates that the client does not have sufficient
@@ -306,7 +450,7 @@
* This result code corresponds to the LDAP result code value of {@code 50}.
*/
public static final ResultCode INSUFFICIENT_ACCESS_RIGHTS = registerErrorResultCode(50,
- INFO_RESULT_INSUFFICIENT_ACCESS_RIGHTS.get());
+ INFO_RESULT_INSUFFICIENT_ACCESS_RIGHTS.get(), Enum.INSUFFICIENT_ACCESS_RIGHTS);
/**
* The result code that indicates that the server is too busy to process the
@@ -314,7 +458,7 @@
* <p>
* This result code corresponds to the LDAP result code value of {@code 51}.
*/
- public static final ResultCode BUSY = registerErrorResultCode(51, INFO_RESULT_BUSY.get());
+ public static final ResultCode BUSY = registerErrorResultCode(51, INFO_RESULT_BUSY.get(), Enum.BUSY);
/**
* The result code that indicates that either the entire server or one or
@@ -324,7 +468,7 @@
* This result code corresponds to the LDAP result code value of {@code 52}.
*/
public static final ResultCode UNAVAILABLE = registerErrorResultCode(52,
- INFO_RESULT_UNAVAILABLE.get());
+ INFO_RESULT_UNAVAILABLE.get(), Enum.UNAVAILABLE);
/**
* The result code that indicates that the server is unwilling to perform
@@ -333,7 +477,7 @@
* This result code corresponds to the LDAP result code value of {@code 53}.
*/
public static final ResultCode UNWILLING_TO_PERFORM = registerErrorResultCode(53,
- INFO_RESULT_UNWILLING_TO_PERFORM.get());
+ INFO_RESULT_UNWILLING_TO_PERFORM.get(), Enum.UNWILLING_TO_PERFORM);
/**
* The result code that indicates that a referral or chaining loop was
@@ -342,7 +486,7 @@
* This result code corresponds to the LDAP result code value of {@code 54}.
*/
public static final ResultCode LOOP_DETECT = registerErrorResultCode(54,
- INFO_RESULT_LOOP_DETECT.get());
+ INFO_RESULT_LOOP_DETECT.get(), Enum.LOOP_DETECT);
/**
* The result code that indicates that a search request included a VLV
@@ -351,7 +495,7 @@
* This result code corresponds to the LDAP result code value of {@code 60}.
*/
public static final ResultCode SORT_CONTROL_MISSING = registerErrorResultCode(60,
- INFO_RESULT_SORT_CONTROL_MISSING.get());
+ INFO_RESULT_SORT_CONTROL_MISSING.get(), Enum.SORT_CONTROL_MISSING);
/**
* The result code that indicates that a search request included a VLV
@@ -360,7 +504,7 @@
* This result code corresponds to the LDAP result code value of {@code 61}.
*/
public static final ResultCode OFFSET_RANGE_ERROR = registerErrorResultCode(61,
- INFO_RESULT_OFFSET_RANGE_ERROR.get());
+ INFO_RESULT_OFFSET_RANGE_ERROR.get(), Enum.OFFSET_RANGE_ERROR);
/**
* The result code that indicates that the requested operation failed
@@ -369,7 +513,7 @@
* This result code corresponds to the LDAP result code value of {@code 64}.
*/
public static final ResultCode NAMING_VIOLATION = registerErrorResultCode(64,
- INFO_RESULT_NAMING_VIOLATION.get());
+ INFO_RESULT_NAMING_VIOLATION.get(), Enum.NAMING_VIOLATION);
/**
* The result code that indicates that the requested operation failed
@@ -379,7 +523,7 @@
* This result code corresponds to the LDAP result code value of {@code 65}.
*/
public static final ResultCode OBJECTCLASS_VIOLATION = registerErrorResultCode(65,
- INFO_RESULT_OBJECTCLASS_VIOLATION.get());
+ INFO_RESULT_OBJECTCLASS_VIOLATION.get(), Enum.OBJECTCLASS_VIOLATION);
/**
* The result code that indicates that the requested operation is not
@@ -388,7 +532,7 @@
* This result code corresponds to the LDAP result code value of {@code 66}.
*/
public static final ResultCode NOT_ALLOWED_ON_NONLEAF = registerErrorResultCode(66,
- INFO_RESULT_NOT_ALLOWED_ON_NONLEAF.get());
+ INFO_RESULT_NOT_ALLOWED_ON_NONLEAF.get(), Enum.NOT_ALLOWED_ON_NONLEAF);
/**
* The result code that indicates that the requested operation is not
@@ -397,7 +541,7 @@
* This result code corresponds to the LDAP result code value of {@code 67}.
*/
public static final ResultCode NOT_ALLOWED_ON_RDN = registerErrorResultCode(67,
- INFO_RESULT_NOT_ALLOWED_ON_RDN.get());
+ INFO_RESULT_NOT_ALLOWED_ON_RDN.get(), Enum.NOT_ALLOWED_ON_RDN);
/**
* The result code that indicates that the requested operation failed
@@ -407,7 +551,7 @@
* This result code corresponds to the LDAP result code value of {@code 68}.
*/
public static final ResultCode ENTRY_ALREADY_EXISTS = registerErrorResultCode(68,
- INFO_RESULT_ENTRY_ALREADY_EXISTS.get());
+ INFO_RESULT_ENTRY_ALREADY_EXISTS.get(), Enum.ENTRY_ALREADY_EXISTS);
/**
* The result code that indicates that the operation could not be processed
@@ -417,7 +561,7 @@
* This result code corresponds to the LDAP result code value of {@code 69}.
*/
public static final ResultCode OBJECTCLASS_MODS_PROHIBITED = registerErrorResultCode(69,
- INFO_RESULT_OBJECTCLASS_MODS_PROHIBITED.get());
+ INFO_RESULT_OBJECTCLASS_MODS_PROHIBITED.get(), Enum.OBJECTCLASS_MODS_PROHIBITED);
/**
* The result code that indicates that the operation could not be processed
@@ -426,7 +570,7 @@
* This result code corresponds to the LDAP result code value of {@code 71}.
*/
public static final ResultCode AFFECTS_MULTIPLE_DSAS = registerErrorResultCode(71,
- INFO_RESULT_AFFECTS_MULTIPLE_DSAS.get());
+ INFO_RESULT_AFFECTS_MULTIPLE_DSAS.get(), Enum.AFFECTS_MULTIPLE_DSAS);
/**
* The result code that indicates that the operation could not be processed
@@ -436,7 +580,7 @@
* This result code corresponds to the LDAP result code value of {@code 76}.
*/
public static final ResultCode VIRTUAL_LIST_VIEW_ERROR = registerErrorResultCode(76,
- INFO_RESULT_VIRTUAL_LIST_VIEW_ERROR.get());
+ INFO_RESULT_VIRTUAL_LIST_VIEW_ERROR.get(), Enum.VIRTUAL_LIST_VIEW_ERROR);
/**
* The result code that should be used if no other result code is
@@ -444,7 +588,7 @@
* <p>
* This result code corresponds to the LDAP result code value of {@code 80}.
*/
- public static final ResultCode OTHER = registerErrorResultCode(80, INFO_RESULT_OTHER.get());
+ public static final ResultCode OTHER = registerErrorResultCode(80, INFO_RESULT_OTHER.get(), Enum.OTHER);
/**
* The client-side result code that indicates that a previously-established
@@ -454,7 +598,7 @@
* This result code corresponds to the LDAP result code value of {@code 81}.
*/
public static final ResultCode CLIENT_SIDE_SERVER_DOWN = registerErrorResultCode(81,
- INFO_RESULT_CLIENT_SIDE_SERVER_DOWN.get());
+ INFO_RESULT_CLIENT_SIDE_SERVER_DOWN.get(), Enum.CLIENT_SIDE_SERVER_DOWN);
/**
* The client-side result code that indicates that a local error occurred
@@ -464,7 +608,7 @@
* This result code corresponds to the LDAP result code value of {@code 82}.
*/
public static final ResultCode CLIENT_SIDE_LOCAL_ERROR = registerErrorResultCode(82,
- INFO_RESULT_CLIENT_SIDE_LOCAL_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_LOCAL_ERROR.get(), Enum.CLIENT_SIDE_LOCAL_ERROR);
/**
* The client-side result code that indicates that an error occurred while
@@ -474,7 +618,7 @@
* This result code corresponds to the LDAP result code value of {@code 83}.
*/
public static final ResultCode CLIENT_SIDE_ENCODING_ERROR = registerErrorResultCode(83,
- INFO_RESULT_CLIENT_SIDE_ENCODING_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_ENCODING_ERROR.get(), Enum.CLIENT_SIDE_ENCODING_ERROR);
/**
* The client-side result code that indicates that an error occurred while
@@ -484,7 +628,7 @@
* This result code corresponds to the LDAP result code value of {@code 84}.
*/
public static final ResultCode CLIENT_SIDE_DECODING_ERROR = registerErrorResultCode(84,
- INFO_RESULT_CLIENT_SIDE_DECODING_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_DECODING_ERROR.get(), Enum.CLIENT_SIDE_DECODING_ERROR);
/**
* The client-side result code that indicates that the client did not
@@ -494,7 +638,7 @@
* This result code corresponds to the LDAP result code value of {@code 85}.
*/
public static final ResultCode CLIENT_SIDE_TIMEOUT = registerErrorResultCode(85,
- INFO_RESULT_CLIENT_SIDE_TIMEOUT.get());
+ INFO_RESULT_CLIENT_SIDE_TIMEOUT.get(), Enum.CLIENT_SIDE_TIMEOUT);
/**
* The client-side result code that indicates that the user requested an
@@ -504,7 +648,7 @@
* This result code corresponds to the LDAP result code value of {@code 86}.
*/
public static final ResultCode CLIENT_SIDE_AUTH_UNKNOWN = registerErrorResultCode(86,
- INFO_RESULT_CLIENT_SIDE_AUTH_UNKNOWN.get());
+ INFO_RESULT_CLIENT_SIDE_AUTH_UNKNOWN.get(), Enum.CLIENT_SIDE_AUTH_UNKNOWN);
/**
* The client-side result code that indicates that the filter provided by
@@ -514,7 +658,7 @@
* This result code corresponds to the LDAP result code value of {@code 87}.
*/
public static final ResultCode CLIENT_SIDE_FILTER_ERROR = registerErrorResultCode(87,
- INFO_RESULT_CLIENT_SIDE_FILTER_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_FILTER_ERROR.get(), Enum.CLIENT_SIDE_FILTER_ERROR);
/**
* The client-side result code that indicates that the user cancelled an
@@ -524,7 +668,7 @@
* This result code corresponds to the LDAP result code value of {@code 88}.
*/
public static final ResultCode CLIENT_SIDE_USER_CANCELLED = registerErrorResultCode(88,
- INFO_RESULT_CLIENT_SIDE_USER_CANCELLED.get());
+ INFO_RESULT_CLIENT_SIDE_USER_CANCELLED.get(), Enum.CLIENT_SIDE_USER_CANCELLED);
/**
* The client-side result code that indicates that there was a problem with
@@ -534,7 +678,7 @@
* This result code corresponds to the LDAP result code value of {@code 89}.
*/
public static final ResultCode CLIENT_SIDE_PARAM_ERROR = registerErrorResultCode(89,
- INFO_RESULT_CLIENT_SIDE_PARAM_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_PARAM_ERROR.get(), Enum.CLIENT_SIDE_PARAM_ERROR);
/**
* The client-side result code that indicates that the client application
@@ -545,7 +689,7 @@
* This result code corresponds to the LDAP result code value of {@code 90}.
*/
public static final ResultCode CLIENT_SIDE_NO_MEMORY = registerErrorResultCode(90,
- INFO_RESULT_CLIENT_SIDE_NO_MEMORY.get());
+ INFO_RESULT_CLIENT_SIDE_NO_MEMORY.get(), Enum.CLIENT_SIDE_NO_MEMORY);
/**
* The client-side result code that indicates that the client was not able
@@ -555,7 +699,7 @@
* This result code corresponds to the LDAP result code value of {@code 91}.
*/
public static final ResultCode CLIENT_SIDE_CONNECT_ERROR = registerErrorResultCode(91,
- INFO_RESULT_CLIENT_SIDE_CONNECT_ERROR.get());
+ INFO_RESULT_CLIENT_SIDE_CONNECT_ERROR.get(), Enum.CLIENT_SIDE_CONNECT_ERROR);
/**
* The client-side result code that indicates that the user requested an
@@ -565,7 +709,7 @@
* This result code corresponds to the LDAP result code value of {@code 92}.
*/
public static final ResultCode CLIENT_SIDE_NOT_SUPPORTED = registerErrorResultCode(92,
- INFO_RESULT_CLIENT_SIDE_NOT_SUPPORTED.get());
+ INFO_RESULT_CLIENT_SIDE_NOT_SUPPORTED.get(), Enum.CLIENT_SIDE_NOT_SUPPORTED);
/**
* The client-side result code that indicates that the client expected a
@@ -576,7 +720,7 @@
* This result code corresponds to the LDAP result code value of {@code 93}.
*/
public static final ResultCode CLIENT_SIDE_CONTROL_NOT_FOUND = registerErrorResultCode(93,
- INFO_RESULT_CLIENT_SIDE_CONTROL_NOT_FOUND.get());
+ INFO_RESULT_CLIENT_SIDE_CONTROL_NOT_FOUND.get(), Enum.CLIENT_SIDE_CONTROL_NOT_FOUND);
/**
* The client-side result code that indicates that the requested single
@@ -587,7 +731,7 @@
* This result code corresponds to the LDAP result code value of {@code 94}.
*/
public static final ResultCode CLIENT_SIDE_NO_RESULTS_RETURNED = registerErrorResultCode(94,
- INFO_RESULT_CLIENT_SIDE_NO_RESULTS_RETURNED.get());
+ INFO_RESULT_CLIENT_SIDE_NO_RESULTS_RETURNED.get(), Enum.CLIENT_SIDE_NO_RESULTS_RETURNED);
/**
* The client-side result code that the requested single entry search
@@ -598,8 +742,8 @@
* <p>
* This result code corresponds to the LDAP result code value of {@code 95}.
*/
- public static final ResultCode CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED =
- registerErrorResultCode(95, INFO_RESULT_CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED.get());
+ public static final ResultCode CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED = registerErrorResultCode(95,
+ INFO_RESULT_CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED.get(), Enum.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED);
/**
* The client-side result code that indicates that the client detected a
@@ -610,7 +754,7 @@
* This result code corresponds to the LDAP result code value of {@code 96}.
*/
public static final ResultCode CLIENT_SIDE_CLIENT_LOOP = registerErrorResultCode(96,
- INFO_RESULT_CLIENT_SIDE_CLIENT_LOOP.get());
+ INFO_RESULT_CLIENT_SIDE_CLIENT_LOOP.get(), Enum.CLIENT_SIDE_CLIENT_LOOP);
/**
* The client-side result code that indicates that the client reached the
@@ -622,7 +766,7 @@
* This result code corresponds to the LDAP result code value of {@code 97}.
*/
public static final ResultCode CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED = registerErrorResultCode(
- 97, INFO_RESULT_CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED.get());
+ 97, INFO_RESULT_CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED.get(), Enum.CLIENT_SIDE_REFERRAL_LIMIT_EXCEEDED);
/**
* The result code that indicates that a cancel request was successful, or
@@ -631,7 +775,7 @@
* This result code corresponds to the LDAP result code value of {@code 118}.
*/
public static final ResultCode CANCELLED = registerErrorResultCode(118, INFO_RESULT_CANCELED
- .get());
+ .get(), Enum.CANCELLED);
/**
* The result code that indicates that a cancel request was unsuccessful
@@ -640,7 +784,7 @@
* This result code corresponds to the LDAP result code value of {@code 119}.
*/
public static final ResultCode NO_SUCH_OPERATION = registerErrorResultCode(119,
- INFO_RESULT_NO_SUCH_OPERATION.get());
+ INFO_RESULT_NO_SUCH_OPERATION.get(), Enum.NO_SUCH_OPERATION);
/**
* The result code that indicates that a cancel request was unsuccessful
@@ -650,7 +794,7 @@
* This result code corresponds to the LDAP result code value of {@code 120}.
*/
public static final ResultCode TOO_LATE = registerErrorResultCode(120, INFO_RESULT_TOO_LATE
- .get());
+ .get(), Enum.TOO_LATE);
/**
* The result code that indicates that a cancel request was unsuccessful
@@ -659,7 +803,7 @@
* This result code corresponds to the LDAP result code value of {@code 121}.
*/
public static final ResultCode CANNOT_CANCEL = registerErrorResultCode(121,
- INFO_RESULT_CANNOT_CANCEL.get());
+ INFO_RESULT_CANNOT_CANCEL.get(), Enum.CANNOT_CANCEL);
/**
* The result code that indicates that the filter contained in an assertion
@@ -668,7 +812,7 @@
* This result code corresponds to the LDAP result code value of {@code 122}.
*/
public static final ResultCode ASSERTION_FAILED = registerErrorResultCode(122,
- INFO_RESULT_ASSERTION_FAILED.get());
+ INFO_RESULT_ASSERTION_FAILED.get(), Enum.ASSERTION_FAILED);
/**
* The result code that should be used if the server will not allow the
@@ -677,7 +821,7 @@
* This result code corresponds to the LDAP result code value of {@code 123}.
*/
public static final ResultCode AUTHORIZATION_DENIED = registerErrorResultCode(123,
- INFO_RESULT_AUTHORIZATION_DENIED.get());
+ INFO_RESULT_AUTHORIZATION_DENIED.get(), Enum.AUTHORIZATION_DENIED);
/**
* The result code that should be used if the server did not actually
@@ -688,7 +832,7 @@
* {@code 16654}.
*/
public static final ResultCode NO_OPERATION = registerSuccessResultCode(16654,
- INFO_RESULT_NO_OPERATION.get());
+ INFO_RESULT_NO_OPERATION.get(), Enum.NO_OPERATION);
/**
* Returns the result code having the specified integer value as defined in
@@ -702,19 +846,15 @@
* @return The result code.
*/
public static ResultCode valueOf(final int intValue) {
- ResultCode resultCode = null;
-
- if (intValue >= 0 || intValue < ELEMENTS.length) {
- resultCode = ELEMENTS[intValue];
+ ResultCode result = null;
+ if (0 <= intValue && intValue < ELEMENTS.length) {
+ result = ELEMENTS[intValue];
}
-
- if (resultCode == null) {
- resultCode =
- new ResultCode(intValue, LocalizableMessage.raw("undefined(" + intValue + ")"),
- true);
+ if (result == null) {
+ result = new ResultCode(
+ intValue, LocalizableMessage.raw("unknown(" + intValue + ")"), true, Enum.UNKNOWN);
}
-
- return resultCode;
+ return result;
}
/**
@@ -736,11 +876,13 @@
* 4511 section 4.1.9.
* @param name
* The name of the error result code.
+ * @param resultCodeEnum
+ * The enum equivalent for this result code
* @return The new error result code.
*/
private static ResultCode registerErrorResultCode(final int intValue,
- final LocalizableMessage name) {
- final ResultCode t = new ResultCode(intValue, name, true);
+ final LocalizableMessage name, final Enum resultCodeEnum) {
+ final ResultCode t = new ResultCode(intValue, name, true, resultCodeEnum);
ELEMENTS[intValue] = t;
return t;
}
@@ -753,11 +895,13 @@
* 4511 section 4.1.9.
* @param name
* The name of the success result code.
+ * @param resultCodeEnum
+ * The enum equivalent for this result code
* @return The new success result code.
*/
private static ResultCode registerSuccessResultCode(final int intValue,
- final LocalizableMessage name) {
- final ResultCode t = new ResultCode(intValue, name, false);
+ final LocalizableMessage name, final Enum resultCodeEnum) {
+ final ResultCode t = new ResultCode(intValue, name, false, resultCodeEnum);
ELEMENTS[intValue] = t;
return t;
}
@@ -768,11 +912,15 @@
private final boolean exceptional;
+ private final Enum resultCodeEnum;
+
// Prevent direct instantiation.
- private ResultCode(final int intValue, final LocalizableMessage name, final boolean exceptional) {
+ private ResultCode(final int intValue, final LocalizableMessage name, final boolean exceptional,
+ final Enum resultCodeEnum) {
this.intValue = intValue;
this.name = name;
this.exceptional = exceptional;
+ this.resultCodeEnum = resultCodeEnum;
}
/**
@@ -816,6 +964,16 @@
}
/**
+ * Returns the enum equivalent for this result code.
+ *
+ * @return The enum equivalent for this result code when a known mapping exists,
+ * or {@link Enum#UNKNOWN} if this is an unknown result code.
+ */
+ public Enum asEnum() {
+ return this.resultCodeEnum;
+ }
+
+ /**
* Indicates whether or not this result code represents an error result.
* <p>
* The following result codes are NOT interpreted as error results:
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/SearchScope.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/SearchScope.java
index 60b89bf..94fc522 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/SearchScope.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/SearchScope.java
@@ -42,6 +42,26 @@
* Scope for LDAP </a>
*/
public final class SearchScope {
+
+ /**
+ * Contains equivalent values for the SearchScope values.
+ * This allows easily using SearchScope values with switch statements.
+ */
+ public static enum Enum {
+ //@Checkstyle:off
+ /** @see SearchScope#BASE_OBJECT */
+ BASE_OBJECT,
+ /** @see SearchScope#SINGLE_LEVEL */
+ SINGLE_LEVEL,
+ /** @see SearchScope#WHOLE_SUBTREE */
+ WHOLE_SUBTREE,
+ /** @see SearchScope#SUBORDINATES */
+ SUBORDINATES,
+ /** Used for unknown search scopes. */
+ UNKNOWN;
+ //@Checkstyle:on
+ }
+
private static final SearchScope[] ELEMENTS = new SearchScope[4];
private static final List<SearchScope> IMMUTABLE_ELEMENTS = Collections.unmodifiableList(Arrays
@@ -50,26 +70,26 @@
/**
* The scope is constrained to the search base entry.
*/
- public static final SearchScope BASE_OBJECT = register(0, "base");
+ public static final SearchScope BASE_OBJECT = register(0, "base", Enum.BASE_OBJECT);
/**
* The scope is constrained to the immediate subordinates of the search base
* entry.
*/
- public static final SearchScope SINGLE_LEVEL = register(1, "one");
+ public static final SearchScope SINGLE_LEVEL = register(1, "one", Enum.SINGLE_LEVEL);
/**
* The scope is constrained to the search base entry and to all its
* subordinates.
*/
- public static final SearchScope WHOLE_SUBTREE = register(2, "sub");
+ public static final SearchScope WHOLE_SUBTREE = register(2, "sub", Enum.WHOLE_SUBTREE);
/**
* The scope is constrained to all the subordinates of the search base
* entry, but does not include the search base entry itself (as wholeSubtree
* does).
*/
- public static final SearchScope SUBORDINATES = register(3, "subordinates");
+ public static final SearchScope SUBORDINATES = register(3, "subordinates", Enum.SUBORDINATES);
/**
* Returns the search scope having the specified integer value as defined in
@@ -81,10 +101,14 @@
* associated with {@code intValue}.
*/
public static SearchScope valueOf(final int intValue) {
- if (intValue < 0 || intValue >= ELEMENTS.length) {
- return null;
+ SearchScope result = null;
+ if (0 <= intValue && intValue < ELEMENTS.length) {
+ result = ELEMENTS[intValue];
}
- return ELEMENTS[intValue];
+ if (result == null) {
+ result = new SearchScope(intValue, "unknown(" + intValue + ")", Enum.UNKNOWN);
+ }
+ return result;
}
/**
@@ -127,10 +151,12 @@
* section 4.5.1.2.
* @param name
* The name of the search scope as defined in RFC 4516.
+ * @param searchScopeEnum
+ * The enum equivalent for this search scope
* @return The new search scope.
*/
- private static SearchScope register(final int intValue, final String name) {
- final SearchScope t = new SearchScope(intValue, name);
+ private static SearchScope register(final int intValue, final String name, Enum searchScopeEnum) {
+ final SearchScope t = new SearchScope(intValue, name, searchScopeEnum);
ELEMENTS[intValue] = t;
return t;
}
@@ -139,10 +165,13 @@
private final String name;
+ private final Enum searchScopeEnum;
+
// Prevent direct instantiation.
- private SearchScope(final int intValue, final String name) {
+ private SearchScope(final int intValue, final String name, Enum searchScopeEnum) {
this.intValue = intValue;
this.name = name;
+ this.searchScopeEnum = searchScopeEnum;
}
/**
@@ -178,6 +207,16 @@
}
/**
+ * Returns the enum equivalent for this search scope.
+ *
+ * @return The enum equivalent for this search scope when a known mapping exists,
+ * or {@link Enum#UNKNOWN} if this is an unknown search scope.
+ */
+ public Enum asEnum() {
+ return this.searchScopeEnum;
+ }
+
+ /**
* Returns the string representation of this search scope as defined in RFC
* 4516.
*
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DataProviderIterator.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DataProviderIterator.java
new file mode 100644
index 0000000..2f175fc
--- /dev/null
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DataProviderIterator.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.testng.annotations.DataProvider;
+
+/**
+ * An iterator implementation that converts an Iterator/Iterable/array to an
+ * Iterator suitable to return from a {@link DataProvider} methods.
+ */
+@SuppressWarnings("javadoc")
+public class DataProviderIterator implements Iterator<Object[]> {
+
+ private final Iterator<?> iter;
+
+ public DataProviderIterator(Iterator<?> iter) {
+ this.iter = iter;
+ }
+
+ public DataProviderIterator(Iterable<?> iterable) {
+ this.iter = iterable != null
+ ? iterable.iterator()
+ : Collections.emptySet().iterator();
+ }
+
+ public <T> DataProviderIterator(T... objs) {
+ this.iter = objs != null
+ ? Arrays.asList(objs).iterator()
+ : Collections.emptySet().iterator();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Object[] next() {
+ return new Object[] { iter.next() };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void remove() {
+ iter.remove();
+ }
+
+}
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ModificationTypeTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ModificationTypeTestCase.java
new file mode 100644
index 0000000..c95834e
--- /dev/null
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ModificationTypeTestCase.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+@SuppressWarnings("javadoc")
+public class ModificationTypeTestCase extends SdkTestCase {
+
+ @DataProvider
+ public Iterator<Object[]> valuesDataProvider() {
+ return new DataProviderIterator(ModificationType.values());
+ }
+
+ @Test(dataProvider = "valuesDataProvider")
+ public void valueOfInt(ModificationType val) throws Exception {
+ assertSame(ModificationType.valueOf(val.intValue()), val);
+ }
+
+ @Test
+ public void valueOfIntUnknown() throws Exception {
+ int intValue = -1;
+ ModificationType unknown = ModificationType.valueOf(intValue);
+ assertSame(unknown.intValue(), intValue);
+ assertSame(unknown.asEnum(), ModificationType.Enum.UNKNOWN);
+ }
+
+}
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ResultCodeTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ResultCodeTestCase.java
new file mode 100644
index 0000000..743cb1c
--- /dev/null
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ResultCodeTestCase.java
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.forgerock.opendj.ldap.ResultCode.Enum.*;
+import static org.testng.Assert.*;
+
+@SuppressWarnings("javadoc")
+public class ResultCodeTestCase extends SdkTestCase {
+
+ @DataProvider
+ public Iterator<Object[]> valuesDataProvider() {
+ final LinkedList<ResultCode> values = new LinkedList<ResultCode>(ResultCode.values());
+ for (Iterator<ResultCode> iter = values.iterator(); iter.hasNext();) {
+ if (iter.next() == null) {
+ iter.remove();
+ }
+ }
+ return new DataProviderIterator(values);
+ }
+
+ @Test(dataProvider = "valuesDataProvider")
+ public void valueOfInt(ResultCode val) throws Exception {
+ assertSame(ResultCode.valueOf(val.intValue()), val);
+ }
+
+ @Test
+ public void valueOfIntUnknown() throws Exception {
+ int intValue = -1;
+ ResultCode unknown = ResultCode.valueOf(intValue);
+ assertSame(unknown.intValue(), intValue);
+ assertSame(unknown.asEnum(), ResultCode.Enum.UNKNOWN);
+ }
+
+ @Test(dataProvider = "valuesDataProvider")
+ public void isExceptional(ResultCode val) {
+ EnumSet<ResultCode.Enum> exceptional = EnumSet.complementOf(EnumSet.of(
+ SUCCESS, COMPARE_FALSE, COMPARE_TRUE, SASL_BIND_IN_PROGRESS, NO_OPERATION));
+ assertEquals(val.isExceptional(), exceptional.contains(val.asEnum()));
+ }
+
+}
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/SearchScopeTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/SearchScopeTestCase.java
index dbb7a6a..fac4d9f 100644
--- a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/SearchScopeTestCase.java
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/SearchScopeTestCase.java
@@ -25,18 +25,26 @@
*/
package org.forgerock.opendj.ldap;
+import java.util.Iterator;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
import static org.fest.assertions.Assertions.*;
import static org.testng.Assert.*;
-import org.testng.annotations.Test;
-
@SuppressWarnings("javadoc")
public class SearchScopeTestCase extends SdkTestCase {
@Test
public void valueOfInt() {
- assertNull(SearchScope.valueOf(-1));
- assertNull(SearchScope.valueOf(Integer.MAX_VALUE));
+ final SearchScope unkown1 = SearchScope.valueOf(-1);
+ assertEquals(unkown1.intValue(), -1);
+ assertEquals(unkown1.asEnum(), SearchScope.Enum.UNKNOWN);
+ final SearchScope unknownMax = SearchScope.valueOf(Integer.MAX_VALUE);
+ assertEquals(unknownMax.intValue(), Integer.MAX_VALUE);
+ assertEquals(unknownMax.asEnum(), SearchScope.Enum.UNKNOWN);
+
assertEquals(SearchScope.valueOf(0), SearchScope.BASE_OBJECT);
assertEquals(SearchScope.valueOf(1), SearchScope.SINGLE_LEVEL);
assertEquals(SearchScope.valueOf(2), SearchScope.WHOLE_SUBTREE);
@@ -58,4 +66,32 @@
SearchScope.SINGLE_LEVEL, SearchScope.WHOLE_SUBTREE,
SearchScope.SUBORDINATES);
}
+
+ @DataProvider
+ public Iterator<Object[]> valuesDataProvider() {
+ return new DataProviderIterator(SearchScope.values());
+ }
+
+ @Test(dataProvider = "valuesDataProvider")
+ public void valueOfInt(SearchScope val) throws Exception {
+ assertSame(SearchScope.valueOf(val.intValue()), val, val.toString());
+ }
+
+ @Test
+ public void valueOfIntUnknown() throws Exception {
+ int intValue = -1;
+ SearchScope unknown = SearchScope.valueOf(intValue);
+ assertSame(unknown.intValue(), intValue);
+ assertSame(unknown.asEnum(), SearchScope.Enum.UNKNOWN);
+ }
+
+ @Test(dataProvider = "valuesDataProvider")
+ public void valueOfString(SearchScope val) throws Exception {
+ assertSame(SearchScope.valueOf(val.toString()), val);
+ }
+
+ @Test
+ public void valueOfStringUnknown() throws Exception {
+ assertNull(SearchScope.valueOf("unknown"));
+ }
}
--
Gitblit v1.10.0