From fef6bf6f14335a840bfa1b0b34ca5f1658155fd1 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 05 Mar 2014 08:15:38 +0000
Subject: [PATCH] OPENDJ-1308 Migrate schema support

---
 opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java  |   14 
 opendj3-server-dev/src/server/org/opends/server/types/DITContentRule.java                            |  219 ------
 opendj3-server-dev/src/server/org/opends/server/types/MatchingRuleUse.java                           |  137 ----
 opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java                          |   94 --
 opendj3-server-dev/src/server/org/opends/server/types/Schema.java                                    |  485 ++------------
 opendj3-server-dev/src/server/org/opends/server/types/LDAPSyntaxDescription.java                     |   84 --
 opendj3-server-dev/src/server/org/opends/server/types/DITStructureRule.java                          |  144 ----
 opendj3-server-dev/src/server/org/opends/server/types/ObjectClass.java                               |   95 --
 opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestAttributeType.java |   76 --
 opendj3-server-dev/src/server/org/opends/server/types/NameForm.java                                  |  169 -----
 opendj3-server-dev/src/server/org/opends/server/types/SchemaFileElement.java                         |    9 
 opendj3-server-dev/src/server/org/opends/server/types/CommonSchemaElements.java                      |  119 ---
 opendj3-server-dev/src/server/org/opends/server/types/AttributeType.java                             |   84 --
 opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestObjectClass.java   |  152 +---
 14 files changed, 168 insertions(+), 1,713 deletions(-)

