From 15440a7ab118debef5993c3b261b1043d9f7afc3 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 18 Aug 2006 23:12:58 +0000
Subject: [PATCH] Update the createEntry method to be more intelligent about the structural objectclass that it uses for the entry that gets created.  If the DN contains a single RDN attribute, then the following mappings will be used:

---
 opends/src/server/org/opends/server/util/StaticUtils.java |   81 ++++++++++++++++++++++++++++++----------
 1 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/StaticUtils.java b/opends/src/server/org/opends/server/util/StaticUtils.java
index 73927b2..98ca5db 100644
--- a/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -3229,10 +3229,22 @@
 
   /**
    * Creates a new, blank entry with the given DN.  It will contain only the
-   * attributes contained in the RDN, and it will be based on the untypedObject
-   * objectclass.  If the entry contains one or more attributes that are not
-   * allowed by the untypedObject class, then the extensibleObject class will
-   * also be added.  Note that this method cannot be used to generate an entry
+   * attribute(s) contained in the RDN.  The choice of objectclasses will be
+   * based on the RDN attribute.  If there is a single RDN attribute, then the
+   * following mapping will be used:
+   * <BR>
+   * <UL>
+   *   <LI>c attribute :: country objectclass</LI>
+   *   <LI>dc attribute :: domain objectclass</LI>
+   *   <LI>o attribute :: organization objectclass</LI>
+   *   <LI>ou attribute :: organizationalUnit objectclass</LI>
+   * </UL>
+   * <BR>
+   * Any other single RDN attribute types, or any case in which there are
+   * multiple RDN attributes, will use the untypedObject objectclass.  If the
+   * RDN includes one or more attributes that are not allowed in the
+   * untypedObject objectclass, then the extensibleObject class will also be
+   * added.  Note that this method cannot be used to generate an entry
    * with an empty or null DN.
    *
    * @param  dn  The DN to use for the entry.
@@ -3252,22 +3264,6 @@
     }
 
 
-    // Get the top and untypedObject classes to include in the entry.
-    LinkedHashMap<ObjectClass,String> objectClasses =
-         new LinkedHashMap<ObjectClass,String>(3);
-
-    objectClasses.put(DirectoryServer.getTopObjectClass(), OC_TOP);
-
-    ObjectClass untypedObjectOC =
-         DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC);
-    if (untypedObjectOC == null)
-    {
-      untypedObjectOC =
-           DirectoryServer.getDefaultObjectClass(OC_UNTYPED_OBJECT);
-    }
-    objectClasses.put(untypedObjectOC, OC_UNTYPED_OBJECT);
-
-
     // Get the information about the RDN attributes.
     RDN rdn = dn.getRDN();
     AttributeType[]  rdnTypes  = rdn.getAttributeTypes();
@@ -3275,6 +3271,49 @@
     AttributeValue[] rdnValues = rdn.getAttributeValues();
 
 
+    // If there is only one RDN attribute, then see which objectclass we should
+    // use.
+    ObjectClass structuralClass;
+    if (rdnTypes.length == 1)
+    {
+      if (rdnTypes[0].hasName(ATTR_C))
+      {
+        structuralClass = DirectoryServer.getObjectClass(OC_COUNTRY, true);
+      }
+      else if (rdnTypes[0].hasName(ATTR_DC))
+      {
+        structuralClass = DirectoryServer.getObjectClass(OC_DOMAIN, true);
+      }
+      else if (rdnTypes[0].hasName(ATTR_O))
+      {
+        structuralClass = DirectoryServer.getObjectClass(OC_ORGANIZATION, true);
+      }
+      else if (rdnTypes[0].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);
+    }
+
+
+    // Get the top and untypedObject classes to include in the entry.
+    LinkedHashMap<ObjectClass,String> objectClasses =
+         new LinkedHashMap<ObjectClass,String>(3);
+
+    objectClasses.put(DirectoryServer.getTopObjectClass(), OC_TOP);
+    objectClasses.put(structuralClass, structuralClass.getNameOrOID());
+
+
     // Iterate through the RDN attributes and add them to the set of user or
     // operational attributes.
     LinkedHashMap<AttributeType,List<Attribute>> userAttributes =
@@ -3287,7 +3326,7 @@
     {
       // First, see if this type is allowed by the untypedObject class.  If not,
       // then we'll need to include the extensibleObject class.
-      if ((! untypedObjectOC.isRequiredOrOptional(rdnTypes[i])) &&
+      if ((! structuralClass.isRequiredOrOptional(rdnTypes[i])) &&
           (! extensibleObjectAdded))
       {
         ObjectClass extensibleObjectOC =

--
Gitblit v1.10.0