directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r506308 - in /directory/apacheds/trunk: core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/partition/impl/btree/ core/src/main/java/org/apache/directory/server/core/schema/
Date Mon, 12 Feb 2007 06:03:32 GMT
Author: akarasulu
Date: Sun Feb 11 22:03:30 2007
New Revision: 506308

URL: http://svn.apache.org/viewvc?view=rev&rev=506308
Log:
changes ...

 o added some lookup functions to the SchemaPartitionDao for attributes
 o added some error checking to the DescriptionParser to catch bad attributeType
   descriptions 
 o fixed some issues in the search algorith wrt using the right matchingRule
   from the attributeType
 o added many tests to make sure we can accept good attributeTypes added to the
   schema subentry and reject those that are non-sensical


Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/SubstringEvaluator.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java?view=diff&rev=506308&r1=506307&r2=506308
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
Sun Feb 11 22:03:30 2007
@@ -1101,106 +1101,191 @@
         checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
         checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
 
-//        // -------------------------------------------------------------------
-//        // test add with existant syntax but no name and no desc
-//        // -------------------------------------------------------------------
-//
-//        descriptions.clear();
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        
-//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
-//        
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
-//
-//        // -------------------------------------------------------------------
-//        // test add with existant syntax but no name 
-//        // -------------------------------------------------------------------
-//        
-//        // clear the matchingRules out now
-//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
-//
-//        descriptions.clear();
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 DESC 'bogus desc' " +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 DESC 'bogus desc' " +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        
-//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
-//        
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
-//
-//        // -------------------------------------------------------------------
-//        // test add success with name
-//        // -------------------------------------------------------------------
-//        
-//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
-//        
-//        descriptions.clear();
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'blah0' DESC 'bogus desc'
" +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'blah1' 'othername1'
) DESC 'bogus desc' " +
-//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        
-//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
-//        
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
-//
-//        // -------------------------------------------------------------------
-//        // test add success full (with obsolete)
-//        // -------------------------------------------------------------------
-//        
-//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
-//        
-//        descriptions.clear();
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'blah0' DESC 'bogus desc'
" +
-//                "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'blah1' 'othername1'
) DESC 'bogus desc' " +
-//                "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
-//        
-//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
-//        
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
-//
-//        // -------------------------------------------------------------------
-//        // test failure to replace
-//        // -------------------------------------------------------------------
-//        
-//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
-//        
-//        try
-//        {
-//            modify( DirContext.REPLACE_ATTRIBUTE, descriptions, "matchingRules" );
-//            fail( "modify REPLACE operations should not be allowed" );
-//        }
-//        catch ( LdapOperationNotSupportedException e )
-//        {
-//            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
-//        }
-//
-//        // -------------------------------------------------------------------
-//        // check add no schema info
-//        // -------------------------------------------------------------------
-//        
-//        descriptions.clear();
-//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10002 DESC 'bogus desc' " +
-//            "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" );
-//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
-//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10002", "other", true );
+        // -------------------------------------------------------------------
+        // test reject with non-existant super type
+        // -------------------------------------------------------------------
+
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 1.2.3.4 X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 1.2.3.4 X-SCHEMA 'nis' )" );
+        
+        try
+        {
+            modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "Cannot add attributeType with bogus non-existant syntax" );
+        }
+        catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+
+        // -------------------------------------------------------------------
+        // test reject with non-existant equality matchingRule
+        // -------------------------------------------------------------------
+
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 EQUALITY 1.2.3.4 X-SCHEMA 'nis' )"
);
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 EQUALITY 1.2.3.4 X-SCHEMA 'nis' )"
);
+        
+        try
+        {
+            modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "Cannot add attributeType with bogus non-existant equality MatchingRule"
);
+        }
+        catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+
+        // -------------------------------------------------------------------
+        // test reject with non-existant ordering matchingRule
+        // -------------------------------------------------------------------
+
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ORDERING 1.2.3.4 X-SCHEMA 'nis' )"
);
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ORDERING 1.2.3.4 X-SCHEMA 'nis' )"
);
+        
+        try
+        {
+            modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "Cannot add attributeType with bogus non-existant ordering MatchingRule"
);
+        }
+        catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+
+        // -------------------------------------------------------------------
+        // test reject with non-existant substring matchingRule
+        // -------------------------------------------------------------------
+
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUBSTR 1.2.3.4 X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUBSTR 1.2.3.4 X-SCHEMA 'nis' )" );
+        
+        try
+        {
+            modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "Cannot add attributeType with bogus non-existant substrings MatchingRule"
);
+        }
+        catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+
+        // -------------------------------------------------------------------
+        // test success with valid superior, valid syntax but no name
+        // -------------------------------------------------------------------
+
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 X-SCHEMA 'nis' )" );
+        
+        modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+
+        // -------------------------------------------------------------------
+        // test success with valid superior, valid syntax and names
+        // -------------------------------------------------------------------
+
+        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) "
+
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 X-SCHEMA 'nis' )" );
+        
+        modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+
+        // -------------------------------------------------------------------
+        // test success with everything
+        // -------------------------------------------------------------------
+
+        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " +
+                "OBSOLETE SUP 2.5.4.41 " +
+                "EQUALITY caseExactIA5Match " +
+                "ORDERING octetStringOrderingMatch " +
+                "SUBSTR caseExactIA5SubstringsMatch COLLECTIVE " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " +
+                "SINGLE-VALUE USAGE userApplications X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) "
+
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 " +
+                "NO-USER-MODIFICATION USAGE directoryOperation X-SCHEMA 'nis' )" );
+        
+        modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+
+        // -------------------------------------------------------------------
+        // test failure to replace
+        // -------------------------------------------------------------------
+        
+        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "attributeTypes" );
+        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+        
+        try
+        {
+            modify( DirContext.REPLACE_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "modify REPLACE operations should not be allowed" );
+        }
+        catch ( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+
+        // -------------------------------------------------------------------
+        // check add no schema info
+        // -------------------------------------------------------------------
+        
+        descriptions.clear();
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'type0' " +
+                "OBSOLETE SUP 2.5.4.41 " +
+                "EQUALITY caseExactIA5Match " +
+                "ORDERING octetStringOrderingMatch " +
+                "SUBSTR caseExactIA5SubstringsMatch COLLECTIVE " +
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " +
+                "SINGLE-VALUE USAGE userApplications )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'type1' 'altName' ) "
+
+                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SUP 2.5.4.41 " +
+                "NO-USER-MODIFICATION USAGE directoryOperation )" );
+        
+        modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "other", true );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "other", true );
     }
 
     

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java?view=diff&rev=506308&r1=506307&r2=506308
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
Sun Feb 11 22:03:30 2007
@@ -57,7 +57,7 @@
     /** ordering matching type constant */
     private static final int ORDERING_MATCH = 1;
     /** substring matching type constant */
