directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r495109 - in /directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema: AbstractSchemaChangeHandler.java MetaAttributeTypeHandler.java MetaMatchingRuleHandler.java MetaObjectClassHandler.java MetaSyntaxHandler.java
Date Thu, 11 Jan 2007 04:26:33 GMT
Author: akarasulu
Date: Wed Jan 10 20:26:32 2007
New Revision: 495109

URL: http://svn.apache.org/viewvc?view=rev&rev=495109
Log:
added base class handler for meta schema entity management to reduce some code; also fixed
bug where we were not registering OIDs even when schemas were disabled

Added:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java

Added: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java?view=auto&rev=495109
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
(added)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
Wed Jan 10 20:26:32 2007
@@ -0,0 +1,135 @@
+/*
+ *  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 java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.core.ServerUtils;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaObject;
+
+
+/**
+ * An abstract schema change handler with some reused functionality.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public abstract class AbstractSchemaChangeHandler implements SchemaChangeHandler
+{
+    protected static final String OU_OID = "2.5.4.11";
+
+    protected final Registries targetRegistries;
+    protected final PartitionSchemaLoader loader;
+    protected final AttributeType m_oidAT;
+    protected final SchemaEntityFactory factory;
+
+    
+    protected AbstractSchemaChangeHandler( Registries targetRegistries, PartitionSchemaLoader
loader ) throws NamingException
+    {
+        this.targetRegistries = targetRegistries;
+        this.loader = loader;
+        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
+        this.factory = new SchemaEntityFactory( targetRegistries );
+    }
+    
+    
+    protected abstract void modify( LdapDN name, Attributes entry, Attributes targetEntry
) throws NamingException;
+    
+    
+    public final void modify( LdapDN name, int modOp, Attributes mods, Attributes entry,
Attributes targetEntry )
+        throws NamingException
+    {
+        modify( name, entry, targetEntry );
+    }
+
+
+    public final void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry,
Attributes targetEntry )
+        throws NamingException
+    {
+        modify( name, entry, targetEntry );
+    }
+
+    
+    protected Set<String> getOids( Set<SearchResult> results ) throws NamingException
+    {
+        Set<String> oids = new HashSet<String>( results.size() );
+        
+        for ( SearchResult result : results )
+        {
+            LdapDN dn = new LdapDN( result.getName() );
+            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
+            oids.add( ( String ) dn.getRdn().getValue() );
+        }
+        
+        return oids;
+    }
+    
+    
+    protected String getOid( Attributes entry ) throws NamingException
+    {
+        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
+        if ( oid == null )
+        {
+            return null;
+        }
+        return ( String ) oid.get();
+    }
+    
+    
+    protected Schema getSchema( LdapDN name ) throws NamingException
+    {
+        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
+    }
+    
+    
+    protected void unregisterOids( String oid ) throws NamingException
+    {
+        targetRegistries.getOidRegistry().unregister( oid );
+    }
+    
+    
+    protected void registerOids( SchemaObject obj ) throws NamingException
+    {
+        String[] names = obj.getNames();
+        
+        if ( names != null )
+        {
+            for ( String name: names )
+            {
+                targetRegistries.getOidRegistry().register( name, obj.getOid() );
+            }
+        }
+        
+        targetRegistries.getOidRegistry().register( obj.getOid(), obj.getOid() );
+    }
+}

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java?view=diff&rev=495109&r1=495108&r2=495109
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
Wed Jan 10 20:26:32 2007
@@ -20,23 +20,19 @@
 package org.apache.directory.server.core.schema;
 
 
-import java.util.HashSet;
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
@@ -51,49 +47,24 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaAttributeTypeHandler implements SchemaChangeHandler
+public class MetaAttributeTypeHandler extends AbstractSchemaChangeHandler
 {
-    private static final String OU_OID = "2.5.4.11";
-
-    private final PartitionSchemaLoader loader;
     private final SchemaPartitionDao dao;
-    private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final AttributeTypeRegistry attributeTypeRegistry;
-    private final AttributeType m_oidAT;
 
     
 
     public MetaAttributeTypeHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
         throws NamingException
     {
-        this.targetRegistries = targetRegistries;
+        super( targetRegistries, loader );
+        
         this.dao = dao;
-        this.loader = loader;
         this.attributeTypeRegistry = targetRegistries.getAttributeTypeRegistry();
-        this.factory = new SchemaEntityFactory( targetRegistries );
-        this.m_oidAT = attributeTypeRegistry.lookup( MetaSchemaConstants.M_OID_AT );
     }
 
 
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
-    
-    
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
-    
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws
NamingException
     {
         String oldOid = getOid( entry );
         AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
@@ -107,20 +78,6 @@
     }
 
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
@@ -134,24 +91,13 @@
         {
             attributeTypeRegistry.register( schema.getSchemaName(), at );
         }
-    }
-
-
-    private Set<String> getOids( Set<SearchResult> results ) throws NamingException
-    {
-        Set<String> oids = new HashSet<String>( results.size() );
-        
-        for ( SearchResult result : results )
+        else
         {
-            LdapDN dn = new LdapDN( result.getName() );
-            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
-            oids.add( ( String ) dn.getRdn().getValue() );
+            registerOids( at );
         }
-        
-        return oids;
     }
-    
-    
+
+
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
         AttributeType at = factory.getAttributeType( entry, targetRegistries );
@@ -171,6 +117,7 @@
         {
             attributeTypeRegistry.unregister( at.getOid() );
         }
+        unregisterOids( at.getOid() );
     }
 
 
@@ -191,12 +138,19 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
+
         if ( ! schema.isDisabled() )
         {
-            AttributeType at = factory.getAttributeType( targetEntry, targetRegistries );
             attributeTypeRegistry.unregister( oldAt.getOid() );
             attributeTypeRegistry.register( schema.getSchemaName(), at );
         }
+        else
+        {
+            registerOids( at );
+        }
+        
+        unregisterOids( oldAt.getOid() );
     }
 
 
@@ -226,10 +180,15 @@
         {
             attributeTypeRegistry.unregister( oldAt.getOid() );
         }
+        unregisterOids( oldAt.getOid() );
 
         if ( ! newSchema.isDisabled() )
         {
             attributeTypeRegistry.register( newSchema.getSchemaName(), at );
+        }
+        else
+        {
+            registerOids( at );
         }
     }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java?view=diff&rev=495109&r1=495108&r2=495109
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
Wed Jan 10 20:26:32 2007
@@ -20,27 +20,22 @@
 package org.apache.directory.server.core.schema;
 
 
-import java.util.HashSet;
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -52,49 +47,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaMatchingRuleHandler implements SchemaChangeHandler
+public class MetaMatchingRuleHandler extends AbstractSchemaChangeHandler
 {
-    private static final String OU_OID = "2.5.4.11";
-
-    private final PartitionSchemaLoader loader;
     private final SchemaPartitionDao dao;
-    private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final MatchingRuleRegistry matchingRuleRegistry;
-    private final AttributeType m_oidAT;
 
     
-
     public MetaMatchingRuleHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
         throws NamingException
     {
-        this.targetRegistries = targetRegistries;
+        super( targetRegistries, loader );
+        
         this.dao = dao;
-        this.loader = loader;
         this.matchingRuleRegistry = targetRegistries.getMatchingRuleRegistry();
-        this.factory = new SchemaEntityFactory( targetRegistries );
-        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
     }
 
 
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
-    
-    
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
-    
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws
NamingException
     {
         String oldOid = getOid( entry );
         MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries );
@@ -108,20 +77,6 @@
     }
 
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
@@ -135,24 +90,13 @@
         {
             matchingRuleRegistry.register( schema.getSchemaName(), mr );
         }
-    }
-
-
-    private Set<String> getOids( Set<SearchResult> results ) throws NamingException
-    {
-        Set<String> oids = new HashSet<String>( results.size() );
-        
-        for ( SearchResult result : results )
+        else
         {
-            LdapDN dn = new LdapDN( result.getName() );
-            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
-            oids.add( ( String ) dn.getRdn().getValue() );
+            registerOids( mr );
         }
-        
-        return oids;
     }
-    
-    
+
+
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
         MatchingRule mr = factory.getMatchingRule( entry, targetRegistries );
@@ -172,6 +116,7 @@
         {
             matchingRuleRegistry.unregister( mr.getOid() );
         }
+        unregisterOids( mr.getOid() );
     }
 
 
@@ -192,12 +137,19 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries );
+
         if ( ! schema.isDisabled() )
         {
-            MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries );
             matchingRuleRegistry.unregister( oldMr.getOid() );
             matchingRuleRegistry.register( schema.getSchemaName(), mr );
         }
+        else
+        {
+            registerOids( mr );
+        }
+
+        unregisterOids( oldMr.getOid() );
     }
 
 
@@ -227,10 +179,15 @@
         {
             matchingRuleRegistry.unregister( oldMr.getOid() );
         }
+        unregisterOids( oldMr.getOid() );
 
         if ( ! newSchema.isDisabled() )
         {
             matchingRuleRegistry.register( newSchema.getSchemaName(), mr );
+        }
+        else
+        {
+            registerOids( mr );
         }
     }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java?view=diff&rev=495109&r1=495108&r2=495109
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
Wed Jan 10 20:26:32 2007
@@ -20,27 +20,22 @@
 package org.apache.directory.server.core.schema;
 
 
-import java.util.HashSet;
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.ObjectClassRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -52,48 +47,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaObjectClassHandler implements SchemaChangeHandler
+public class MetaObjectClassHandler extends AbstractSchemaChangeHandler
 {
-    private static final String OU_OID = "2.5.4.11";
-
-    private final PartitionSchemaLoader loader;
     private final SchemaPartitionDao dao;
-    private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final ObjectClassRegistry objectClassRegistry;
-    private final AttributeType m_oidAT;
 
 
     public MetaObjectClassHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
         throws NamingException
     {
-        this.targetRegistries = targetRegistries;
+        super( targetRegistries, loader );
+        
         this.dao = dao;
-        this.loader = loader;
         this.objectClassRegistry = targetRegistries.getObjectClassRegistry();
-        this.factory = new SchemaEntityFactory( targetRegistries );
-        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
     }
 
 
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
-    
-    
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
-    
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws
NamingException
     {
         String oldOid = getOid( entry );
         ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries );
@@ -107,20 +77,6 @@
     }
 
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
@@ -134,24 +90,13 @@
         {
             objectClassRegistry.register( schema.getSchemaName(), oc );
         }
-    }
-
-
-    private Set<String> getOids( Set<SearchResult> results ) throws NamingException
-    {
-        Set<String> oids = new HashSet<String>( results.size() );
-        
-        for ( SearchResult result : results )
+        else
         {
-            LdapDN dn = new LdapDN( result.getName() );
-            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
-            oids.add( ( String ) dn.getRdn().getValue() );
+            registerOids( oc );
         }
-        
-        return oids;
     }
-    
-    
+
+
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
         ObjectClass oc = factory.getObjectClass( entry, targetRegistries );
@@ -171,6 +116,8 @@
         {
             objectClassRegistry.unregister( oc.getOid() );
         }
+        
+        unregisterOids( oc.getOid() );
     }
 
 
@@ -191,12 +138,19 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries );
+
         if ( ! schema.isDisabled() )
         {
-            ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries );
             objectClassRegistry.unregister( oldOc.getOid() );
             objectClassRegistry.register( schema.getSchemaName(), oc );
         }
+        else
+        {
+            registerOids( oc );
+        }
+        
+        unregisterOids( oldOc.getOid() );
     }
 
 
@@ -220,16 +174,21 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
-        ObjectClass at = factory.getObjectClass( targetEntry, targetRegistries );
+        ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries );
 
         if ( ! oldSchema.isDisabled() )
         {
             objectClassRegistry.unregister( oldOc.getOid() );
         }
-
+        unregisterOids( oldOc.getOid() );
+        
         if ( ! newSchema.isDisabled() )
         {
-            objectClassRegistry.register( newSchema.getSchemaName(), at );
+            objectClassRegistry.register( newSchema.getSchemaName(), oc );
+        }
+        else
+        {
+            registerOids( oc );
         }
     }
 

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java?view=diff&rev=495109&r1=495108&r2=495109
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
Wed Jan 10 20:26:32 2007
@@ -20,27 +20,22 @@
 package org.apache.directory.server.core.schema;
 
 
-import java.util.HashSet;
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.server.schema.registries.SyntaxRegistry;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -52,49 +47,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaSyntaxHandler implements SchemaChangeHandler
+public class MetaSyntaxHandler extends AbstractSchemaChangeHandler
 {
-    private static final String OU_OID = "2.5.4.11";
-
-    private final PartitionSchemaLoader loader;
     private final SchemaPartitionDao dao;
-    private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final SyntaxRegistry syntaxRegistry;
-    private final AttributeType m_oidAT;
 
     
-
     public MetaSyntaxHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
         throws NamingException
     {
-        this.targetRegistries = targetRegistries;
+        super( targetRegistries, loader );
+
         this.dao = dao;
-        this.loader = loader;
         this.syntaxRegistry = targetRegistries.getSyntaxRegistry();
-        this.factory = new SchemaEntityFactory( targetRegistries );
-        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
     }
 
-
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = ServerUtils.getAttribute( m_oidAT, entry );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
-    
-    
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
     
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry ) throws
NamingException
     {
         String oldOid = getOid( entry );
         Syntax syntax = factory.getSyntax( targetEntry, targetRegistries );
@@ -107,21 +76,7 @@
         }
     }
 
-
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry )
-        throws NamingException
-    {
-        modify( name, entry, targetEntry );
-    }
-
-
+    
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
@@ -135,24 +90,14 @@
         {
             syntaxRegistry.register( schema.getSchemaName(), syntax );
         }
-    }
-
-
-    private Set<String> getOids( Set<SearchResult> results ) throws NamingException
-    {
-        Set<String> oids = new HashSet<String>( results.size() );
-        
-        for ( SearchResult result : results )
+        else
         {
-            LdapDN dn = new LdapDN( result.getName() );
-            dn.normalize( this.targetRegistries.getAttributeTypeRegistry().getNormalizerMapping()
);
-            oids.add( ( String ) dn.getRdn().getValue() );
+            // even for disabled schemas add OIDs
+            registerOids( syntax );
         }
-        
-        return oids;
     }
-    
-    
+
+
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
         String oid = getOid( entry );
@@ -168,11 +113,13 @@
         }
         
         Schema schema = getSchema( name );
-        
         if ( ! schema.isDisabled() )
         {
-            syntaxRegistry.unregister( getOid( entry ) );
+            syntaxRegistry.unregister( oid );
         }
+
+        // no matter what we remove OID for deleted syntaxes
+        unregisterOids( oid );
     }
 
 
@@ -194,12 +141,21 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        Syntax syntax = factory.getSyntax( targetEntry, targetRegistries );
+        
         if ( ! schema.isDisabled() )
         {
-            Syntax syntax = factory.getSyntax( targetEntry, targetRegistries );
             syntaxRegistry.unregister( oldOid );
             syntaxRegistry.register( schema.getSchemaName(), syntax );
         }
+        else
+        {
+            // even for disabled schemas add OIDs
+            registerOids( syntax );
+        }
+        
+        // always remove old OIDs that are not in schema anymore
+        unregisterOids( oldOid );
     }
 
 
@@ -230,10 +186,17 @@
         {
             syntaxRegistry.unregister( oldOid );
         }
+        // always remove old OIDs that are not in schema anymore
+        unregisterOids( oldOid );
 
         if ( ! newSchema.isDisabled() )
         {
             syntaxRegistry.register( newSchema.getSchemaName(), syntax );
+        }
+        else
+        {
+            // register new syntax OIDs even if schema is disabled 
+            registerOids( syntax );
         }
     }
 



Mime
View raw message