From 4b31a35ca148d08a0c89ebbcbb51edeb3ba411b9 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 25 Jan 2007 01:59:52 +0000
Subject: [PATCH] Make a number of updates to schema processing, all of which fall under the umbrella of issue #1163.  The individual issues addressed include:

---
 opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java |  224 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 208 insertions(+), 16 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
index 57392a6..d9d94f7 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -992,7 +992,7 @@
               try
               {
                 type = AttributeTypeSyntax.decodeAttributeType(v.getValue(),
-                                                               newSchema);
+                                                newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1017,7 +1017,7 @@
               try
               {
                 oc = ObjectClassSyntax.decodeObjectClass(v.getValue(),
-                                                         newSchema);
+                                                         newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1041,7 +1041,8 @@
               NameForm nf;
               try
               {
-                nf = NameFormSyntax.decodeNameForm(v.getValue(), newSchema);
+                nf = NameFormSyntax.decodeNameForm(v.getValue(), newSchema,
+                                                   false);
               }
               catch (DirectoryException de)
               {
@@ -1066,7 +1067,7 @@
               try
               {
                 dcr = DITContentRuleSyntax.decodeDITContentRule(v.getValue(),
-                                                                newSchema);
+                                                newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1116,7 +1117,7 @@
               try
               {
                 mru = MatchingRuleUseSyntax.decodeMatchingRuleUse(v.getValue(),
-                                                                  newSchema);
+                                                 newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1162,7 +1163,7 @@
               try
               {
                 type = AttributeTypeSyntax.decodeAttributeType(v.getValue(),
-                                                               newSchema);
+                                                newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1188,7 +1189,7 @@
               try
               {
                 oc = ObjectClassSyntax.decodeObjectClass(v.getValue(),
-                                                         newSchema);
+                                                         newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1212,7 +1213,8 @@
               NameForm nf;
               try
               {
-                nf = NameFormSyntax.decodeNameForm(v.getValue(), newSchema);
+                nf = NameFormSyntax.decodeNameForm(v.getValue(), newSchema,
+                                                   false);
               }
               catch (DirectoryException de)
               {
@@ -1237,7 +1239,7 @@
               try
               {
                 dcr = DITContentRuleSyntax.decodeDITContentRule(v.getValue(),
-                                                                newSchema);
+                                                newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1289,7 +1291,7 @@
               try
               {
                 mru = MatchingRuleUseSyntax.decodeMatchingRuleUse(v.getValue(),
-                                                                  newSchema);
+                                                 newSchema, false);
               }
               catch (DirectoryException de)
               {
@@ -1435,7 +1437,7 @@
 
 
     // Make sure that the new attribute type doesn't reference an undefined
-    // superior attribute type.
+    // or OBSOLETE superior attribute type.
     AttributeType superiorType = attributeType.getSuperiorType();
     if (superiorType != null)
     {
@@ -1447,6 +1449,56 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (superiorType.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_OBSOLETE_SUPERIOR_ATTRIBUTE_TYPE;
+        String message = getMessage(msgID, attributeType.getNameOrOID(),
+                                    superiorType.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
+    }
+
+
+    // Make sure that none of the associated matching rules are marked OBSOLETE.
+    MatchingRule mr = attributeType.getEqualityMatchingRule();
+    if ((mr != null) && mr.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_ATTRTYPE_OBSOLETE_MR;
+      String message = getMessage(msgID, attributeType.getNameOrOID(),
+                                  mr.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
+    mr = attributeType.getOrderingMatchingRule();
+    if ((mr != null) && mr.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_ATTRTYPE_OBSOLETE_MR;
+      String message = getMessage(msgID, attributeType.getNameOrOID(),
+                                  mr.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
+    mr = attributeType.getSubstringMatchingRule();
+    if ((mr != null) && mr.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_ATTRTYPE_OBSOLETE_MR;
+      String message = getMessage(msgID, attributeType.getNameOrOID(),
+                                  mr.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
+    mr = attributeType.getApproximateMatchingRule();
+    if ((mr != null) && mr.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_ATTRTYPE_OBSOLETE_MR;
+      String message = getMessage(msgID, attributeType.getNameOrOID(),
+                                  mr.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
     }
 
 
@@ -1572,7 +1624,8 @@
         AttributeType at;
         try
         {
-          at = AttributeTypeSyntax.decodeAttributeType(v.getValue(), schema);
+          at = AttributeTypeSyntax.decodeAttributeType(v.getValue(), schema,
+                                                       false);
         }
         catch (DirectoryException de)
         {
@@ -1746,7 +1799,8 @@
 
 
     // Make sure that the new objectclass doesn't reference an undefined
-    // superior class, or an undefined required or optional attribute type.
+    // superior class, or an undefined required or optional attribute type,
+    // and that none of them are OBSOLETE.
     ObjectClass superiorClass = objectClass.getSuperiorClass();
     if (superiorClass != null)
     {
@@ -1758,6 +1812,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (superiorClass.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_OBSOLETE_SUPERIOR_OBJECTCLASS;
+        String message = getMessage(msgID, objectClass.getNameOrOID(),
+                                    superiorClass.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : objectClass.getRequiredAttributes())
@@ -1770,6 +1832,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_OC_OBSOLETE_REQUIRED_ATTR;
+        String message = getMessage(msgID, objectClass.getNameOrOID(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : objectClass.getOptionalAttributes())
@@ -1782,6 +1852,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_OC_OBSOLETE_OPTIONAL_ATTR;
+        String message = getMessage(msgID, objectClass.getNameOrOID(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
 
@@ -1906,7 +1984,7 @@
         ObjectClass oc;
         try
         {
-          oc = ObjectClassSyntax.decodeObjectClass(v.getValue(), schema);
+          oc = ObjectClassSyntax.decodeObjectClass(v.getValue(), schema, false);
         }
         catch (DirectoryException de)
         {
@@ -2045,7 +2123,8 @@
 
 
     // Make sure that the new name form doesn't reference an undefined
-    // structural class, or an undefined required or optional attribute type.
+    // structural class, or an undefined required or optional attribute type, or
+    // that any of them are marked OBSOLETE.
     ObjectClass structuralClass = nameForm.getStructuralClass();
     if (! schema.hasObjectClass(structuralClass.getOID()))
     {
@@ -2063,6 +2142,14 @@
       throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                    msgID);
     }
+    if (structuralClass.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_NF_OC_OBSOLETE;
+      String message = getMessage(msgID, nameForm.getNameOrOID(),
+                                  structuralClass.getNameOrOID());
+      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+                                   msgID);
+    }
 
     NameForm existingNFForClass = schema.getNameForm(structuralClass);
     if ((existingNFForClass != null) && (existingNFForClass != existingNF))
@@ -2085,6 +2172,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_NF_OBSOLETE_REQUIRED_ATTR;
+        String message = getMessage(msgID, nameForm.getNameOrOID(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : nameForm.getOptionalAttributes())
@@ -2097,6 +2192,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_NF_OBSOLETE_OPTIONAL_ATTR;
+        String message = getMessage(msgID, nameForm.getNameOrOID(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
 
@@ -2220,7 +2323,7 @@
         NameForm nf;
         try
         {
-          nf = NameFormSyntax.decodeNameForm(v.getValue(), schema);
+          nf = NameFormSyntax.decodeNameForm(v.getValue(), schema, false);
         }
         catch (DirectoryException de)
         {
@@ -2363,6 +2466,15 @@
                                    msgID);
     }
 
+    if (structuralClass.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_DCR_STRUCTURAL_OC_OBSOLETE;
+      String message = getMessage(msgID, ditContentRule.getName(),
+                                  structuralClass.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
     for (ObjectClass oc : ditContentRule.getAuxiliaryClasses())
     {
       if (! schema.hasObjectClass(oc.getOID()))
@@ -2373,6 +2485,22 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      if (oc.getObjectClassType() != ObjectClassType.AUXILIARY)
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DCR_OC_NOT_AUXILIARY;
+        String message = getMessage(msgID, ditContentRule.getName(),
+                                    oc.getNameOrOID());
+        throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+                                     msgID);
+      }
+      if (oc.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DCR_OBSOLETE_AUXILIARY_OC;
+        String message = getMessage(msgID, ditContentRule.getName(),
+                                    oc.getNameOrOID());
+        throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : ditContentRule.getRequiredAttributes())
@@ -2385,6 +2513,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DCR_OBSOLETE_REQUIRED_ATTR;
+        String message = getMessage(msgID, ditContentRule.getName(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : ditContentRule.getOptionalAttributes())
@@ -2397,6 +2533,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DCR_OBSOLETE_OPTIONAL_ATTR;
+        String message = getMessage(msgID, ditContentRule.getName(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
     for (AttributeType at : ditContentRule.getProhibitedAttributes())
@@ -2409,6 +2553,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DCR_OBSOLETE_PROHIBITED_ATTR;
+        String message = getMessage(msgID, ditContentRule.getName(),
+                                    at.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
 
@@ -2616,6 +2768,29 @@
       throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                    msgID);
     }
+    if (nameForm.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_DSR_OBSOLETE_NAME_FORM;
+      String message = getMessage(msgID, ditStructureRule.getNameOrRuleID(),
+                                  nameForm.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
+
+    // If there are any superior rules, then make sure none of them are marked
+    // OBSOLETE.
+    for (DITStructureRule dsr : ditStructureRule.getSuperiorRules())
+    {
+      if (dsr.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_DSR_OBSOLETE_SUPERIOR_RULE;
+        String message = getMessage(msgID, ditStructureRule.getNameOrRuleID(),
+                                    dsr.getNameOrRuleID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
+    }
 
 
     // If there is no existing rule, then we're adding a new DIT structure rule.
@@ -2867,6 +3042,15 @@
                                    msgID);
     }
 
+    if (matchingRule.isObsolete())
+    {
+      int    msgID   = MSGID_SCHEMA_MODIFY_MRU_OBSOLETE_MR;
+      String message = getMessage(msgID, matchingRuleUse.getName(),
+                                  matchingRule.getNameOrOID());
+      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                   msgID);
+    }
+
 
     // Make sure that the new matching rule use doesn't reference an undefined
     // attribute type.
@@ -2880,6 +3064,14 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
                                      msgID);
       }
+      else if (at.isObsolete())
+      {
+        int    msgID   = MSGID_SCHEMA_MODIFY_MRU_OBSOLETE_ATTR;
+        String message = getMessage(msgID, matchingRuleUse.getName(),
+                                    matchingRule.getNameOrOID());
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message,
+                                     msgID);
+      }
     }
 
 

--
Gitblit v1.10.0