From aac8798b81c60524d57e85ff44720c74fe5a029b 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:

---
 opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java     |   81 ++++++++++++++++++++-------
 opendj-sdk/opends/src/server/org/opends/server/util/ServerConstants.java |   72 ++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 21 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/ServerConstants.java b/opendj-sdk/opends/src/server/org/opends/server/util/ServerConstants.java
index f7c635c..b33e39b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/ServerConstants.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/ServerConstants.java
@@ -112,6 +112,14 @@
 
 
   /**
+   * The name of the standard attribute that is used to hold country names,
+   * formatted in all lowercase.
+   */
+  public static final String ATTR_C = "c";
+
+
+
+  /**
    * The name of the standard attribute that is used to hold common names,
    * formatted in all lowercase.
    */
@@ -152,6 +160,14 @@
 
 
   /**
+   * The name of the standard attribute that is used to hold domain component
+   * names, formatted in all lowercase.
+   */
+  public static final String ATTR_DC = "dc";
+
+
+
+  /**
    * The name of the attribute that is used to specify the maximum number of
    * connections established at any time since startup, formatted in camel case.
    */
@@ -187,6 +203,22 @@
 
 
   /**
+   * The name of the standard attribute that is used to hold organization names,
+   * formatted in all lowercase.
+   */
+  public static final String ATTR_O = "o";
+
+
+
+  /**
+   * The name of the standard attribute that is used to hold organizational unit
+   * names, formatted in all lowercase.
+   */
+  public static final String ATTR_OU = "ou";
+
+
+
+  /**
    * The name of the standard attribute that is used to specify the name of the
    * Directory Server product, formatted in camel case.
    */
@@ -407,6 +439,22 @@
   public static final String OC_ALIAS = "alias";
 
 
+
+  /**
+   * The name of the standard objectclass, formatted in all lowercase, that is
+   * used to indicate that an entry describes a country.
+   */
+  public static final String OC_COUNTRY = "country";
+
+
+
+  /**
+   * The name of the standard objectclass, formatted in all lowercase, that is
+   * used to indicate that an entry describes a domain.
+   */
+  public static final String OC_DOMAIN = "domain";
+
+
   /**
    * The name of the standard objectclass that is used to allow any attribute
    * type to be present in an entry, formatted in camel case.
@@ -479,6 +527,30 @@
 
 
   /**
+   * The name of the standard objectclass, formatted in all lowercase, that is
+   * used to indicate that an entry describes an organization.
+   */
+  public static final String OC_ORGANIZATION = "organization";
+
+
+
+  /**
+   * The name of the standard objectclass that is  used to indicate that an
+   * entry describes an organizational unit.
+   */
+  public static final String OC_ORGANIZATIONAL_UNIT = "organizationalUnit";
+
+
+
+  /**
+   * The name of the organizationalUnit objectclass formatted in all lowercase
+   * characters.
+   */
+  public static final String OC_ORGANIZATIONAL_UNIT_LC = "organizationalunit";
+
+
+
+  /**
    * The name of the standard objectclass that is used to indicate that an entry
    * is a smart referral, formatted in all lowercase.
    */
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java b/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
index 73927b2..98ca5db 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opendj-sdk/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