You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/01/30 20:28:34 UTC

svn commit: r501526 - 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/ schema-registries/src/main/java/org/apache/directory/server/schema/registries/

Author: akarasulu
Date: Tue Jan 30 11:28:33 2007
New Revision: 501526

URL: http://svn.apache.org/viewvc?view=rev&rev=501526
Log:
Added code to disable/enable schemas and tested it.  Moved this code down into
the DefaultRegistry where it aught to be instead of the MetaSchemaHandler which
calls unload(String) with the schema name.

Added:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
    directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java

Added: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java?view=auto&rev=501526
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java (added)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java Tue Jan 30 11:28:33 2007
@@ -0,0 +1,112 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.schema;
+
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+
+
+/**
+ * A test case which tests the correct operation of the schema 
+ * entity handler.  
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MetaSchemaHandlerITest extends AbstractAdminTestCase
+{
+    /** the schema to use for this test: one that is not loaded by default */
+    private static final String TEST_SCHEMA = "nis";
+    /** a test attribute in the test schema: uidNumber in nis schema */
+    private static final String TEST_ATTR_OID = "1.3.6.1.1.1.1.0";
+    
+    
+    /**
+     * Checks to make sure updates enabling a metaSchema object in
+     * the schema partition triggers the loading of that schema into
+     * the global registries.
+     */
+    public void testEnableSchema() throws Exception
+    {
+        AttributeTypeRegistry atr = registries.getAttributeTypeRegistry();
+        
+        // check that the nis schema is not loaded
+        assertNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+        
+        // double check and make sure an attribute from that schema is 
+        // not in the AttributeTypeRegistry
+        assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
+        
+        // now enable the test schema
+        ModificationItemImpl[] mods = new ModificationItemImpl[1];
+        Attribute attr = new AttributeImpl( "m-disabled", "FALSE" );
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        super.schemaRoot.modifyAttributes( "cn=nis", mods );
+        
+        // now test that the schema is loaded 
+        assertNotNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+        
+        // double check and make sure the test attribute from the 
+        // test schema is now loaded and present within the attr registry
+        assertTrue( atr.hasAttributeType( TEST_ATTR_OID ) );
+    }
+
+
+    /**
+     * Checks to make sure updates disabling a metaSchema object in
+     * the schema partition triggers the unloading of that schema from
+     * the global registries.
+     */
+    public void testDisableSchema() throws Exception
+    {
+        // let's enable the test schema
+        testEnableSchema();
+        
+        AttributeTypeRegistry atr = registries.getAttributeTypeRegistry();
+        
+        // check that the nis schema is loaded
+        assertNotNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+        
+        // double check and make sure an attribute from that schema is 
+        // in the AttributeTypeRegistry
+        assertTrue( atr.hasAttributeType( TEST_ATTR_OID ) );
+        
+        // now disable the test schema
+        ModificationItemImpl[] mods = new ModificationItemImpl[1];
+        Attribute attr = new AttributeImpl( "m-disabled", "TRUE" );
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        super.schemaRoot.modifyAttributes( "cn=nis", mods );
+        
+        // now test that the schema is NOT loaded 
+        assertNull( registries.getLoadedSchemas().get( TEST_SCHEMA ) );
+        
+        // double check and make sure the test attribute from the test  
+        // schema is now NOT loaded and present within the attr registry
+        assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
+    }
+}

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java?view=diff&rev=501526&r1=501525&r2=501526
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSchemaHandler.java Tue Jan 30 11:28:33 2007
@@ -20,8 +20,6 @@
 package org.apache.directory.server.core.schema;
 
 
-import java.util.Iterator;
-
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -33,7 +31,6 @@
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.OidRegistry;
 import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.schema.registries.SchemaObjectRegistry;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
