From d9df9288eaa3a66fb29fd4ab649d4c2ef886445c Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Mon, 30 May 2016 10:43:13 +0000
Subject: [PATCH] OPENDJ-2987 Address all changes suggested in PR 510

---
 opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java    |  299 ++++++++++---------------------------
 opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java         |   17 --
 opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java       |   32 ----
 opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java |    2 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java         |    4 
 opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java   |    2 
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeType.java          |   10 +
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java            |   54 +++++-
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/Schema.java                 |   32 ++-
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java          |    3 
 10 files changed, 154 insertions(+), 301 deletions(-)

diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeType.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeType.java
index 23cae5d..8918f6e 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeType.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeType.java
@@ -454,7 +454,15 @@
      * @param equalityMatchingRule
      *            The equality matching rule of the place-holder attribute type.
      */
-    AttributeType(final String name, final Syntax syntax, final MatchingRule equalityMatchingRule) {
+    static AttributeType newPlaceHolder(final String name, final Syntax syntax,
+            final MatchingRule equalityMatchingRule) {
+        return new AttributeType(name, syntax, equalityMatchingRule);
+    }
+
+    /**
+     * Creates a new place-holder attribute type having the specified name, default syntax, and default matching rule.
+     */
+    private AttributeType(final String name, final Syntax syntax, final MatchingRule equalityMatchingRule) {
         final StringBuilder builder = new StringBuilder(name.length() + 4);
         StaticUtils.toLowerCase(name, builder);
         builder.append("-oid");
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
index 529d85a..714ad4f 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
@@ -770,7 +770,7 @@
         // or is not structural, then fail.
         if (structuralClassOID != null) {
             try {
-                structuralClass = schema.asStrictSchema().getObjectClass(structuralClassOID);
+                structuralClass = schema.getObjectClass(structuralClassOID);
             } catch (final UnknownSchemaElementException e) {
                 final LocalizableMessage message =
                         ERR_ATTR_SYNTAX_DCR_UNKNOWN_STRUCTURAL_CLASS1.get(getNameOrOID(),
@@ -791,7 +791,7 @@
             ObjectClass objectClass;
             for (final String oid : auxiliaryClassOIDs) {
                 try {
-                    objectClass = schema.asStrictSchema().getObjectClass(oid);
+                    objectClass = schema.getObjectClass(oid);
                 } catch (final UnknownSchemaElementException e) {
                     // This isn't good because it is an unknown auxiliary class.
                     final LocalizableMessage message =
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
index ffae27c..f4f3451 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
@@ -401,6 +401,16 @@
     /** Indicates whether validation failed. */
     private boolean isValid;
 
+    /**
+     * Indicates whether this object class is a placeholder.
+     * <p>
+     * A placeholder objectclass is returned by a non-strict schema when the requested
+     * object class does not exist in the schema. The placeholder is not registered to
+     * the schema.
+     * It is defined as an abstract object class, with no optional or required attribute.
+     * <p>
+     * A strict schema never returns a placeholder: it throws an UnknownSchemaElementException.
+     */
     private boolean isPlaceHolder;
 
     /** Indicates whether this object class is the extensibleObject class. */
@@ -426,6 +436,20 @@
                .type(AUXILIARY));
     }
 
+    /**
+     * Creates a new place-holder object class having the specified name.
+     * <p>
+     * A place-holder object class is never registered to a schema.
+     * <p>
+     * The OID of the place-holder object class will be the normalized object
+     * class name followed by the suffix "-oid".
+     *
+     * @param name
+     *            The name of the place-holder object class.
+     */
+    static ObjectClass newPlaceHolder(String name) {
+        return new ObjectClass(name);
+    }
 
     private ObjectClass(final Builder builder) {
         super(builder);
@@ -453,7 +477,7 @@
      * @param name
      *            The name of the place-holder object class.
      */
-    ObjectClass(final String name) {
+    private ObjectClass(final String name) {
         this.oid = toOID(name);
         this.names = Collections.singletonList(name);
         this.isObsolete = false;
@@ -849,7 +873,7 @@
             ObjectClass superiorClass;
             for (final String superClassOid : superiorClassOIDs) {
                 try {
-                    superiorClass = schema.asStrictSchema().getObjectClass(superClassOid);
+                    superiorClass = schema.getObjectClass(superClassOid);
                 } catch (final UnknownSchemaElementException e) {
                     final LocalizableMessage message =
                             WARN_ATTR_SYNTAX_OBJECTCLASS_UNKNOWN_SUPERIOR_CLASS1.get(
@@ -920,21 +944,23 @@
                 }
 
                 // Inherit all required attributes from superior class.
-                Iterator<AttributeType> i = superiorClass.getRequiredAttributes().iterator();
-                if (i.hasNext() && requiredAttributes == Collections.EMPTY_SET) {
-                    requiredAttributes = new HashSet<>();
-                }
-                while (i.hasNext()) {
-                    requiredAttributes.add(i.next());
+                final Set<AttributeType> supRequiredAttrs = superiorClass.getRequiredAttributes();
+                if (!supRequiredAttrs.isEmpty()) {
+                    if (requiredAttributes == Collections.EMPTY_SET) {
+                        requiredAttributes = new HashSet<>(supRequiredAttrs);
+                    } else {
+                        requiredAttributes.addAll(supRequiredAttrs);
+                    }
                 }
 
                 // Inherit all optional attributes from superior class.
-                i = superiorClass.getOptionalAttributes().iterator();
-                if (i.hasNext() && optionalAttributes == Collections.EMPTY_SET) {
-                    optionalAttributes = new HashSet<>();
-                }
-                while (i.hasNext()) {
-                    optionalAttributes.add(i.next());
+                final Set<AttributeType> supOptionalAttrs = superiorClass.getOptionalAttributes();
+                if (!supOptionalAttrs.isEmpty()) {
+                    if (optionalAttributes == Collections.EMPTY_SET) {
+                        optionalAttributes = new HashSet<>(supOptionalAttrs);
+                    } else {
+                        optionalAttributes.addAll(supOptionalAttrs);
+                    }
                 }
 
                 superiorClasses.add(superiorClass);
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/Schema.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/Schema.java
index 8506b74..b019ade 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/Schema.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/Schema.java
@@ -206,7 +206,7 @@
 
         private AttributeType getAttributeType0(String nameOrOid, Syntax syntax, MatchingRule equalityMatchingRule) {
             final AttributeType type = strictImpl.getAttributeType0(nameOrOid);
-            return type != null ? type : new AttributeType(nameOrOid, syntax, equalityMatchingRule);
+            return type != null ? type : AttributeType.newPlaceHolder(nameOrOid, syntax, equalityMatchingRule);
         }
 
         @Override
@@ -317,7 +317,7 @@
         @Override
         public ObjectClass getObjectClass(final String nameOrOid) {
             ObjectClass result = strictImpl.getObjectClass0(nameOrOid);
-            return result != null ? result : new ObjectClass(nameOrOid);
+            return result != null ? result : ObjectClass.newPlaceHolder(nameOrOid);
         }
 
         @Override
@@ -504,27 +504,37 @@
 
         @Override
         public String getOIDForName(String lowerCaseName) {
-            final String oid = getOIDForName0(lowerCaseName);
-            return oid != null ? toLowerCase(oid) : null;
-        }
-
-        private String getOIDForName0(String lowerName) {
-            AttributeType attributeType = getAttributeType0(lowerName);
+            AttributeType attributeType = getAttributeType0(lowerCaseName);
             if (attributeType != null) {
                 return attributeType.getOID();
             }
             try {
-                return getObjectClass(lowerName).getOID();
+                return getObjectClass(lowerCaseName).getOID();
             } catch (UnknownSchemaElementException ignore) {
                 // try next schema element
             }
             try {
-                return getMatchingRule(lowerName).getOID();
+                return getSyntax(null, lowerCaseName).getOID();
             } catch (UnknownSchemaElementException ignore) {
                 // try next schema element
             }
             try {
-                return getNameForm(lowerName).getOID();
+                return getMatchingRule(lowerCaseName).getOID();
+            } catch (UnknownSchemaElementException ignore) {
+                // try next schema element
+            }
+            try {
+                return getNameForm(lowerCaseName).getOID();
+            } catch (UnknownSchemaElementException ignore) {
+                // try next schema element
+            }
+            try {
+                return getDITContentRule(lowerCaseName).getStructuralClassOID();
+            } catch (UnknownSchemaElementException ignore) {
+                // try next schema element
+            }
+            try {
+                return getMatchingRuleUse(lowerCaseName).getMatchingRuleOID();
             } catch (UnknownSchemaElementException ignore) {
                 // try next schema element
             }
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
index 7d48981..a4203a3 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
@@ -1343,9 +1343,6 @@
             }
 
             ocType = ocType != null ? ocType : STRUCTURAL;
-            if (ocType == STRUCTURAL && superiorClasses.isEmpty()) {
-                superiorClasses = singleton(TOP_OBJECTCLASS_NAME);
-            }
             ocBuilder.superiorObjectClasses(superiorClasses)
                      .type(ocType);
             return ocBuilder.addToSchema(overwrite);
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
index 8c923a7..035df63 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
@@ -123,12 +123,13 @@
     }
 
     @Test
-    public void testGetOptionalAttributesNoSuperiorEmpty() throws Exception {
+    public void testGetOptionalAttributesNoSuperiorNoAttribute() throws Exception {
         final ObjectClass.Builder ocBuilder = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3")
             .names("testType");
         ObjectClass oc = ocBuilder.addToSchema().toSchema().getObjectClass("1.2.3");
         assertThat(oc.getOptionalAttributes()).isEmpty();
+        assertThat(oc.getDeclaredOptionalAttributes()).isEmpty();
     }
 
     @Test
@@ -140,44 +141,43 @@
             .optionalAttributes("at1", "at2", "at3")
             .addToSchema().toSchema().getObjectClass("1.2.3");
 
-        Set<AttributeType> attributes = oc.getOptionalAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at1", "at2", "at3"));
+        assertThat(oc.getOptionalAttributes()).containsOnly(attrs(schema, "at1", "at2", "at3"));
+        assertThat(oc.getDeclaredOptionalAttributes()).containsOnly((attrs(schema, "at1", "at2", "at3")));
+
     }
 
     @Test
-    public void testGetOptionalAttributeOneSuperiorEmpty() throws Exception {
+    public void testGetOptionalAttributeOneSuperiorNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getOptionalAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at1", "at2", "at3"));
+        assertThat(child.getOptionalAttributes()).containsOnly(attrs(schema, "at1", "at2", "at3"));
+        assertThat(child.getDeclaredOptionalAttributes()).isEmpty();
+
     }
 
     @Test
-    public void testGetOptionalAttributeMultipleSuperiorsEmpty() throws Exception {
+    public void testGetOptionalAttributeMultipleSuperiorsNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent1")
             .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
             .optionalAttributes("at4", "at5", "at6")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("child")
             .superiorObjectClasses("parent1", "parent2")
@@ -194,9 +194,8 @@
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .optionalAttributes("at4", "at5", "at6")
@@ -204,8 +203,8 @@
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getOptionalAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6"));
+        assertThat(child.getOptionalAttributes()).containsOnly(attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6"));
+        assertThat(child.getDeclaredOptionalAttributes()).containsOnly((attrs(schema, "at4", "at5", "at6")));
     }
 
     @Test
@@ -214,15 +213,13 @@
             .buildObjectClass("1.2.3.1")
             .names("parent1")
             .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
             .optionalAttributes("at4", "at5", "at6")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("child")
             .optionalAttributes("at7", "at8", "at9")
@@ -230,78 +227,19 @@
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getOptionalAttributes();
-        assertThat(attributes).containsOnly(
+        assertThat(child.getOptionalAttributes()).containsOnly(
                 attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6", "at7", "at8", "at9"));
+        assertThat(child.getDeclaredOptionalAttributes()).containsOnly((attrs(schema, "at7", "at8", "at9")));
     }
 
     @Test
-    public void testGetDeclaredOptionalAttributesNoSuperiorEmpty() throws Exception {
-        final ObjectClass.Builder ocBuilder = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3")
-            .names("testType");
-        ObjectClass oc = ocBuilder.addToSchema().toSchema().getObjectClass("1.2.3");
-        assertThat(oc.getDeclaredOptionalAttributes()).isEmpty();
-    }
-
-    @Test
-    public void testGetDeclaredOptionalAttributesNoSuperior() throws Exception {
-        Schema schema = schema();
-        ObjectClass oc = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3")
-            .names("testType")
-            .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema().getObjectClass("1.2.3");
-
-        Set<AttributeType> attributes = oc.getDeclaredOptionalAttributes();
-        assertThat(attributes).containsOnly((attrs(schema, "at1", "at2", "at3")));
-    }
-
-    @Test
-    public void testGetDeclaredOptionalAttributeOneSuperiorEmpty() throws Exception {
-        Schema schema = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3.1")
-            .names("parent")
-            .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
-
-        schema = new SchemaBuilder(schema)
-            .buildObjectClass("1.2.3.2")
-            .names("child")
-            .superiorObjectClasses("parent")
-            .addToSchema().toSchema();
-        ObjectClass child = schema.getObjectClass("child");
-
-        assertThat(child.getDeclaredOptionalAttributes()).isEmpty();
-    }
-
-    @Test
-    public void testGetDeclaredOptionalAttributeOneSuperior() throws Exception {
-        Schema schema = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3.1")
-            .names("parent")
-            .optionalAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
-
-        schema = new SchemaBuilder(schema)
-            .buildObjectClass("1.2.3.2")
-            .names("child")
-            .optionalAttributes("at4", "at5", "at6")
-            .superiorObjectClasses("parent")
-            .addToSchema().toSchema();
-        ObjectClass child = schema.getObjectClass("child");
-
-        Set<AttributeType> attributes = child.getDeclaredOptionalAttributes();
-        assertThat(attributes).containsOnly((attrs(schema, "at4", "at5", "at6")));
-    }
-
-    @Test
-    public void testGetRequiredAttributesNoSuperiorEmpty() throws Exception {
+    public void testGetRequiredAttributesNoSuperiorNoAttribute() throws Exception {
         final ObjectClass.Builder ocBuilder = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3")
             .names("testType");
         ObjectClass oc = ocBuilder.addToSchema().toSchema().getObjectClass("1.2.3");
         assertThat(oc.getRequiredAttributes()).isEmpty();
+        assertThat(oc.getDeclaredRequiredAttributes()).isEmpty();
     }
 
     @Test
@@ -313,52 +251,50 @@
             .requiredAttributes("at1", "at2", "at3")
             .addToSchema().toSchema().getObjectClass("1.2.3");
 
-        Set<AttributeType> attributes = oc.getRequiredAttributes();
-        assertThat(attributes).containsOnly((attrs(schema, "at1", "at2", "at3")));
+        assertThat(oc.getRequiredAttributes()).containsOnly((attrs(schema, "at1", "at2", "at3")));
+        assertThat(oc.getDeclaredRequiredAttributes()).containsOnly((attrs(schema, "at1", "at2", "at3")));
     }
 
     @Test
-    public void testGetRequiredAttributeOneSuperiorEmpty() throws Exception {
+    public void testGetRequiredAttributeOneSuperiorNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getRequiredAttributes();
-        assertThat(attributes).containsOnly((attrs(schema, "at1", "at2", "at3")));
+        assertThat(child.getRequiredAttributes()).containsOnly((attrs(schema, "at1", "at2", "at3")));
+        assertThat(child.getDeclaredRequiredAttributes()).isEmpty();
     }
 
     @Test
-    public void testGetRequiredAttributeMultipleSuperiorsEmpty() throws Exception {
+    public void testGetRequiredAttributeMultipleSuperiorsNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent1")
             .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
             .requiredAttributes("at4", "at5", "at6")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("child")
             .superiorObjectClasses("parent1", "parent2")
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getRequiredAttributes();
-        assertThat(attributes).containsOnly((attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6")));
+        assertThat(child.getRequiredAttributes()).containsOnly(
+                (attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6")));
+        assertThat(child.getDeclaredRequiredAttributes()).isEmpty();
     }
 
     @Test
@@ -367,9 +303,8 @@
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .requiredAttributes("at4", "at5", "at6")
@@ -377,8 +312,8 @@
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getRequiredAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6"));
+        assertThat(child.getRequiredAttributes()).containsOnly(attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6"));
+        assertThat(child.getDeclaredRequiredAttributes()).containsOnly(attrs(schema, "at4", "at5", "at6"));
     }
 
     @Test
@@ -387,15 +322,13 @@
             .buildObjectClass("1.2.3.1")
             .names("parent1")
             .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
             .requiredAttributes("at4", "at5", "at6")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("child")
             .requiredAttributes("at7", "at8", "at9")
@@ -403,69 +336,9 @@
             .addToSchema().toSchema();
         ObjectClass child = schema.getObjectClass("child");
 
-        Set<AttributeType> attributes = child.getRequiredAttributes();
-        assertThat(attributes).containsOnly(
+        assertThat(child.getRequiredAttributes()).containsOnly(
                 attrs(schema, "at1", "at2", "at3", "at4", "at5", "at6", "at7", "at8", "at9"));
-    }
-
-    @Test
-    public void testGetDeclaredRequiredAttributesNoSuperiorEmpty() throws Exception {
-        final ObjectClass.Builder ocBuilder = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3")
-            .names("testType");
-        ObjectClass oc = ocBuilder.addToSchema().toSchema().getObjectClass("1.2.3");
-        assertThat(oc.getDeclaredRequiredAttributes()).isEmpty();
-    }
-
-    @Test
-    public void testGetDeclaredRequiredAttributesNoSuperior() throws Exception {
-        Schema schema = schema();
-        ObjectClass oc = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3")
-            .names("testType")
-            .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema().getObjectClass("1.2.3");
-
-        Set<AttributeType> attributes = oc.getDeclaredRequiredAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at1", "at2", "at3"));
-    }
-
-    @Test
-    public void testGetDeclaredRequiredAttributeOneSuperiorEmpty() throws Exception {
-        Schema schema = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3.1")
-            .names("parent")
-            .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
-
-        schema = new SchemaBuilder(schema)
-            .buildObjectClass("1.2.3.2")
-            .names("child")
-            .superiorObjectClasses("parent")
-            .addToSchema().toSchema();
-        ObjectClass child = schema.getObjectClass("child");
-
-        assertThat(child.getDeclaredRequiredAttributes()).isEmpty();
-    }
-
-    @Test
-    public void testGetDeclaredRequiredAttributeOneSuperior() throws Exception {
-        Schema schema = new SchemaBuilder(schema())
-            .buildObjectClass("1.2.3.1")
-            .names("parent")
-            .requiredAttributes("at1", "at2", "at3")
-            .addToSchema().toSchema();
-
-        schema = new SchemaBuilder(schema)
-            .buildObjectClass("1.2.3.2")
-            .names("child")
-            .requiredAttributes("at4", "at5", "at6")
-            .superiorObjectClasses("parent")
-            .addToSchema().toSchema();
-        ObjectClass child = schema.getObjectClass("child");
-
-        Set<AttributeType> attributes = child.getDeclaredRequiredAttributes();
-        assertThat(attributes).containsOnly(attrs(schema, "at4", "at5", "at6"));
+        assertThat(child.getDeclaredRequiredAttributes()).containsOnly(attrs(schema, "at7", "at8", "at9"));
     }
 
     @Test
@@ -476,10 +349,12 @@
             .names("testType")
             .addToSchema().toSchema().getObjectClass("1.2.3");
 
-        // top should be added to superior classes
-        assertThat(oc.getSuperiorClasses()).containsOnly(schema.getObjectClass(TOP_OBJECTCLASS_OID));
-        // toString() should return the initial definition, without top
-        assertThat(oc.toString()).isEqualTo("( 1.2.3 NAME 'testType' )");
+        assertThat(oc.getSuperiorClasses())
+            .as("\"top\" should be added to superior classes for STRUCTURAL object classes")
+            .containsOnly(schema.getObjectClass(TOP_OBJECTCLASS_OID));
+        assertThat(oc.toString())
+            .as("toString() should return the initial definition, without top")
+            .isEqualTo("( 1.2.3 NAME 'testType' )");
     }
 
     @Test
@@ -487,9 +362,8 @@
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
@@ -505,14 +379,12 @@
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent1")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("child")
             .superiorObjectClasses("parent1", "parent2")
@@ -523,12 +395,12 @@
     }
 
     @Test
-    public void testIsDescendantOfNoSuperior() throws Exception {
+    public void testStructuralIsDescendantOfTopDespiteNoSuperiorDeclared() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("testType1")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.2")
             .names("testType2")
             .addToSchema().toSchema();
@@ -544,13 +416,13 @@
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("grandParent")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.2")
             .names("parent")
             .superiorObjectClasses("grandParent")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.3")
             .names("child")
             .superiorObjectClasses("parent")
@@ -573,17 +445,17 @@
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("grandParent")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.2")
             .names("parent1")
             .superiorObjectClasses("grandParent")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.3")
             .names("parent2")
-            .addToSchema().toSchema();
-        schema = new SchemaBuilder(schema)
+            .addToSchema()
+
             .buildObjectClass("1.2.3.4")
             .names("child")
             .superiorObjectClasses("parent1", "parent2")
@@ -606,7 +478,7 @@
     }
 
     @Test
-    public void testIsOptionalEmpty() throws Exception {
+    public void testIsOptionalNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("testType")
@@ -630,14 +502,13 @@
     }
 
     @Test
-    public void testIsOptionalEmptyWithOneSuperior() throws Exception {
+    public void testIsOptionalNoAttributeWithOneSuperior() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .optionalAttributes("at1")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
@@ -654,9 +525,8 @@
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .optionalAttributes("at1")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .optionalAttributes("at2")
@@ -679,7 +549,7 @@
     }
 
     @Test
-    public void testIsRequiredEmpty() throws Exception {
+    public void testIsRequiredNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("testType")
@@ -703,14 +573,13 @@
     }
 
     @Test
-    public void testIsRequiredEmptyWithOneSuperior() throws Exception {
+    public void testIsRequiredNoAttributeWithOneSuperior() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .requiredAttributes("at1")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
@@ -727,9 +596,8 @@
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .requiredAttributes("at1")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .requiredAttributes("at2")
@@ -743,7 +611,7 @@
     }
 
     @Test
-    public void testIsRequiredOrOptionalEmpty() throws Exception {
+    public void testIsRequiredOrOptionalNoAttribute() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("testType")
@@ -769,15 +637,14 @@
     }
 
     @Test
-    public void testIsRequiredOrOptionalEmptyWithOneSuperior() throws Exception {
+    public void testIsRequiredOrOptionalNoAttributeWithOneSuperior() throws Exception {
         Schema schema = new SchemaBuilder(schema())
             .buildObjectClass("1.2.3.1")
             .names("parent")
             .requiredAttributes("at1")
             .optionalAttributes("at2")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .superiorObjectClasses("parent")
@@ -796,9 +663,8 @@
             .names("parent")
             .requiredAttributes("at1")
             .optionalAttributes("at2")
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("child")
             .requiredAttributes("at3")
@@ -830,33 +696,28 @@
             .buildObjectClass("1.2.3.1")
             .names("parent1")
             .type(ObjectClassType.ABSTRACT)
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.2")
             .names("parent2")
             .type(ObjectClassType.ABSTRACT)
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.3")
             .names("parent3")
             .type(ObjectClassType.STRUCTURAL)
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.4")
             .names("parent4")
             .type(ObjectClassType.STRUCTURAL)
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.5")
             .names("parent5")
             .type(ObjectClassType.AUXILIARY)
-            .addToSchema().toSchema();
+            .addToSchema()
 
-        schema = new SchemaBuilder(schema)
             .buildObjectClass("1.2.3.6")
             .names("parent6")
             .type(ObjectClassType.AUXILIARY)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index baa74a6..242eada 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -49,7 +49,6 @@
 import java.util.TreeSet;
 
 import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.config.server.ConfigChangeResult;
 import org.forgerock.opendj.config.server.ConfigException;
@@ -3426,8 +3425,6 @@
           continue;
         }
 
-        // Now we know we are not in the config schema, let's check the unknown elements ...
-        validateNoUnknownElements(newObjectClass);
         oidList.add(newObjectClass.getOID());
         try
         {
@@ -3483,35 +3480,6 @@
     }
   }
 
-  private void validateNoUnknownElements(ObjectClass oc) throws DirectoryException
-  {
-    validateNoUnknownElements(oc.getDeclaredOptionalAttributes(), oc.getOID(),
-        WARN_ATTR_SYNTAX_OBJECTCLASS_UNKNOWN_OPTIONAL_ATTR);
-    validateNoUnknownElements(oc.getDeclaredRequiredAttributes(), oc.getOID(),
-        WARN_ATTR_SYNTAX_OBJECTCLASS_UNKNOWN_REQUIRED_ATTR);
-    for (ObjectClass superiorClass : oc.getSuperiorClasses())
-    {
-      if (superiorClass.isPlaceHolder())
-      {
-        LocalizableMessage message =
-            WARN_ATTR_SYNTAX_OBJECTCLASS_UNKNOWN_SUPERIOR_CLASS.get(oc.getOID(), superiorClass.getOID());
-        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
-      }
-    }
-  }
-
-  private void validateNoUnknownElements(Set<AttributeType> attributeTypes, String oid, Arg2<Object, Object> msg)
-      throws DirectoryException
-  {
-    for (AttributeType attributeType : attributeTypes)
-    {
-      if (attributeType.isPlaceHolder())
-      {
-        throw new DirectoryException(CONSTRAINT_VIOLATION, msg.get(oid, attributeType.getOID()));
-      }
-    }
-  }
-
   @Override
   public void createBackup(BackupConfig backupConfig) throws DirectoryException
   {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index 5659e33..641aaf8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -2429,23 +2429,6 @@
   }
 
   /**
-   * Causes the Directory Server to construct a new objectclass
-   * definition with the provided name and with no required or allowed
-   * attributes. This should only be used if there is no objectclass
-   * for the specified name. It will not register the created
-   * objectclass with the Directory Server.
-   *
-   * @param name
-   *          The name to use for the objectclass, as provided by the
-   *          user.
-   * @return The constructed objectclass definition.
-   */
-  public static ObjectClass getDefaultObjectClass(String name)
-  {
-    return directoryServer.schema.getSchemaNG().getObjectClass(name);
-  }
-
-  /**
    * Retrieves the set of attribute type definitions that have been
    * defined in the Directory Server.
    *
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
index 7fe718f..98162f1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
@@ -34,7 +34,7 @@
  * for a SchemaElement.
  * <p>
  * Note that {@code setSchemaFile()} method works ONLY for non-SDK classes, because SDK schema
- * elements are immutable, so modifying the map fo extra properties has no effect on the actual
+ * elements are immutable, so modifying the map for extra properties has no effect on the actual
  * element.
  */
 @RemoveOnceSDKSchemaIsUsed("All read methods can be provided by ServerSchemaElement class. Write method" +
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java
index e67153b..6cf7860 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/schema/GenericSchemaTestCase.java
@@ -261,7 +261,7 @@
     if (! invalidOIDs.isEmpty())
     {
       StringBuilder message = new StringBuilder()
-          .append("All object classes defined in OpenDS must have valid OIDs assigned.").append(EOL)
+          .append("All object classes defined in OpenDJ must have valid OIDs assigned.").append(EOL)
           .append("Object classes without valid OIDs:").append(EOL);
       for (String s : invalidOIDs)
       {

--
Gitblit v1.10.0