From 1bac1f37201cd12e5c70c6fa0139074bc42dcab1 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 19 Dec 2014 14:09:12 +0000
Subject: [PATCH] StaticUtils.java: Extracted methods addAttributeValue() and getObjectClassName().

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java |  113 +++++++++++++++++++++++---------------------------------
 1 files changed, 47 insertions(+), 66 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java
index 411ecd4..578ffc7 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java
@@ -3610,42 +3610,8 @@
     RDN rdn = dn.rdn();
     int numAVAs = rdn.getNumValues();
 
-    // If there is only one RDN attribute, then see which objectclass we should
-    // use.
-    ObjectClass structuralClass;
-    if (numAVAs == 1)
-    {
-      AttributeType attrType = rdn.getAttributeType(0);
-
-      if (attrType.hasName(ATTR_C))
-      {
-        structuralClass = DirectoryServer.getObjectClass(OC_COUNTRY, true);
-      }
-      else if (attrType.hasName(ATTR_DC))
-      {
-        structuralClass = DirectoryServer.getObjectClass(OC_DOMAIN, true);
-      }
-      else if (attrType.hasName(ATTR_O))
-      {
-        structuralClass = DirectoryServer.getObjectClass(OC_ORGANIZATION, true);
-      }
-      else if (attrType.hasName(ATTR_OU))
-      {
-        structuralClass =
-             DirectoryServer.getObjectClass(OC_ORGANIZATIONAL_UNIT_LC, true);
-      }
-      else
-      {
-        structuralClass =
-             DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC, true);
-      }
-    }
-    else
-    {
-      structuralClass =
-           DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC, true);
-    }
-
+    // If there is only one RDN attribute, then see which objectclass we should use.
+    ObjectClass structuralClass = DirectoryServer.getObjectClass(getObjectClassName(rdn, numAVAs));
 
     // Get the top and untypedObject classes to include in the entry.
     LinkedHashMap<ObjectClass,String> objectClasses =
@@ -3689,39 +3655,11 @@
       // Create the attribute and add it to the appropriate map.
       if (attrType.isOperational())
       {
-        List<Attribute> attrList = operationalAttributes.get(attrType);
-        if ((attrList == null) || attrList.isEmpty())
-        {
-          AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
-          builder.add(attrValue);
-          attrList = new ArrayList<Attribute>(1);
-          attrList.add(builder.toAttribute());
-          operationalAttributes.put(attrType, attrList);
-        }
-        else
-        {
-          AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
-          builder.add(attrValue);
-          attrList.set(0, builder.toAttribute());
-        }
+        addAttributeValue(operationalAttributes, attrType, attrName, attrValue);
       }
       else
       {
-        List<Attribute> attrList = userAttributes.get(attrType);
-        if ((attrList == null) || attrList.isEmpty())
-        {
-          AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
-          builder.add(attrValue);
-          attrList = new ArrayList<Attribute>(1);
-          attrList.add(builder.toAttribute());
-          userAttributes.put(attrType, attrList);
-        }
-        else
-        {
-          AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
-          builder.add(attrValue);
-          attrList.set(0, builder.toAttribute());
-        }
+        addAttributeValue(userAttributes, attrType, attrName, attrValue);
       }
     }
 
@@ -3730,7 +3668,50 @@
     return new Entry(dn, objectClasses, userAttributes, operationalAttributes);
   }
 
+  private static String getObjectClassName(RDN rdn, int numAVAs)
+  {
+    if (numAVAs == 1)
+    {
+      final AttributeType attrType = rdn.getAttributeType(0);
+      if (attrType.hasName(ATTR_C))
+      {
+        return OC_COUNTRY;
+      }
+      else if (attrType.hasName(ATTR_DC))
+      {
+        return OC_DOMAIN;
+      }
+      else if (attrType.hasName(ATTR_O))
+      {
+        return OC_ORGANIZATION;
+      }
+      else if (attrType.hasName(ATTR_OU))
+      {
+        return OC_ORGANIZATIONAL_UNIT_LC;
+      }
+    }
+    return OC_UNTYPED_OBJECT_LC;
+  }
 
+  private static void addAttributeValue(LinkedHashMap<AttributeType, List<Attribute>> attrs,
+      AttributeType attrType, String attrName, ByteString attrValue)
+  {
+    List<Attribute> attrList = attrs.get(attrType);
+    if ((attrList == null) || attrList.isEmpty())
+    {
+      AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
+      builder.add(attrValue);
+      attrList = new ArrayList<Attribute>(1);
+      attrList.add(builder.toAttribute());
+      attrs.put(attrType, attrList);
+    }
+    else
+    {
+      AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
+      builder.add(attrValue);
+      attrList.set(0, builder.toAttribute());
+    }
+  }
 
   /**
    * Retrieves a user-friendly string that indicates the length of time (in

--
Gitblit v1.10.0