diff --git a/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java b/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
index b8222ff..ab632c6 100644
--- a/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
+++ b/opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -172,6 +172,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public Set<String> getBackends()
   {
     return Collections.emptySet();
@@ -180,6 +181,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public boolean canLaunch(Task taskToBeLaunched,
       Collection<LocalizableMessage> incompatibilityReasons)
   {
@@ -199,6 +201,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public Type getType()
   {
     return Type.NEW_SCHEMA_ELEMENT;
@@ -207,6 +210,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public void runTask()
   {
     state = State.RUNNING;
@@ -227,6 +231,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   protected String getCommandLinePath()
   {
     return null;
@@ -235,6 +240,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   protected List<String> getCommandLineArguments()
   {
     return Collections.emptyList();
@@ -243,6 +249,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public LocalizableMessage getTaskDescription()
   {
     return INFO_CTRL_PANEL_DELETE_SCHEMA_ELEMENT_TASK_DESCRIPTION.get();
@@ -262,6 +269,7 @@
       final ObjectClass fObjectclass = objectClass;
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           if (!isFirst[0])
@@ -305,6 +313,7 @@
       final int fNumberDeleted = numberDeleted;
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           getProgressDialog().getProgressBar().setIndeterminate(false);
@@ -321,6 +330,7 @@
       final AttributeType fAttribute = attribute;
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           if (!isFirst[0])
@@ -366,6 +376,7 @@
       final int fNumberDeleted = numberDeleted;
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           getProgressDialog().getProgressBar().setIndeterminate(false);
@@ -381,6 +392,7 @@
     {
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           getProgressDialog().appendProgressHtml(Utilities.applyFont(
@@ -486,7 +498,7 @@
    */
   private String getSchemaFileAttributeValue(CommonSchemaElements element)
   {
-    return element.getDefinition();
+    return element.toString();
   }
 
   /**
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java b/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
index aa04f87..a9f4e11 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/SchemaBackend.java
@@ -58,6 +58,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.ConditionResult;
 import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchScope;
 import org.forgerock.opendj.ldap.schema.ObjectClassType;
 import org.forgerock.util.Reject;
@@ -86,7 +87,6 @@
 import org.opends.server.schema.NameFormSyntax;
 import org.opends.server.schema.ObjectClassSyntax;
 import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
 import org.opends.server.util.DynamicConstants;
 import org.opends.server.util.LDIFException;
 import org.opends.server.util.LDIFReader;
@@ -3121,8 +3121,8 @@
     // We allow only unimplemented syntaxes to be substituted.
     if(schema.getSyntax(oid) !=null)
     {
-      LocalizableMessage message = ERR_ATTR_SYNTAX_INVALID_LDAP_SYNTAX.get(
-              ldapSyntaxDesc.getDefinition(),oid);
+      LocalizableMessage message =
+          ERR_ATTR_SYNTAX_INVALID_LDAP_SYNTAX.get(ldapSyntaxDesc, oid);
       throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                                      message);
     }
@@ -3259,7 +3259,7 @@
       if (schemaFile.equals(getSchemaFile(ldapSyntax)))
       {
         values.add(AttributeValues.create(ldapSyntaxesType,
-                ldapSyntax.getDefinition()));
+                ldapSyntax.toString()));
       }
     }
 
@@ -3329,8 +3329,7 @@
       {
         if (schemaFile.equals(getSchemaFile(nf)))
         {
-          values.add(AttributeValues.create(
-              nameFormsType, nf.getDefinition()));
+          values.add(AttributeValues.create(nameFormsType, nf.toString()));
         }
       }
     }
@@ -3354,7 +3353,7 @@
       if (schemaFile.equals(getSchemaFile(dcr)))
       {
         values.add(AttributeValues.create(ditContentRulesType,
-                                      dcr.getDefinition()));
+                                      dcr.toString()));
       }
     }
 
@@ -3401,7 +3400,7 @@
       if (schemaFile.equals(getSchemaFile(mru)))
       {
         values.add(AttributeValues.create(matchingRuleUsesType,
-                                      mru.getDefinition()));
+                                      mru.toString()));
       }
     }
 
@@ -3485,7 +3484,7 @@
     }
 
     values.add(AttributeValues.create(attributeTypesType,
-                                  attributeType.getDefinition()));
+                                  attributeType.toString()));
     addedTypes.add(attributeType);
   }
 
@@ -3536,7 +3535,7 @@
       }
     }
     values.add(AttributeValues.create(objectClassesType,
-                                  objectClass.getDefinition()));
+                                  objectClass.toString()));
     addedClasses.add(objectClass);
   }
 
@@ -3587,7 +3586,7 @@
     }
 
     values.add(AttributeValues.create(ditStructureRulesType,
-                                  ditStructureRule.getDefinition()));
+                                  ditStructureRule.toString()));
     addedDSRs.add(ditStructureRule);
   }
 
@@ -3712,20 +3711,7 @@
     {
       logger.traceException(e);
 
-      for (File f : installedFileList)
-      {
-        try
-        {
-          if (f.exists())
-          {
-            f.delete();
-          }
-        }
-        catch (Exception e2)
-        {
-          logger.traceException(e2);
-        }
-      }
+      deleteFiles(installedFileList);
 
       boolean allRestored = true;
       for (int i=0; i < installedFileList.size(); i++)
@@ -3772,38 +3758,28 @@
       }
     }
 
+    deleteFiles(origFileList);
+    deleteFiles(tempFileList);
+  }
 
-    // At this point, we're committed to the schema change, so we can't throw
-    // any more exceptions, but all we have left is to clean up the original and
-    // temporary files.
-    for (File f : origFileList)
+  private void deleteFiles(Iterable<File> files)
+  {
+    if (files != null)
     {
-      try
+      for (File f : files)
       {
-        if (f.exists())
+        try
         {
-          f.delete();
+          if (f.exists())
+          {
+            f.delete();
+          }
         }
-      }
-      catch (Exception e)
-      {
-        logger.traceException(e);
-      }
-    }
-
-    for (File f : tempFileList)
-    {
-      try
-      {
-        if (f.exists())
+        catch (Exception e)
         {
-          f.delete();
+          logger.traceException(e);
         }
       }
-      catch (Exception e)
-      {
-        logger.traceException(e);
-      }
     }
   }
 
@@ -3852,25 +3828,7 @@
    */
   private void cleanUpTempSchemaFiles(HashMap<String,File> tempSchemaFiles)
   {
-    if ((tempSchemaFiles == null) || tempSchemaFiles.isEmpty())
-    {
-      return;
-    }
-
-    for (File f : tempSchemaFiles.values())
-    {
-      try
-      {
-        if (f.exists())
-        {
-          f.delete();
-        }
-      }
-      catch (Exception e)
-      {
-        logger.traceException(e);
-      }
-    }
+    deleteFiles(tempSchemaFiles.values());
   }
 
 
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/AttributeType.java b/opendj3-server-dev/src/server/org/opends/server/types/AttributeType.java
index 07b2b3a..0fb59bf 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/AttributeType.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/AttributeType.java
@@ -390,21 +390,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this attribute
-   * type.
-   *
-   * @return  The definition string used to create this attribute
-   *          type.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves the superior type for this attribute type.
    *
    * @return  The superior type for this attribute type, or
@@ -639,74 +624,11 @@
     return isObjectClassType;
   }
 
-
-
-  /**
-   * Appends a string representation of this schema definition's
-   * non-generic properties to the provided buffer.
-   *
-   * @param  buffer  The buffer to which the information should be
-   *                 appended.
-   */
+  /** {@inheritDoc} */
   @Override
-  protected void toStringContent(StringBuilder buffer)
+  public String toString()
   {
-    if (superiorType != null)
-    {
-      buffer.append(" SUP ");
-      buffer.append(superiorType.getNameOrOID());
-    }
-
-    if (equalityMatchingRule != null)
-    {
-      buffer.append(" EQUALITY ");
-      buffer.append(equalityMatchingRule.getNameOrOID());
-    }
-
-    if (orderingMatchingRule != null)
-    {
-      buffer.append(" ORDERING ");
-      buffer.append(orderingMatchingRule.getNameOrOID());
-    }
-
-    if (substringMatchingRule != null)
-    {
-      buffer.append(" SUBSTR ");
-      buffer.append(substringMatchingRule.getNameOrOID());
-    }
-
-    // NOTE -- We will not include any approximate matching rule
-    // information here because it would break the standard and
-    // anything that depends on it.
-    // FIXME -- Should we encode this into one of the "extra"
-    // properties?
-
-    if (syntax != null)
-    {
-      buffer.append(" SYNTAX ");
-      buffer.append(syntax.getOID());
-    }
-
-    if (isSingleValue)
-    {
-      buffer.append(" SINGLE-VALUE");
-    }
-
-    if (isCollective)
-    {
-      buffer.append(" COLLECTIVE");
-    }
-
-    if (isNoUserModification)
-    {
-      buffer.append(" NO-USER-MODIFICATION");
-    }
-
-    if (attributeUsage != null)
-    {
-      buffer.append(" USAGE ");
-      buffer.append(attributeUsage.toString());
-    }
+    return definition;
   }
 
   /**
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/CommonSchemaElements.java b/opendj3-server-dev/src/server/org/opends/server/types/CommonSchemaElements.java
index 90a6379..681e507 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/CommonSchemaElements.java
@@ -28,7 +28,6 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -545,122 +544,6 @@
     return hashCode;
   }
 
-
-
-  /**
-   * Retrieves the string representation of this schema definition in
-   * the form specified in RFC 2252.
-   *
-   * @return The string representation of this schema definition in
-   *         the form specified in RFC 2252.
-   */
-  @Override
-  public final String toString() {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
-  }
-
-
-
-  /**
-   * Appends a string representation of this schema definition in the
-   * form specified in RFC 2252 to the provided buffer.
-   *
-   * @param buffer
-   *          The buffer to which the information should be appended.
-   * @param includeFileElement
-   *          Indicates whether to include an "extra" property that
-   *          specifies the path to the schema file from which this
-   *          schema definition was loaded.
-   */
-  private final void toString(StringBuilder buffer, boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(oid);
-
-    if (!names.isEmpty()) {
-      Iterator<String> iterator = names.values().iterator();
-
-      String firstName = iterator.next();
-      if (iterator.hasNext()) {
-        buffer.append(" NAME ( '");
-        buffer.append(firstName);
-
-        while (iterator.hasNext()) {
-          buffer.append("' '");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append("' )");
-      } else {
-        buffer.append(" NAME '");
-        buffer.append(firstName);
-        buffer.append("'");
-      }
-    }
-
-    if ((description != null) && (description.length() > 0)) {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (isObsolete) {
-      buffer.append(" OBSOLETE");
-    }
-
-    // Delegate remaining string output to sub-class.
-    toStringContent(buffer);
-
-    if (!extraProperties.isEmpty()) {
-      for (Map.Entry<String, List<String>> e : extraProperties
-          .entrySet()) {
-
-        String property = e.getKey();
-        if (!includeFileElement
-            && property.equals(SCHEMA_PROPERTY_FILENAME)) {
-          // Don't include the schema file if it was not requested.
-          continue;
-        }
-
-        List<String> valueList = e.getValue();
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1) {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        } else {
-          buffer.append(" ( ");
-
-          for (String value : valueList) {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
-
-
-
-  /**
-   * Appends a string representation of this schema definition's
-   * non-generic properties to the provided buffer.
-   *
-   * @param buffer
-   *          The buffer to which the information should be appended.
-   */
-  protected abstract void toStringContent(StringBuilder buffer);
-
   /**
    * Retrieves the definition string used to create this attribute
    * type and including the X-SCHEMA-FILE extension.
@@ -672,7 +555,7 @@
   public static String getDefinitionWithFileName(SchemaFileElement elem)
   {
     final String schemaFile = getSchemaFile(elem);
-    final String definition = elem.getDefinition();
+    final String definition = elem.toString();
     if (schemaFile != null)
     {
       int pos = definition.lastIndexOf(')');
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/DITContentRule.java b/opendj3-server-dev/src/server/org/opends/server/types/DITContentRule.java
index 14c15f2..2d230bf 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/DITContentRule.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/DITContentRule.java
@@ -225,21 +225,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this DIT content
-   * rule.
-   *
-   * @return  The definition string used to create this DIT content
-   *          rule.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves the structural objectclass for this DIT content rule.
    *
    * @return  The structural objectclass for this DIT content rule.
@@ -520,209 +505,7 @@
   @Override
   public String toString()
   {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
+    return definition;
   }
 
-
-
-  /**
-   * Appends a string representation of this attribute type in the
-   * form specified in RFC 2252 to the provided buffer.
-   *
-   * @param  buffer              The buffer to which the information
-   *                             should be appended.
-   * @param  includeFileElement  Indicates whether to include an
-   *                             "extra" property that specifies the
-   *                             path to the schema file from which
-   *                             this DIT content rule was loaded.
-   */
-  public void toString(StringBuilder buffer,
-  boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(structuralClass.getOID());
-
-    if (! names.isEmpty())
-    {
-      Iterator<String> iterator = names.values().iterator();
-
-      String firstName = iterator.next();
-      if (iterator.hasNext())
-      {
-        buffer.append(" NAME ( '");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append("' '");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append("' )");
-      }
-      else
-      {
-        buffer.append(" NAME '");
-        buffer.append(firstName);
-        buffer.append("'");
-      }
-    }
-
-    if ((description != null) && (description.length() > 0))
-    {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (isObsolete)
-    {
-      buffer.append(" OBSOLETE");
-    }
-
-    if (! auxiliaryClasses.isEmpty())
-    {
-      Iterator<ObjectClass> iterator = auxiliaryClasses.iterator();
-
-      String firstClass = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" AUX (");
-        buffer.append(firstClass);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" AUX ");
-        buffer.append(firstClass);
-      }
-    }
-
-    if (! requiredAttributes.isEmpty())
-    {
-      Iterator<AttributeType> iterator =
-           requiredAttributes.iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" MUST ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" MUST ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (! optionalAttributes.isEmpty())
-    {
-      Iterator<AttributeType> iterator =
-           optionalAttributes.iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" MAY ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" MAY ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (! prohibitedAttributes.isEmpty())
-    {
-      Iterator<AttributeType> iterator =
-           prohibitedAttributes.iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" NOT ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" NOT ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (! extraProperties.isEmpty())
-    {
-      for (String property : extraProperties.keySet())
-      {
-        if ((! includeFileElement) &&
-            property.equals(SCHEMA_PROPERTY_FILENAME))
-        {
-          continue;
-        }
-
-        List<String> valueList = extraProperties.get(property);
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1)
-        {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        }
-        else
-        {
-          buffer.append(" ( ");
-
-          for (String value : valueList)
-          {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
 }
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/DITStructureRule.java b/opendj3-server-dev/src/server/org/opends/server/types/DITStructureRule.java
index c3c5803..166ba12 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/DITStructureRule.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/DITStructureRule.java
@@ -26,7 +26,6 @@
  */
 package org.opends.server.types;
 
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -175,21 +174,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this DIT structure
-   * rule.
-   *
-   * @return  The definition string used to create this DIT structure
-   *          rule.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves the set of names that may be used to reference this DIT
    * structure rule.  The returned mapping will be between an all
    * lower-case form of the name and a name in the user-defined form
@@ -400,133 +384,7 @@
   @Override
   public String toString()
   {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
+    return definition;
   }
 
-
-
-  /**
-   * Appends a string representation of this attribute type in the
-   * form specified in RFC 2252 to the provided buffer.
-   *
-   * @param  buffer              The buffer to which the information
-   *                             should be appended.
-   * @param  includeFileElement  Indicates whether to include an
-   *                             "extra" property that specifies the
-   *                             path to the schema file from which
-   *                             this DIT structure rule was loaded.
-   */
-  private void toString(StringBuilder buffer, boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(ruleID);
-
-    if (! names.isEmpty())
-    {
-      Iterator<String> iterator = names.values().iterator();
-
-      String firstName = iterator.next();
-      if (iterator.hasNext())
-      {
-        buffer.append(" NAME ( '");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append("' '");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append("' )");
-      }
-      else
-      {
-        buffer.append(" NAME '");
-        buffer.append(firstName);
-        buffer.append("'");
-      }
-    }
-
-    if ((description != null) && (description.length() > 0))
-    {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (isObsolete)
-    {
-      buffer.append(" OBSOLETE");
-    }
-
-    buffer.append(" FORM ");
-    buffer.append(nameForm.getNameOrOID());
-
-    if ((superiorRules != null) && (! superiorRules.isEmpty()))
-    {
-      Iterator<DITStructureRule> iterator = superiorRules.iterator();
-
-      int firstRule = iterator.next().getRuleID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" SUP ( ");
-        buffer.append(firstRule);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" ");
-          buffer.append(iterator.next().getRuleID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" SUP ");
-        buffer.append(firstRule);
-      }
-    }
-
-    if (! extraProperties.isEmpty())
-    {
-      for (String property : extraProperties.keySet())
-      {
-        if ((! includeFileElement) &&
-            property.equals(SCHEMA_PROPERTY_FILENAME))
-        {
-          continue;
-        }
-
-        List<String> valueList = extraProperties.get(property);
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1)
-        {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        }
-        else
-        {
-          buffer.append(" ( ");
-
-          for (String value : valueList)
-          {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
 }
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/LDAPSyntaxDescription.java b/opendj3-server-dev/src/server/org/opends/server/types/LDAPSyntaxDescription.java
index e246ce1..5b60f36 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/LDAPSyntaxDescription.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/LDAPSyntaxDescription.java
@@ -137,21 +137,6 @@
 
 
 
-    /**
-   * Retrieves the definition string used to create this ldap syntax
-   * description.
-   *
-   * @return  The definition string used to create this ldap syntax
-     *            description.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
    /**
    * Retrieves the ldap syntax description syntax associated with
     * this ldap syntax.
@@ -299,74 +284,7 @@
   @Override
   public String toString()
   {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
+    return definition;
   }
 
-
-
-  /**
-   * Appends a string representation of this ldap syntax in the form
-   * specified in RFC 2252 to the provided buffer.
-   *
-   * @param  buffer              The buffer to which the information
-   *                             should be appended.
-   * @param  includeFileElement  Indicates whether to include an
-   *                             "extra" property that specifies the
-   *                             path to the schema file from which
-   *                             this ldap syntax was loaded.
-   */
-  public void toString(StringBuilder buffer,
-                       boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(oid);
-
-    if ((description != null) && (description.length() > 0))
-    {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (! extraProperties.isEmpty())
-    {
-      for (String property : extraProperties.keySet())
-      {
-        if ((! includeFileElement) &&
-            property.equals(SCHEMA_PROPERTY_FILENAME))
-        {
-          continue;
-        }
-
-        List<String> valueList = extraProperties.get(property);
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1)
-        {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        }
-        else
-        {
-          buffer.append(" ( ");
-
-          for (String value : valueList)
-          {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
 }
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/MatchingRuleUse.java b/opendj3-server-dev/src/server/org/opends/server/types/MatchingRuleUse.java
index c358501..2e219b1 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/MatchingRuleUse.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/MatchingRuleUse.java
@@ -26,7 +26,6 @@
  */
 package org.opends.server.types;
 
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -175,21 +174,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this matching rule
-   * use.
-   *
-   * @return  The definition string used to create this matching rule
-   *          use.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves the matching rule for this matching rule use.
    *
    * @return  The matching rule for this matching rule use.
@@ -379,126 +363,7 @@
   @Override
   public String toString()
   {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
+    return definition;
   }
 
-
-
-  /**
-   * Appends a string representation of this matching rule use in the
-   * form specified in RFC 2252 to the provided buffer.
-   *
-   * @param  buffer              The buffer to which the information
-   *                             should be appended.
-   * @param  includeFileElement  Indicates whether to include an
-   *                             "extra" property that specifies the
-   *                             path to the schema file from which
-   *                             this matching rule use was loaded.
-   */
-  private void toString(StringBuilder buffer, boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(matchingRule.getOID());
-
-    if (! names.isEmpty())
-    {
-      Iterator<String> iterator = names.values().iterator();
-
-      String firstName = iterator.next();
-      if (iterator.hasNext())
-      {
-        buffer.append(" NAME ( '");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append("' '");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append("' )");
-      }
-      else
-      {
-        buffer.append(" NAME '");
-        buffer.append(firstName);
-        buffer.append("'");
-      }
-    }
-
-    if ((description != null) && (description.length() > 0))
-    {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (isObsolete)
-    {
-      buffer.append(" OBSOLETE");
-    }
-
-    buffer.append(" APPLIES ");
-    Iterator<AttributeType> iterator = attributes.iterator();
-    String firstName = iterator.next().getNameOrOID();
-    if (iterator.hasNext())
-    {
-      buffer.append("( ");
-      buffer.append(firstName);
-
-      while (iterator.hasNext())
-      {
-        buffer.append(" $ ");
-        buffer.append(iterator.next().getNameOrOID());
-      }
-
-      buffer.append(" )");
-    }
-    else
-    {
-      buffer.append(firstName);
-    }
-
-    if (! extraProperties.isEmpty())
-    {
-      for (String property : extraProperties.keySet())
-      {
-        if ((! includeFileElement) &&
-            property.equals(SCHEMA_PROPERTY_FILENAME))
-        {
-          continue;
-        }
-
-        List<String> valueList = extraProperties.get(property);
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1)
-        {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        }
-        else
-        {
-          buffer.append(" ( ");
-
-          for (String value : valueList)
-          {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
 }
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/NameForm.java b/opendj3-server-dev/src/server/org/opends/server/types/NameForm.java
index 8900991..2c97e9c 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/NameForm.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/NameForm.java
@@ -26,7 +26,6 @@
  */
 package org.opends.server.types;
 
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -193,19 +192,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this name form.
-   *
-   * @return  The definition string used to create this name form.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves the set of names that may be used to reference this
    * name form.  The returned object will be a mapping between each
    * name in all lowercase characters and that name in a user-defined
@@ -489,160 +475,7 @@
   @Override
   public String toString()
   {
-    StringBuilder buffer = new StringBuilder();
-    toString(buffer, true);
-    return buffer.toString();
+    return definition;
   }
 
-
-
-  /**
-   * Appends a string representation of this name form in the form
-   * specified in RFC 2252 to the provided buffer.
-   *
-   * @param  buffer              The buffer to which the information
-   *                             should be appended.
-   * @param  includeFileElement  Indicates whether to include an
-   *                             "extra" property that specifies the
-   *                             path to the schema file from which
-   *                             this name form was loaded.
-   */
-  private void toString(StringBuilder buffer, boolean includeFileElement)
-  {
-    buffer.append("( ");
-    buffer.append(oid);
-
-    if (! names.isEmpty())
-    {
-      Iterator<String> iterator = names.values().iterator();
-
-      String firstName = iterator.next();
-      if (iterator.hasNext())
-      {
-        buffer.append(" NAME ( '");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append("' '");
-          buffer.append(iterator.next());
-        }
-
-        buffer.append("' )");
-      }
-      else
-      {
-        buffer.append(" NAME '");
-        buffer.append(firstName);
-        buffer.append("'");
-      }
-    }
-
-    if ((description != null) && (description.length() > 0))
-    {
-      buffer.append(" DESC '");
-      buffer.append(description);
-      buffer.append("'");
-    }
-
-    if (isObsolete)
-    {
-      buffer.append(" OBSOLETE");
-    }
-
-    buffer.append(" OC ");
-    buffer.append(structuralClass.getNameOrOID());
-
-    if (! requiredAttributes.isEmpty())
-    {
-      Iterator<AttributeType> iterator =
-           requiredAttributes.iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" MUST ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" MUST ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (! optionalAttributes.isEmpty())
-    {
-      Iterator<AttributeType> iterator =
-           optionalAttributes.iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext())
-      {
-        buffer.append(" MAY ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext())
-        {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      }
-      else
-      {
-        buffer.append(" MAY ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (! extraProperties.isEmpty())
-    {
-      for (String property : extraProperties.keySet())
-      {
-        if ((! includeFileElement) &&
-            property.equals(SCHEMA_PROPERTY_FILENAME))
-        {
-          continue;
-        }
-
-        List<String> valueList = extraProperties.get(property);
-
-        buffer.append(" ");
-        buffer.append(property);
-
-        if (valueList.size() == 1)
-        {
-          buffer.append(" '");
-          buffer.append(valueList.get(0));
-          buffer.append("'");
-        }
-        else
-        {
-          buffer.append(" ( ");
-
-          for (String value : valueList)
-          {
-            buffer.append("'");
-            buffer.append(value);
-            buffer.append("' ");
-          }
-
-          buffer.append(")");
-        }
-      }
-    }
-
-    buffer.append(" )");
-  }
 }
-
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/ObjectClass.java b/opendj3-server-dev/src/server/org/opends/server/types/ObjectClass.java
index a97967d..c4453ea 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/ObjectClass.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/ObjectClass.java
@@ -29,7 +29,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -268,19 +267,6 @@
 
 
   /**
-   * Retrieves the definition string used to create this objectclass.
-   *
-   * @return  The definition string used to create this objectclass.
-   */
-  @Override
-  public String getDefinition()
-  {
-    return definition;
-  }
-
-
-
-  /**
    * Retrieves an unmodifiable view of the set of direct superior
    * classes for this objectclass.
    *
@@ -470,84 +456,11 @@
     return isExtensibleObject;
   }
 
-
-
-  /**
-   * Appends a string representation of this schema definition's
-   * non-generic properties to the provided buffer.
-   *
-   * @param  buffer  The buffer to which the information should be
-   *                 appended.
-   */
+  /** {@inheritDoc} */
   @Override
-  protected void toStringContent(StringBuilder buffer) {
-
-    if (!superiorClasses.isEmpty()) {
-      buffer.append(" SUP ");
-      Iterator<ObjectClass> iterator = superiorClasses.iterator();
-      ObjectClass oc =  iterator.next();
-
-      if(iterator.hasNext()) {
-        buffer.append("( ");
-        buffer.append(oc.getNameOrOID());
-
-        while(iterator.hasNext()) {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      } else {
-        buffer.append(oc.getNameOrOID());
-      }
-    }
-
-    if (objectClassType != null) {
-      buffer.append(" ");
-      buffer.append(objectClassType.toString());
-    }
-
-    if (!requiredAttributes.isEmpty()) {
-      Iterator<AttributeType> iterator = requiredAttributes
-          .iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext()) {
-        buffer.append(" MUST ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext()) {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      } else {
-        buffer.append(" MUST ");
-        buffer.append(firstName);
-      }
-    }
-
-    if (!optionalAttributes.isEmpty()) {
-      Iterator<AttributeType> iterator = optionalAttributes
-          .iterator();
-
-      String firstName = iterator.next().getNameOrOID();
-      if (iterator.hasNext()) {
-        buffer.append(" MAY ( ");
-        buffer.append(firstName);
-
-        while (iterator.hasNext()) {
-          buffer.append(" $ ");
-          buffer.append(iterator.next().getNameOrOID());
-        }
-
-        buffer.append(" )");
-      } else {
-        buffer.append(" MAY ");
-        buffer.append(firstName);
-      }
-    }
+  public String toString()
+  {
+    return definition;
   }
 
 
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/Schema.java b/opendj3-server-dev/src/server/org/opends/server/types/Schema.java
index 7b6b4fc..c291787 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/Schema.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/Schema.java
@@ -450,16 +450,7 @@
       {
         registerSubordinateType(attributeType, superiorType);
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = attributeType.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      attributeTypeSet.add(AttributeValues.create(rawValue,
-          normValue));
+      attributeTypeSet.add(createAttrValueForAdd(attributeType));
     }
   }
 
@@ -506,34 +497,48 @@
       {
         deregisterSubordinateType(attributeType, superiorType);
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = attributeType.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        attributeTypeSet.remove(AttributeValues.create(rawValue,
-                                                   normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = attributeType.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        attributeTypeSet.remove(AttributeValues.create(rawValue,
-                                                   normValue));
-      }
+      attributeTypeSet.remove(createAttrValueForRemove(attributeType));
     }
   }
 
 
 
   /**
+   * We'll use an attribute value including the normalized value rather than the
+   * attribute type because otherwise it would use a very expensive matching
+   * rule (OID first component match) that would kill performance.
+   */
+  private AttributeValue createAttrValueForRemove(Object elem)
+  {
+    final String valueString = elem.toString();
+    final ByteString rawValue = ByteString.valueOf(valueString);
+    final ByteString normValue = normalizeAttrValue(valueString, rawValue);
+    return AttributeValues.create(rawValue, normValue);
+  }
+
+  private ByteString normalizeAttrValue(String valueString, ByteString rawValue)
+  {
+    try
+    {
+      return normalizeAttributeValue(rawValue);
+    }
+    catch (Exception e)
+    {
+      return ByteString.valueOf(toLowerCase(valueString));
+    }
+  }
+
+  private AttributeValue createAttrValueForAdd(Object elem)
+      throws DirectoryException
+  {
+    final String valueString = elem.toString();
+    final ByteString rawValue = ByteString.valueOf(valueString);
+    final ByteString normValue = normalizeAttributeValue(rawValue);
+    return AttributeValues.create(rawValue, normValue);
+  }
+
+
+  /**
    * Registers the provided attribute type as a subtype of the given
    * superior attribute type, recursively following any additional
    * elements in the superior chain.
@@ -752,15 +757,7 @@
       {
         objectClasses.put(name, objectClass);
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = objectClass.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      objectClassSet.add(AttributeValues.create(rawValue, normValue));
+      objectClassSet.add(createAttrValueForAdd(objectClass));
     }
   }
 
@@ -787,29 +784,7 @@
       {
         objectClasses.remove(name, objectClass);
       }
-
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = objectClass.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        objectClassSet.remove(AttributeValues.create(rawValue,
-                                                 normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = objectClass.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        objectClassSet.remove(AttributeValues.create(rawValue,
-                                                 normValue));
-      }
+      objectClassSet.remove(createAttrValueForRemove(objectClass));
     }
   }
 
@@ -961,15 +936,7 @@
       }
 
       syntaxes.put(toLowerCase(syntax.getOID()), syntax);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = syntax.toString();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      syntaxSet.add(AttributeValues.create(rawValue, normValue));
+      syntaxSet.add(createAttrValueForAdd(syntax));
     }
   }
 
@@ -987,26 +954,7 @@
     synchronized (syntaxes)
     {
       syntaxes.remove(toLowerCase(syntax.getOID()), syntax);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = syntax.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        syntaxSet.remove(AttributeValues.create(rawValue, normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = syntax.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        syntaxSet.remove(AttributeValues.create(rawValue, normValue));
-      }
+      syntaxSet.remove(createAttrValueForRemove(syntax));
     }
   }
 
@@ -1015,7 +963,7 @@
   /**
    * Retrieves the ldap syntax definitions for this schema, as a
    * mapping between the OID for the syntax and the ldap syntax
-   * defition itself. Each ldap syntax should only be present once,
+   * definition itself. Each ldap syntax should only be present once,
    * since its only key is its OID.  The contents of the returned
    * mapping must not be altered.
    *
@@ -1310,15 +1258,7 @@
             matchingRules.put(toLowerCase(name), matchingRule);
           }
         }
-        // We'll use an attribute value including the normalized value
-        // rather than the attribute type because otherwise it would
-        // use a very expensive matching rule (OID first component
-        // match) that would kill performance.
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.add(
-            AttributeValues.create(rawValue, normValue));
+        matchingRuleSet.add(createAttrValueForAdd(matchingRule));
       }
     }
   }
@@ -1368,28 +1308,7 @@
             matchingRules.remove(toLowerCase(name), matchingRule);
           }
         }
-
-        // We'll use an attribute value including the normalized value
-        // rather than the attribute type because otherwise it would
-        // use a very expensive matching rule (OID first component
-        // match) that would kill performance.
-        try
-        {
-          String valueString = matchingRule.toString();
-          ByteString rawValue = ByteString.valueOf(valueString);
-          ByteString normValue = normalizeAttributeValue(rawValue);
-          matchingRuleSet.remove(AttributeValues.create(rawValue,
-              normValue));
-        }
-        catch (Exception e)
-        {
-          String valueString = matchingRule.toString();
-          ByteString rawValue = ByteString.valueOf(valueString);
-          ByteString normValue =
-              ByteString.valueOf(toLowerCase(valueString));
-          matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                    normValue));
-        }
+        matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
       }
     }
   }
@@ -1503,15 +1422,7 @@
           matchingRules.put(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRule.toString();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleSet.add(AttributeValues.create(rawValue,
-          normValue));
+      matchingRuleSet.add(createAttrValueForAdd(matchingRule));
     }
   }
 
@@ -1542,27 +1453,7 @@
           matchingRules.remove(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
+      matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
     }
   }
 
@@ -1675,15 +1566,7 @@
           matchingRules.put(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRule.toString();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleSet.add(AttributeValues.create(rawValue,
-          normValue));
+      matchingRuleSet.add(createAttrValueForAdd(matchingRule));
     }
   }
 
@@ -1714,28 +1597,7 @@
           matchingRules.remove(name, matchingRule);
         }
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
+      matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
     }
   }
 
@@ -1847,15 +1709,7 @@
           matchingRules.put(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleSet.add(AttributeValues.create(rawValue,
-          normValue));
+      matchingRuleSet.add(createAttrValueForAdd(matchingRule));
     }
   }
 
@@ -1886,27 +1740,7 @@
           matchingRules.remove(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
+      matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
     }
   }
 
@@ -2018,15 +1852,7 @@
           matchingRules.put(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleSet.add(AttributeValues.create(rawValue,
-          normValue));
+      matchingRuleSet.add(createAttrValueForAdd(matchingRule));
     }
   }
 
@@ -2057,27 +1883,7 @@
           matchingRules.remove(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-                                                  normValue));
-      }
+      matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
     }
   }
 
@@ -2195,15 +2001,7 @@
           matchingRules.put(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRule.toString();
-      ByteString rawValue  = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleSet.add(
-          AttributeValues.create(rawValue, normValue));
+      matchingRuleSet.add(createAttrValueForAdd(matchingRule));
     }
   }
 
@@ -2234,27 +2032,7 @@
           matchingRules.remove(name, matchingRule);
         }
       }
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-            normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRule.toString();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleSet.remove(AttributeValues.create(rawValue,
-            normValue));
-      }
+      matchingRuleSet.remove(createAttrValueForRemove(matchingRule));
     }
   }
 
@@ -2364,16 +2142,7 @@
       }
 
       matchingRuleUses.put(matchingRule, matchingRuleUse);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = matchingRuleUse.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      matchingRuleUseSet.add(AttributeValues.create(rawValue,
-          normValue));
+      matchingRuleUseSet.add(createAttrValueForAdd(matchingRuleUse));
     }
   }
 
@@ -2393,28 +2162,7 @@
     {
       matchingRuleUses.remove(matchingRuleUse.getMatchingRule(),
                               matchingRuleUse);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = matchingRuleUse.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        matchingRuleUseSet.remove(AttributeValues.create(rawValue,
-                                                     normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = matchingRuleUse.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        matchingRuleUseSet.remove(AttributeValues.create(rawValue,
-                                                     normValue));
-      }
+      matchingRuleUseSet.remove(createAttrValueForRemove(matchingRuleUse));
     }
   }
 
@@ -2523,16 +2271,7 @@
       }
 
       ditContentRules.put(objectClass, ditContentRule);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = ditContentRule.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      ditContentRuleSet.add(AttributeValues.create(rawValue,
-          normValue));
+      ditContentRuleSet.add(createAttrValueForAdd(ditContentRule));
     }
   }
 
@@ -2551,28 +2290,7 @@
     {
       ditContentRules.remove(ditContentRule.getStructuralClass(),
                              ditContentRule);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = ditContentRule.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        ditContentRuleSet.remove(AttributeValues.create(rawValue,
-                                                    normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = ditContentRule.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        ditContentRuleSet.remove(AttributeValues.create(rawValue,
-                                                    normValue));
-      }
+      ditContentRuleSet.remove(createAttrValueForRemove(ditContentRule));
     }
   }
 
@@ -2750,16 +2468,7 @@
 
       ditStructureRulesByNameForm.put(nameForm, ditStructureRule);
       ditStructureRulesByID.put(ruleID, ditStructureRule);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = ditStructureRule.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      ditStructureRuleSet.add(AttributeValues.create(rawValue,
-                                                 normValue));
+      ditStructureRuleSet.add(createAttrValueForAdd(ditStructureRule));
     }
   }
 
@@ -2781,28 +2490,7 @@
            ditStructureRule.getNameForm(), ditStructureRule);
       ditStructureRulesByID.remove(ditStructureRule.getRuleID(),
                                    ditStructureRule);
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = ditStructureRule.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        ditStructureRuleSet.remove(AttributeValues.create(rawValue,
-                                                      normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = ditStructureRule.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        ditStructureRuleSet.remove(AttributeValues.create(rawValue,
-                                                      normValue));
-      }
+      ditStructureRuleSet.remove(createAttrValueForRemove(ditStructureRule));
     }
   }
 
@@ -3001,15 +2689,7 @@
       {
         nameFormsByName.put(name, nameForm);
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      String valueString = nameForm.getDefinition();
-      ByteString rawValue = ByteString.valueOf(valueString);
-      ByteString normValue = normalizeAttributeValue(rawValue);
-      nameFormSet.add(AttributeValues.create(rawValue, normValue));
+      nameFormSet.add(createAttrValueForAdd(nameForm));
     }
   }
 
@@ -3042,28 +2722,7 @@
       {
         nameFormsByName.remove(name, nameForm);
       }
-
-      // We'll use an attribute value including the normalized value
-      // rather than the attribute type because otherwise it would use
-      // a very expensive matching rule (OID first component match)
-      // that would kill performance.
-      try
-      {
-        String valueString = nameForm.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue = normalizeAttributeValue(rawValue);
-        nameFormSet.remove(AttributeValues.create(rawValue,
-            normValue));
-      }
-      catch (Exception e)
-      {
-        String valueString = nameForm.getDefinition();
-        ByteString rawValue = ByteString.valueOf(valueString);
-        ByteString normValue =
-            ByteString.valueOf(toLowerCase(valueString));
-        nameFormSet.remove(AttributeValues.create(rawValue,
-            normValue));
-      }
+      nameFormSet.remove(createAttrValueForRemove(nameForm));
     }
   }
 
@@ -3186,8 +2845,8 @@
       if (StaticUtils.hasDescriptor(de.getMessageObject(),
           ERR_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE))
       {
-        LocalizableMessage message = ERR_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE.
-            get(element.getDefinition());
+        LocalizableMessage message =
+            ERR_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE.get(element);
         throw new DirectoryException(de.getResultCode(), message,
                                      de);
       }
@@ -3221,10 +2880,8 @@
     {
       // FIXME -- Is this an appropriate maximum depth for detecting
       // circular references?
-      LocalizableMessage message = ERR_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE.get(
-          element.getDefinition());
       throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-                                   message);
+          ERR_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE.get(element));
     }
 
 
@@ -3370,7 +3027,7 @@
   private AttributeType recreateFromDefinition(AttributeType attrType)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(attrType.getDefinition());
+    ByteString value = ByteString.valueOf(attrType.toString());
     AttributeType copy =
         AttributeTypeSyntax.decodeAttributeType(value, this, false);
     setSchemaFile(copy, getSchemaFile(attrType));
@@ -3384,7 +3041,7 @@
   private DITContentRule recreateFromDefinition(DITContentRule dcr)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(dcr.getDefinition());
+    ByteString value = ByteString.valueOf(dcr.toString());
     DITContentRule copy =
         DITContentRuleSyntax.decodeDITContentRule(value, this, false);
     setSchemaFile(copy, getSchemaFile(dcr));
@@ -3394,7 +3051,7 @@
   private DITStructureRule recreateFromDefinition(DITStructureRule dsr)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(dsr.getDefinition());
+    ByteString value = ByteString.valueOf(dsr.toString());
     DITStructureRule copy =
         DITStructureRuleSyntax.decodeDITStructureRule(value, this, false);
     setSchemaFile(copy, getSchemaFile(dsr));
@@ -3404,7 +3061,7 @@
   private MatchingRuleUse recreateFromDefinition(MatchingRuleUse mru)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(mru.getDefinition());
+    ByteString value = ByteString.valueOf(mru.toString());
     MatchingRuleUse copy =
         MatchingRuleUseSyntax.decodeMatchingRuleUse(value, this, false);
     setSchemaFile(copy, getSchemaFile(mru));
@@ -3414,7 +3071,7 @@
   private NameForm recreateFromDefinition(NameForm nf)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(nf.getDefinition());
+    ByteString value = ByteString.valueOf(nf.toString());
     NameForm copy = NameFormSyntax.decodeNameForm(value, this, false);
     setSchemaFile(copy, getSchemaFile(nf));
     return copy;
@@ -3423,7 +3080,7 @@
   private ObjectClass recreateFromDefinition(ObjectClass oc)
       throws DirectoryException
   {
-    ByteString value = ByteString.valueOf(oc.getDefinition());
+    ByteString value = ByteString.valueOf(oc.toString());
     ObjectClass copy = ObjectClassSyntax.decodeObjectClass(value, this, false);
     setSchemaFile(copy, getSchemaFile(oc));
     return copy;
diff --git a/opendj3-server-dev/src/server/org/opends/server/types/SchemaFileElement.java b/opendj3-server-dev/src/server/org/opends/server/types/SchemaFileElement.java
index 71132c6..87f68c3 100644
--- a/opendj3-server-dev/src/server/org/opends/server/types/SchemaFileElement.java
+++ b/opendj3-server-dev/src/server/org/opends/server/types/SchemaFileElement.java
@@ -66,13 +66,4 @@
    */
   Map<String, List<String>> getExtraProperties();
 
-  /**
-   * Retrieves the definition string that is used to represent this
-   * element in the schema configuration file.
-   *
-   * @return  The definition string that should be used to represent
-   *          this element in the schema configuration file.
-   */
-  public String getDefinition();
-
 }
diff --git a/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestAttributeType.java b/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestAttributeType.java
index 187eec6..bb07eb2 100644
--- a/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestAttributeType.java
+++ b/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestAttributeType.java
@@ -27,19 +27,18 @@
 package org.opends.server.types;
 
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
 import org.forgerock.opendj.ldap.schema.AttributeUsage;
+import org.forgerock.util.Utils;
 import org.opends.server.api.ApproximateMatchingRule;
 import org.opends.server.api.AttributeSyntax;
 import org.opends.server.api.EqualityMatchingRule;
 import org.opends.server.api.OrderingMatchingRule;
 import org.opends.server.api.SubstringMatchingRule;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.util.ServerConstants;
 import org.testng.Assert;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -151,33 +150,22 @@
 
       if (names != null)
       {
-        for (String name : names)
-        {
-          nameSet.add(name);
-        }
+        nameSet.addAll(names);
       }
 
       if (! nameSet.isEmpty())
       {
+        definition.append(" NAME ");
         if (nameSet.size() == 1)
         {
-          definition.append(" NAME '");
+          definition.append("'");
           definition.append(nameSet.iterator().next());
           definition.append("'");
         }
         else
         {
-          Iterator<String> iterator = nameSet.iterator();
-
-          definition.append(" NAME ( '");
-          definition.append(iterator.next());
-
-          while (iterator.hasNext())
-          {
-            definition.append("' '");
-            definition.append(iterator.next());
-          }
-
+          definition.append("( '");
+          definition.append(Utils.joinAsString("' '", nameSet));
           definition.append("' )");
         }
       }
@@ -242,7 +230,7 @@
       if (attributeUsage != null)
       {
         definition.append(" USAGE ");
-        definition.append(attributeUsage.toString());
+        definition.append(attributeUsage);
       }
 
       if (extraProperties != null)
@@ -785,56 +773,6 @@
     Assert.assertEquals(type.isOperational(), result);
   }
 
-
-
-  /**
-   * Check that the {@link AttributeType#toString()} method.
-   *
-   * @throws Exception
-   *           If the test failed unexpectedly.
-   */
-  @Test
-  public void testToStringDefault() throws Exception {
-    AttributeTypeBuilder builder = new AttributeTypeBuilder(null,
-        "1.2.3");
-    AttributeType type = builder.getInstance();
-    Assert.assertEquals(type.toString(), "( 1.2.3 "
-        + "EQUALITY caseIgnoreMatch "
-        + "ORDERING caseIgnoreOrderingMatch "
-        + "SUBSTR caseIgnoreSubstringsMatch "
-        + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
-        + "USAGE userApplications )");
-  }
-
-
-
-  /**
-   * Check that the {@link AttributeType#toString()} method.
-   *
-   * @throws Exception
-   *           If the test failed unexpectedly.
-   */
-  @Test
-  public void testToString() throws Exception {
-    AttributeTypeBuilder builder = new AttributeTypeBuilder(
-        "testType", "1.2.3");
-    builder.addTypeNames("anotherName");
-    builder.setAttributeUsage(AttributeUsage.DIRECTORY_OPERATION);
-    builder.setSingleValue(true);
-    builder.setSyntax(DirectoryServer.getDefaultBooleanSyntax());
-    builder.addExtraProperty(
-        ServerConstants.SCHEMA_PROPERTY_FILENAME, "/foo/bar");
-
-    AttributeType type = builder.getInstance();
-    Assert.assertEquals(type.toString(), "( 1.2.3 "
-        + "NAME ( 'testType' 'anotherName' ) "
-        + "EQUALITY booleanMatch "
-        + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 " + "SINGLE-VALUE "
-        + "USAGE directoryOperation " + "X-SCHEMA-FILE '/foo/bar' )");
-  }
-
-
-
   /**
    * {@inheritDoc}
    */
diff --git a/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestObjectClass.java b/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestObjectClass.java
index 8becac9..1cec884 100644
--- a/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestObjectClass.java
+++ b/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/TestObjectClass.java
@@ -36,9 +36,9 @@
 import java.util.Set;
 
 import org.forgerock.opendj.ldap.schema.ObjectClassType;
+import org.forgerock.util.Utils;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.schema.SchemaConstants;
-import org.opends.server.util.ServerConstants;
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
@@ -125,33 +125,22 @@
 
       if (names != null)
       {
-        for (String name : names)
-        {
-          nameSet.add(name);
-        }
+        nameSet.addAll(names);
       }
 
       if (! nameSet.isEmpty())
       {
+        definition.append(" NAME ");
         if (nameSet.size() == 1)
         {
-          definition.append(" NAME '");
+          definition.append("'");
           definition.append(nameSet.iterator().next());
           definition.append("'");
         }
         else
         {
-          Iterator<String> iterator = nameSet.iterator();
-
-          definition.append(" NAME ( '");
-          definition.append(iterator.next());
-
-          while (iterator.hasNext())
-          {
-            definition.append("' '");
-            definition.append(iterator.next());
-          }
-
+          definition.append("( '");
+          definition.append(Utils.joinAsString("' '", nameSet));
           definition.append("' )");
         }
       }
@@ -196,56 +185,11 @@
       if (objectClassType != null)
       {
         definition.append(" ");
-        definition.append(objectClassType.toString());
+        definition.append(objectClassType);
       }
 
-      if ((requiredAttributeTypes != null) &&
-          (! requiredAttributeTypes.isEmpty()))
-      {
-        if (requiredAttributeTypes.size() == 1)
-        {
-          definition.append(" MUST ");
-          definition.append(
-               requiredAttributeTypes.iterator().next().getNameOrOID());
-        }
-        else
-        {
-          Iterator<AttributeType> iterator = requiredAttributeTypes.iterator();
-
-          definition.append(" MUST ( ");
-          definition.append(iterator.next().getNameOrOID());
-          while (iterator.hasNext())
-          {
-            definition.append(" $ ");
-            definition.append(iterator.next().getNameOrOID());
-          }
-          definition.append(" )");
-        }
-      }
-
-      if ((optionalAttributeTypes != null) &&
-          (! optionalAttributeTypes.isEmpty()))
-      {
-        if (optionalAttributeTypes.size() == 1)
-        {
-          definition.append(" MUST ");
-          definition.append(
-               optionalAttributeTypes.iterator().next().getNameOrOID());
-        }
-        else
-        {
-          Iterator<AttributeType> iterator = optionalAttributeTypes.iterator();
-
-          definition.append(" MUST ( ");
-          definition.append(iterator.next().getNameOrOID());
-          while (iterator.hasNext())
-          {
-            definition.append(" $ ");
-            definition.append(iterator.next().getNameOrOID());
-          }
-          definition.append(" )");
-        }
-      }
+      append(definition, "MUST", requiredAttributeTypes);
+      append(definition, "MAY", optionalAttributeTypes);
 
       if (extraProperties != null)
       {
@@ -293,6 +237,35 @@
 
 
 
+    private void append(StringBuilder definition, String word,
+        Set<AttributeType> attrTypes)
+    {
+      if ((attrTypes != null) && (!attrTypes.isEmpty()))
+      {
+        definition.append(" ");
+        definition.append(word);
+        definition.append(" ");
+        if (attrTypes.size() == 1)
+        {
+          definition.append(attrTypes.iterator().next().getNameOrOID());
+        }
+        else
+        {
+          definition.append("( ");
+          Iterator<AttributeType> iterator = attrTypes.iterator();
+          definition.append(iterator.next().getNameOrOID());
+          while (iterator.hasNext())
+          {
+            definition.append(" $ ");
+            definition.append(iterator.next().getNameOrOID());
+          }
+          definition.append(" )");
+        }
+      }
+    }
+
+
+
     /**
      * Set the objectClassType.
      *
@@ -1571,55 +1544,6 @@
     Assert.assertTrue(c.isRequiredOrOptional(types[1]));
   }
 
-
-
-  /**
-   * Check the {@link ObjectClass#toString()} method.
-   *
-   * @throws Exception
-   *           If the test failed unexpectedly.
-   */
-  @Test
-  public void testToStringDefault() throws Exception {
-    ObjectClassBuilder builder = new ObjectClassBuilder(null, "1.2.3");
-    ObjectClass type = builder.getInstance();
-    Assert.assertEquals(type.toString(), "( 1.2.3 STRUCTURAL )");
-  }
-
-
-
-  /**
-   * Check the {@link ObjectClass#toString()} method.
-   *
-   * @throws Exception
-   *           If the test failed unexpectedly.
-   */
-  @Test
-  public void testToString() throws Exception {
-    ObjectClassBuilder builder = new ObjectClassBuilder(
-        "parentClass", "1.2.1");
-    ObjectClass parent = builder.getInstance();
-
-    builder = new ObjectClassBuilder("childClass", "1.2.2");
-    builder.addTypeNames("anotherName");
-    builder.setDescription("A description");
-    builder.setObjectClassType(ObjectClassType.ABSTRACT);
-    builder.setObsolete(true);
-    builder.setSuperior(Collections.singleton(parent));
-    builder.addRequiredAttributeTypes(types[0], types[1], types[2]);
-    builder.addOptionalAttributeTypes(types[3]);
-    builder.addExtraProperty(
-        ServerConstants.SCHEMA_PROPERTY_FILENAME, "/foo/bar");
-    ObjectClass type = builder.getInstance();
-    Assert.assertEquals(type.toString(), "( 1.2.2 "
-        + "NAME ( 'childClass' 'anotherName' ) "
-        + "DESC 'A description' " + "OBSOLETE " + "SUP parentClass "
-        + "ABSTRACT " + "MUST ( testType0 $ testType1 $ testType2 ) "
-        + "MAY testType3 " + "X-SCHEMA-FILE '/foo/bar' )");
-  }
-
-
-
   /**
    * Create test data for testing different combinations of superiors.
    *

--
Gitblit v1.10.0