From 9ad92942049990e1e291603fdb674ed82872043b Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 25 Sep 2006 09:27:48 +0000
Subject: [PATCH] Refactoring: simplify the AttributeType.isOperational() method, by providing an "isOperational" getter in the AttributeUsage enumeration.

---
 opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java  |   18 +-----------------
 opendj-sdk/opends/src/server/org/opends/server/types/AttributeUsage.java |   39 +++++++++++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
index 2e1e145..73854f6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
@@ -43,7 +43,6 @@
 import org.opends.server.core.DirectoryServer;
 
 import static org.opends.server.loggers.Debug.*;
-import static org.opends.server.loggers.Error.*;
 import static org.opends.server.messages.CoreMessages.*;
 import static org.opends.server.messages.MessageHandler.*;
 import static org.opends.server.util.ServerConstants.*;
@@ -723,22 +722,7 @@
   {
     assert debugEnter(CLASS_NAME, "isOperational");
 
-    switch (attributeUsage)
-    {
-      case USER_APPLICATIONS:
-        return false;
-      case DIRECTORY_OPERATION:
-      case DISTRIBUTED_OPERATION:
-      case DSA_OPERATION:
-        return true;
-    }
-
-    // We should never get here.  If we do, assume it's a user-defined
-    // attribute.
-    logError(ErrorLogCategory.CORE_SERVER,
-             ErrorLogSeverity.SEVERE_WARNING,
-             MSGID_UNKNOWN_ATTRIBUTE_USAGE, getNameOrOID());
-    return false;
+    return attributeUsage.isOperational();
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeUsage.java b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeUsage.java
index 7b8334a..7535cec 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeUsage.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeUsage.java
@@ -37,14 +37,14 @@
   /**
    * The attribute usage intended for user-defined attribute types.
    */
-  USER_APPLICATIONS("userApplications"),
+  USER_APPLICATIONS("userApplications", false),
 
 
 
   /**
    * The attribute usage intended for standard operational attributes.
    */
-  DIRECTORY_OPERATION("directoryOperation"),
+  DIRECTORY_OPERATION("directoryOperation", true),
 
 
 
@@ -52,7 +52,7 @@
    * The attribute usage intended for non-standard operational
    * attributes shared among multiple DSAs.
    */
-  DISTRIBUTED_OPERATION("distributedOperation"),
+  DISTRIBUTED_OPERATION("distributedOperation", true),
 
 
 
@@ -60,12 +60,16 @@
    * The attribute usage intended for non-standard operational
    * attributes used by a single DSA.
    */
-  DSA_OPERATION("dSAOperation");
+  DSA_OPERATION("dSAOperation", true);
 
 
 
   // The string representation of this attribute usage.
-  String usageString;
+  private final String usageString;
+
+  // Flag indicating whether or not the usage should be categorized as
+  // operational.
+  private final boolean isOperational;
 
 
 
@@ -73,12 +77,17 @@
    * Creates a new attribute usage with the provided string
    * representation.
    *
-   * @param  usageString  The string representation of this attribute
-   *                      usage.
+   * @param usageString
+   *          The string representation of this attribute usage.
+   * @param isOperational
+   *          <code>true</code> if attributes having this attribute
+   *          usage are operational, or <code>false</code>
+   *          otherwise.
    */
-  private AttributeUsage(String usageString)
+  private AttributeUsage(String usageString, boolean isOperational)
   {
     this.usageString = usageString;
+    this.isOperational = isOperational;
   }
 
 
@@ -92,5 +101,19 @@
   {
     return usageString;
   }
+
+
+
+  /**
+   * Determine whether or not attributes having this attribute usage
+   * are operational.
+   *
+   * @return Returns <code>true</code> if attributes having this
+   *         attribute usage are operational, or <code>false</code>
+   *         otherwise.
+   */
+  public boolean isOperational() {
+    return isOperational;
+  }
 }
 

--
Gitblit v1.10.0