-    private static final int SUBSTRING_MATCH = 3;
+    private static final int SUBSTRING_MATCH = 2;
 
     /** Database used to evaluate leaf with */
     private BTreePartition db;
@@ -190,8 +190,8 @@
          * We need to iterate through all values and for each value we normalize
          * and use the comparator to determine if a match exists.
          */
-        Normalizer normalizer = getNormalizer( attrId );
-        Comparator comparator = getComparator( attrId );
+        Normalizer normalizer = getNormalizer( attrId, ORDERING_MATCH );
+        Comparator<Object> comparator = getComparator( attrId, ORDERING_MATCH );
         Object filterValue = node.getValue();
         NamingEnumeration list = attr.getAll();
 
@@ -284,8 +284,8 @@
             return idx.hasValue( node.getValue(), rec.getEntryId() );
         }
 
-        Normalizer normalizer = getNormalizer( node.getAttribute() );
-        Comparator comparator = getComparator( node.getAttribute() );
+        Normalizer normalizer = getNormalizer( node.getAttribute(), EQUALITY_MATCH );
+        Comparator<Object> comparator = getComparator( node.getAttribute(), EQUALITY_MATCH
);
 
         /*
          * Get the attribute and if it is not set in rec then resusitate it
@@ -355,9 +355,10 @@
      * @return the comparator for equality matching
      * @throws NamingException if there is a failure
      */
