directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r506220 - in /directory/apacheds/trunk: core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/schema/
Date Mon, 12 Feb 2007 02:08:18 GMT
Author: akarasulu
Date: Sun Feb 11 18:08:17 2007
New Revision: 506220

URL: http://svn.apache.org/viewvc?view=rev&rev=506220
Log:
fixing breakage with MetaSyntaxHandlerITest

Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.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/MetaSyntaxHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerITest.java?view=diff&rev=506220&r1=506219&r2=506220
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerITest.java
Sun Feb 11 18:08:17 2007
@@ -20,10 +20,16 @@
 package org.apache.directory.server.core.schema;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.constants.SystemSchemaConstants;
@@ -36,6 +42,7 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker;
 
 
 /**
@@ -56,7 +63,8 @@
     private static final String MR_OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
     private static final String MR_DESCRIPTION = "A test matchingRule";
 
-    
+    private static final String SUBSCHEMA_SUBENTRY = "subschemaSubentry";
+
     /**
      * Gets relative DN to ou=schema.
      */
@@ -83,6 +91,7 @@
         
         LdapDN dn = getSyntaxContainer( "apachemeta" );
         dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        createDummySyntaxChecker( OID, "apachemeta" );
         super.schemaRoot.createSubcontext( dn, attrs );
         
         assertTrue( registries.getSyntaxRegistry().hasSyntax( OID ) );
@@ -433,6 +442,7 @@
         // nis is by default inactive
         LdapDN dn = getSyntaxContainer( "nis" );
         dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        createDummySyntaxChecker( OID, "nis" );
         super.schemaRoot.createSubcontext( dn, attrs );
         
         assertFalse( "adding new syntax to disabled schema should not register it into the
registries", 
@@ -479,5 +489,50 @@
         
         assertEquals( "syntax should be in apachemeta schema after move", 
             registries.getSyntaxRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+
+
+    private void createDummySyntaxChecker( String oid, String schema ) throws NamingException
+    {
+        List<String> descriptions = new ArrayList<String>();
+        descriptions.add( "( " + oid + " DESC 'bogus desc' FQCN " + AcceptAllSyntaxChecker.class.getName()

+            + " X-SCHEMA '" + schema + "' )" );
+        modify( DirContext.ADD_ATTRIBUTE, descriptions, "syntaxCheckers" );
+    }
+    
+    
+    private void modify( int op, List<String> descriptions, String opAttr ) throws
NamingException
+    {
+        LdapDN dn = new LdapDN( getSubschemaSubentryDN() );
+        Attribute attr = new AttributeImpl( opAttr );
+        for ( String description : descriptions )
+        {
+            attr.add( description );
+        }
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( attr );
+        
+        rootDSE.modifyAttributes( dn, op, mods );
+    }
+    
+    
+    /**
+     * Get's the subschemaSubentry attribute value from the rootDSE.
+     * 
+     * @return the subschemaSubentry distinguished name
+     * @throws NamingException if there are problems accessing the RootDSE
+     */
+    private String getSubschemaSubentryDN() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        controls.setReturningAttributes( new String[]{ SUBSCHEMA_SUBENTRY } );
+        
+        NamingEnumeration<SearchResult> results = rootDSE.search( "", "(objectClass=*)",
controls );
+        SearchResult result = results.next();
+        results.close();
+        Attribute subschemaSubentry = result.getAttributes().get( SUBSCHEMA_SUBENTRY );
+        return ( String ) subschemaSubentry.get();
     }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java?view=diff&rev=506220&r1=506219&r2=506220
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
Sun Feb 11 18:08:17 2007
@@ -271,14 +271,14 @@
     {
         Schema schema = loader.getSchema( syntax.getSchema() );
         
-        if ( ! this.targetRegistries.getSyntaxCheckerRegistry().hasSyntaxChecker( syntax.getOid()
) )
+        if ( ! dao.hasSyntaxChecker( syntax.getOid() ) )
         {
             throw new LdapOperationNotSupportedException(
                 "Cannot permit the addition of a syntax without the prior creation of a "
+
                 "\nsyntaxChecker with the same object identifier of the syntax!",
                 ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
-        
+
         if ( ! schema.isDisabled() )
         {
             syntaxRegistry.register( syntax );

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=506220&r1=506219&r2=506220
==============================================================================
--- 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 18:08:17 2007
@@ -244,6 +244,90 @@
     }
     
     
+    public boolean hasSyntax( String oid ) throws NamingException
+    {
+        BranchNode filter = new BranchNode( AssertionEnum.AND );
+        filter.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_SYNTAX_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;
+            }
+            
+            if ( ne.hasMore() )
+            {
+                throw new NamingException( "Got more than one syntax for oid of " + oid );
+            }
+
+            return true;
+        }
+        finally
+        {
+            ne.close();
+        }
+    }
+    
+    
+    public boolean hasSyntaxChecker( String oid ) throws NamingException
+    {
+        BranchNode filter = new BranchNode( AssertionEnum.AND );
+        filter.addNode( new SimpleNode( OBJECTCLASS_OID, 
+            MetaSchemaConstants.META_SYNTAX_CHECKER_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;
+            }
+            
+            if ( ne.hasMore() )
+            {
+                throw new NamingException( "Got more than one syntaxChecker for oid of "
+ oid );
+            }
+
+            return true;
+        }
+        finally
+        {
+            ne.close();
+        }
+    }
+    
+    
     /**
      * Given the non-normalized name (alias) or the OID for a schema entity.  This 
      * method finds the schema under which that entity is located. 



Mime
View raw message