@@ -41,7 +38,6 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.SchemaObject;
 
 
 /**
@@ -147,34 +143,9 @@
 
     private void disableSchema( String schemaName ) throws NamingException
     {
-        disableSchema( globalRegistries.getDitStructureRuleRegistry(), schemaName );
-        disableSchema( globalRegistries.getDitContentRuleRegistry(), schemaName );
-        disableSchema( globalRegistries.getMatchingRuleUseRegistry(), schemaName );
-        disableSchema( globalRegistries.getNameFormRegistry(), schemaName );
-        disableSchema( globalRegistries.getObjectClassRegistry(), schemaName );
-        disableSchema( globalRegistries.getAttributeTypeRegistry(), schemaName );
-        disableSchema( globalRegistries.getMatchingRuleRegistry(), schemaName );
-        disableSchema( globalRegistries.getSyntaxRegistry(), schemaName );
-
-        globalRegistries.getNormalizerRegistry().unregisterSchemaElements( schemaName );
-        globalRegistries.getComparatorRegistry().unregisterSchemaElements( schemaName );
-        globalRegistries.getSyntaxCheckerRegistry().unregisterSchemaElements( schemaName );
+        globalRegistries.unload( schemaName );
     }
 
-    
-    private void disableSchema( SchemaObjectRegistry registry, String schemaName ) throws NamingException
-    {
-        Iterator<? extends SchemaObject> objects = registry.iterator();
-        while ( objects.hasNext() )
-        {
-            SchemaObject obj = objects.next();
-            if ( obj.getSchema().equalsIgnoreCase( schemaName ) )
-            {
-                registry.unregister( obj.getOid() );
-            }
-        }
-    }
-    
 
     /**
      * TODO - for now we're just going to add the schema to the global 

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java?view=diff&rev=501526&r1=501525&r2=501526
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java (original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/DefaultRegistries.java Tue Jan 30 11:28:33 2007
@@ -33,6 +33,7 @@
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.Syntax;
 
 
@@ -507,7 +508,45 @@
         byName.put( schema.getSchemaName(), schema );
         schemaLoader.load( schema, this );
     }
+    
+    
+    public void unload( String schemaName ) throws NamingException
+    {
+        disableSchema( ditStructureRuleRegistry, schemaName );
+        disableSchema( ditContentRuleRegistry, schemaName );
+        disableSchema( matchingRuleUseRegistry, schemaName );
+        disableSchema( nameFormRegistry, schemaName );
+        disableSchema( objectClassRegistry, schemaName );
+        disableSchema( attributeTypeRegistry, schemaName );
+        disableSchema( matchingRuleRegistry, schemaName );
+        disableSchema( syntaxRegistry, schemaName );
+
+        normalizerRegistry.unregisterSchemaElements( schemaName );
+        comparatorRegistry.unregisterSchemaElements( schemaName );
+        syntaxCheckerRegistry.unregisterSchemaElements( schemaName );
+        byName.remove( schemaName );
+    }
+
 
+    private void disableSchema( SchemaObjectRegistry registry, String schemaName ) throws NamingException
+    {
+        Iterator<? extends SchemaObject> objects = registry.iterator();
+        List<String> unregistered = new ArrayList<String>();
+        while ( objects.hasNext() )
+        {
+            SchemaObject obj = objects.next();
+            if ( obj.getSchema().equalsIgnoreCase( schemaName ) )
+            {
+                unregistered.add( obj.getOid() );
+            }
+        }
+        
+        for ( String oid : unregistered )
+        {
+            registry.unregister( oid );
+        }
+    }
+    
 
     public SchemaLoader setSchemaLoader()
     {

Modified: directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java?view=diff&rev=501526&r1=501525&r2=501526
==============================================================================
--- directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java (original)
+++ directory/apacheds/trunk/schema-registries/src/main/java/org/apache/directory/server/schema/registries/Registries.java Tue Jan 30 11:28:33 2007
@@ -44,6 +44,8 @@
     void load( String schemaName ) throws NamingException;
     
     void load( String schemaName, Properties props ) throws NamingException;
+
+    void unload( String schemaName ) throws NamingException;
     
     SchemaLoader setSchemaLoader();