-    private Comparator getComparator( String attrId ) throws NamingException
+    @SuppressWarnings("unchecked")
+    private Comparator<Object> getComparator( String attrId, int matchType ) throws
NamingException
     {
-        MatchingRule mrule = getMatchingRule( attrId, EQUALITY_MATCH );
+        MatchingRule mrule = getMatchingRule( attrId, matchType );
         
         if ( mrule == null )
         {
@@ -375,9 +376,9 @@
      * @return the normalizer for equality matching
      * @throws NamingException if there is a failure
      */
-    private Normalizer getNormalizer( String attrId ) throws NamingException
+    private Normalizer getNormalizer( String attrId, int matchType ) throws NamingException
     {
-        MatchingRule mrule = getMatchingRule( attrId, EQUALITY_MATCH );
+        MatchingRule mrule = getMatchingRule( attrId, matchType );
         
         if ( mrule == null )
         {
@@ -416,6 +417,17 @@
                 throw new NamingException( "Unknown match type: " + matchType );
         }
 
+        // if there is no ordering or substring matchingRule for the attributeType 
+        // then we fallback to use the equality matching rule to determine the
+        // normalizer and comparator to use.  This possible since 
+        // comparators are redundant and enable ordering to occur.  So if
+        // we can we will use the comparator of the ordering matchingRule
+        // and if not we default to the equality matchingRule's comparator.
+        if ( matchType != EQUALITY_MATCH && mrule == null )
+        {
+            return getMatchingRule( attrId, EQUALITY_MATCH );
+        }
+        
         return mrule;
     }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/SubstringEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/SubstringEvaluator.java?view=diff&rev=506308&r1=506307&r2=506308
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/SubstringEvaluator.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/SubstringEvaluator.java
Sun Feb 11 22:03:30 2007
@@ -61,8 +61,8 @@
      * @param oidRegistry the OID registry for name to OID mapping
      * @param attributeTypeRegistry the attributeType registry
      */
-    public SubstringEvaluator(BTreePartition db, OidRegistry oidRegistry,
-        AttributeTypeRegistry attributeTypeRegistry)
+    public SubstringEvaluator( BTreePartition db, OidRegistry oidRegistry,
+        AttributeTypeRegistry attributeTypeRegistry )
     {
         this.db = db;
         this.oidRegistry = oidRegistry;

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java?view=diff&rev=506308&r1=506307&r2=506308
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
Sun Feb 11 22:03:30 2007
@@ -253,12 +253,84 @@
                 throw iave;
             }
 
+            // if the supertype is provided make sure it exists in some schema
+            if ( desc.getSuperType() != null && ! dao.hasAttributeType( desc.getSuperType()
) )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an invalid super
type: " 
+                        + desc.getSuperType(), 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
+            // if the syntax is provided by the description make sure it exists in some schema
             if ( desc.getSyntax() != null && ! dao.hasSyntax( desc.getSyntax() )
)
             {
                 throw new LdapOperationNotSupportedException(
                     "Cannot permit the addition of an attributeType with an invalid syntax:
" + desc.getSyntax(), 
                     ResultCodeEnum.UNWILLING_TO_PERFORM );
             }
+            
+            // if the matchingRule is provided make sure it exists in some schema
+            if ( desc.getEqualityMatchingRule() != null && ! dao.hasMatchingRule(
desc.getEqualityMatchingRule() ) )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an invalid EQUALITY
matchingRule: " 
+                        + desc.getEqualityMatchingRule(), 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
+            // if the matchingRule is provided make sure it exists in some schema
+            if ( desc.getOrderingMatchingRule() != null && ! dao.hasMatchingRule(
desc.getOrderingMatchingRule() ) )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an invalid ORDERING
matchingRule: " 
+                        + desc.getOrderingMatchingRule(), 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
+            // if the matchingRule is provided make sure it exists in some schema
+            if ( desc.getSubstringsMatchingRule() != null && ! dao.hasMatchingRule(
desc.getSubstringsMatchingRule() ) )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an invalid SUBSTRINGS
matchingRule: " 
+                        + desc.getSubstringsMatchingRule(), 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
+            // if the equality matching rule is null and no super type is specified then
there is
+            // definitely no equality matchingRule that can be resolved.  We cannot use an
attribute
+            // without a matchingRule for search or for building indices not to mention lookups.
+            if ( desc.getEqualityMatchingRule() == null && desc.getSuperType() ==
null )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an no EQUALITY matchingRule
" +
+                    "\nand no super type from which to derive an EQUALITY matchingRule.",

+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+            else if ( desc.getEqualityMatchingRule() == null )
+            {
+                AttributeType superType = globalRegistries.getAttributeTypeRegistry().lookup(
desc.getSuperType() );
+                if ( superType.getEquality() == null )
+                {
+                    throw new LdapOperationNotSupportedException(
+                        "Cannot permit the addition of an attributeType with which cannot
resolve an " +
+                        "EQUALITY matchingRule from it's super type.", 
+                        ResultCodeEnum.UNWILLING_TO_PERFORM );
+                }
+            }
+            
+            // a syntax is manditory for an attributeType and if not provided by the description

+            // must be provided from some ancestor in the attributeType hierarchy; without
either
+            // of these the description definitely cannot resolve a syntax and cannot be
allowed.
+            // if a supertype exists then it must resolve a proper syntax somewhere in the
hierarchy.
+            if ( desc.getSyntax() == null && desc.getSuperType() == null )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an no syntax " +
+                    "\nand no super type from which to derive a syntax.", 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+            
 
             AttributeTypeImpl at = new AttributeTypeImpl( desc.getNumericOid(), globalRegistries
);
             at.setCanUserModify( desc.isUserModifiable() );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java?view=diff&rev=506308&r1=506307&r2=506308
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartitionDao.java
Sun Feb 11 22:03:30 2007
@@ -245,6 +245,49 @@
     }
     
     
+    public boolean hasAttributeType( String oid ) throws NamingException
+    {
+        BranchNode filter = new BranchNode( AssertionEnum.AND );
+        filter.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC, AssertionEnum.EQUALITY ) );
+
+        if ( NUMERIC_OID_CHECKER.isValidSyntax( oid ) )
+        {
+            filter.addNode( new SimpleNode( M_OID_OID, oid, AssertionEnum.EQUALITY ) );
+        }
+        else
+        {
+            filter.addNode( new SimpleNode( M_NAME_OID, oid.toLowerCase(), AssertionEnum.EQUALITY
) );
+        }
+        
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        NamingEnumeration<SearchResult> ne = null;
+
+        try
+        {
+            ne = partition.search( partition.getSuffix(), new HashMap(), filter, searchControls
);
+            
+            if ( ! ne.hasMore() )
+            {
+                return false;
+            }
+            
+            ne.next();
+            if ( ne.hasMore() )
+            {
+                throw new NamingException( "Got more than one attributeType for oid of "
+ oid );
+            }
+
+            return true;
+        }
+        finally
+        {
+            ne.close();
+        }
+    }
+    
+    
     public boolean hasSyntax( String oid ) throws NamingException
     {
         BranchNode filter = new BranchNode( AssertionEnum.AND );



Mime
View raw message