directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r569837 - /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/
Date Sun, 26 Aug 2007 16:42:27 GMT
Author: akarasulu
Date: Sun Aug 26 09:42:26 2007
New Revision: 569837

URL: http://svn.apache.org/viewvc?rev=569837&view=rev
Log:
really fixing DIRSERVER-904 properly for all schema entity types

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/AbstractSchemaChangeHandler.java
Sun Aug 26 09:42:26 2007
@@ -31,7 +31,9 @@
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 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.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
@@ -58,6 +60,40 @@
         this.loader = loader;
         this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
         this.factory = new SchemaEntityFactory( targetRegistries );
+    }
+    
+    
+    protected void checkOidIsUnique( Attributes entry ) throws NamingException
+    {
+        String oid = getOid( entry );
+        
+        if ( targetRegistries.getOidRegistry().hasOid( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema entity is not
unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+    
+    protected void checkOidIsUnique( SchemaObject schemaObject ) throws NamingException
+    {
+        String oid = schemaObject.getOid();
+        
+        if ( targetRegistries.getOidRegistry().hasOid( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema entity is not
unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+    
+    
+    protected void checkOidIsUnique( String oid ) throws NamingException
+    {
+        if ( targetRegistries.getOidRegistry().hasOid( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema entity is not
unique.", 
+                ResultCodeEnum.OTHER );
+        }
     }
     
     

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandler.java
Sun Aug 26 09:42:26 2007
@@ -68,13 +68,13 @@
     protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean
cascade ) 
         throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Schema schema = getSchema( name );
         AttributeType at = factory.getAttributeType( targetEntry, targetRegistries, schema.getSchemaName()
);
         
         if ( ! schema.isDisabled() )
         {
-            attributeTypeRegistry.unregister( oldOid );
+            attributeTypeRegistry.unregister( oid );
             attributeTypeRegistry.register( at );
         }
     }
@@ -99,6 +99,7 @@
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        checkOidIsUnique( entry );
         
         Schema schema = getSchema( name );
         AttributeType at = factory.getAttributeType( entry, targetRegistries, schema.getSchemaName()
);
@@ -151,6 +152,7 @@
 
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
+        checkOidIsUnique( newOid );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         AttributeType at = factory.getAttributeType( targetEntry, targetRegistries, schema.getSchemaName()
);
 
@@ -188,6 +190,7 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        checkOidIsUnique( newOid );
         AttributeType at = factory.getAttributeType( targetEntry, targetRegistries, newSchema.getSchemaName()
);
 
         if ( ! oldSchema.isDisabled() )

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaComparatorHandler.java
Sun Aug 26 09:42:26 2007
@@ -35,8 +35,8 @@
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
-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;
@@ -54,14 +54,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaComparatorHandler implements SchemaChangeHandler
+public class MetaComparatorHandler extends AbstractSchemaChangeHandler
 {
-    private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final ComparatorRegistry comparatorRegistry;
     private final MatchingRuleRegistry matchingRuleRegistry;
-    private final AttributeType oidAT;
     private final AttributeType byteCodeAT;
     private final AttributeType descAT;
     private final AttributeType fqcnAT;
@@ -70,44 +67,25 @@
 
     public MetaComparatorHandler( Registries targetRegistries, PartitionSchemaLoader loader
) throws NamingException
     {
-        this.targetRegistries = targetRegistries;
-        this.loader = loader;
+        super( targetRegistries, loader );
         this.comparatorRegistry = targetRegistries.getComparatorRegistry();
         this.matchingRuleRegistry = targetRegistries.getMatchingRuleRegistry();
         this.factory = new SchemaEntityFactory( targetRegistries );
-        this.oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
         this.byteCodeAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_BYTECODE_AT
);
         this.descAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DESCRIPTION_AT
);
         this.fqcnAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_FQCN_AT
);
     }
 
-
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = AttributeUtils.getAttribute( entry, oidAT );
-        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, boolean cascade
) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean
cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Comparator comparator = factory.getComparator( targetEntry, targetRegistries );
         Schema schema = getSchema( name );
         
         if ( ! schema.isDisabled() )
         {
-            comparatorRegistry.unregister( oldOid );
+            comparatorRegistry.unregister( oid );
             ComparatorDescription description = getComparatorDescription( schema.getSchemaName(),
targetEntry );
             comparatorRegistry.register( description, comparator );
         }
@@ -140,25 +118,12 @@
     }
     
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, Attributes
targetEntry, 
-        boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry, 
-        boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        checkOidIsUniqueForComparator( entry );
         
         Comparator comparator = factory.getComparator( entry, targetRegistries );
         Schema schema = getSchema( name );
@@ -227,6 +192,7 @@
         }
 
         String oid = NamespaceTools.getRdnValue( newRdn );
+        checkOidIsUniqueForComparator( oid );
         Schema schema = getSchema( name );
         
         if ( ! schema.isDisabled() )
@@ -255,7 +221,8 @@
         }
 
         String oid = NamespaceTools.getRdnValue( newRn );
-
+        checkOidIsUniqueForComparator( oid );
+        
         Schema oldSchema = getSchema( oriChildName );
         Schema newSchema = getSchema( newParentName );
         
@@ -307,6 +274,28 @@
     }
     
     
+    private void checkOidIsUniqueForComparator( String oid ) throws NamingException
+    {
+        if ( super.targetRegistries.getComparatorRegistry().hasComparator( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema comparator is
not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+
+    private void checkOidIsUniqueForComparator( Attributes entry ) throws NamingException
+    {
+        String oid = getOid( entry );
+        
+        if ( super.targetRegistries.getComparatorRegistry().hasComparator( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema comparator is
not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+
     private void checkNewParent( LdapDN newParent ) throws NamingException
     {
         if ( newParent.size() != 3 )

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandler.java
Sun Aug 26 09:42:26 2007
@@ -67,13 +67,13 @@
     protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, 
         boolean cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Schema schema = getSchema( name );
         MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries, schema.getSchemaName()
);
         
         if ( ! schema.isDisabled() )
         {
-            matchingRuleRegistry.unregister( oldOid );
+            matchingRuleRegistry.unregister( oid );
             matchingRuleRegistry.register( mr );
         }
     }
@@ -84,6 +84,7 @@
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        checkOidIsUnique( entry );
         
         String schemaName = getSchemaName( name );
         MatchingRule mr = factory.getMatchingRule( entry, targetRegistries, schemaName );
@@ -136,6 +137,8 @@
 
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
+        checkOidIsUnique( newOid );
+        
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries, schema.getSchemaName()
);
 
@@ -172,6 +175,8 @@
         Schema newSchema = getSchema( newParentName );
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRn );
+        checkOidIsUnique( newOid );
+        
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         MatchingRule mr = factory.getMatchingRule( targetEntry, targetRegistries, newSchema.getSchemaName()
);
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaNormalizerHandler.java
Sun Aug 26 09:42:26 2007
@@ -34,8 +34,8 @@
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
-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;
@@ -54,14 +54,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaNormalizerHandler implements SchemaChangeHandler
+public class MetaNormalizerHandler extends AbstractSchemaChangeHandler
 {
-    private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final NormalizerRegistry normalizerRegistry;
     private final MatchingRuleRegistry matchingRuleRegistry;
-    private final AttributeType oidAT;
     private final AttributeType byteCodeAT;
     private final AttributeType descAT;
     private final AttributeType fqcnAT;
@@ -69,33 +66,16 @@
 
     public MetaNormalizerHandler( Registries targetRegistries, PartitionSchemaLoader loader
) throws NamingException
     {
-        this.targetRegistries = targetRegistries;
-        this.loader = loader;
+        super( targetRegistries, loader );
         this.normalizerRegistry = targetRegistries.getNormalizerRegistry();
         this.matchingRuleRegistry = targetRegistries.getMatchingRuleRegistry();
         this.factory = new SchemaEntityFactory( targetRegistries );
-        this.oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
         this.byteCodeAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_BYTECODE_AT
);
         this.descAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DESCRIPTION_AT
);
         this.fqcnAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_FQCN_AT
);
     }
 
 
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
-    
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = AttributeUtils.getAttribute( entry, oidAT );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
     
     
     private NormalizerDescription getNormalizerDescription( String schemaName, Attributes
entry ) throws NamingException
@@ -124,15 +104,15 @@
     }
     
     
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean cascade
) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean
cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Normalizer normalizer = factory.getNormalizer( targetEntry, targetRegistries );
         Schema schema = getSchema( name );
         
         if ( ! schema.isDisabled() )
         {
-            normalizerRegistry.unregister( oldOid );
+            normalizerRegistry.unregister( oid );
             NormalizerDescription normalizerDescription = getNormalizerDescription( schema.getSchemaName(),

                 targetEntry );
             normalizerRegistry.register( normalizerDescription, normalizer );
@@ -140,25 +120,12 @@
     }
 
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, 
-        Attributes targetEntry, boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, Attributes
targetEntry, 
-        boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        checkOidIsUniqueForNormalizer( entry );
         
         Normalizer normalizer = factory.getNormalizer( entry, targetRegistries );
         Schema schema = getSchema( name );
@@ -226,6 +193,8 @@
         }
 
         String oid = NamespaceTools.getRdnValue( newRdn );
+        checkOidIsUniqueForNormalizer( oid );
+        
         Schema schema = getSchema( name );
         
         if ( ! schema.isDisabled() )
@@ -255,7 +224,8 @@
         }
 
         String oid = NamespaceTools.getRdnValue( newRn );
-
+        checkOidIsUniqueForNormalizer( oid );
+        
         Schema oldSchema = getSchema( oriChildName );
         Schema newSchema = getSchema( newParentName );
         
@@ -307,6 +277,28 @@
     }
 
     
+    private void checkOidIsUniqueForNormalizer( String oid ) throws NamingException
+    {
+        if ( super.targetRegistries.getNormalizerRegistry().hasNormalizer( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema normalizer is
not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+
+    private void checkOidIsUniqueForNormalizer( Attributes entry ) throws NamingException
+    {
+        String oid = getOid( entry );
+        
+        if ( super.targetRegistries.getNormalizerRegistry().hasNormalizer( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema normalizer is
not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+    }
+
+
     private void checkNewParent( LdapDN newParent ) throws NamingException
     {
         if ( newParent.size() != 3 )

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
Sun Aug 26 09:42:26 2007
@@ -29,21 +29,15 @@
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.ObjectClassRegistry;
-import org.apache.directory.server.schema.registries.OidRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
-import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
-import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 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.schema.syntax.AttributeTypeUsageSyntaxChecker;
-import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
 
@@ -58,8 +52,6 @@
 {
     private final SchemaPartitionDao dao;
     private final ObjectClassRegistry objectClassRegistry;
-    private final OidRegistry oidRegistry;
-    private final AttributeType m_oidAT;
 
 
     public MetaObjectClassHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
@@ -69,21 +61,19 @@
         
         this.dao = dao;
         this.objectClassRegistry = targetRegistries.getObjectClassRegistry();
-        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT_OID
);
-        this.oidRegistry = targetRegistries.getOidRegistry();
     }
 
 
     protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, 
         boolean cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Schema schema = getSchema( name );
         ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries, schema.getSchemaName()
);
 
         if ( ! schema.isDisabled() )
         {
-            objectClassRegistry.unregister( oldOid );
+            objectClassRegistry.unregister( oid );
             objectClassRegistry.register( oc );
         }
     }
@@ -94,13 +84,7 @@
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
-        String oid = ( String ) AttributeUtils.getAttribute( entry, m_oidAT ).get();
-        
-        if ( oidRegistry.hasOid( oid ) )
-        {
-            throw new LdapNamingException( "Oid " + oid + " for new objectClass is not unique.",

-                ResultCodeEnum.OTHER );
-        }
+        checkOidIsUnique( entry );
         
         String schemaName = getSchemaName( name );
         ObjectClass oc = factory.getObjectClass( entry, targetRegistries, schemaName );
@@ -156,6 +140,7 @@
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
+        checkOidIsUnique( newOid );
         ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries, schema.getSchemaName()
);
 
         if ( ! schema.isDisabled() )
@@ -191,6 +176,7 @@
         Schema newSchema = getSchema( newParentName );
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRn );
+        checkOidIsUnique( newOid );
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         ObjectClass oc = factory.getObjectClass( targetEntry, targetRegistries, newSchema.getSchemaName()
);
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandler.java?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandler.java
Sun Aug 26 09:42:26 2007
@@ -34,9 +34,9 @@
 import org.apache.directory.server.schema.registries.SyntaxRegistry;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 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;
@@ -55,14 +55,11 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MetaSyntaxCheckerHandler implements SchemaChangeHandler
+public class MetaSyntaxCheckerHandler extends AbstractSchemaChangeHandler
 {
-    private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
-    private final Registries targetRegistries;
     private final SyntaxCheckerRegistry syntaxCheckerRegistry;
     private final SyntaxRegistry syntaxRegistry;
-    private final AttributeType oidAT;
     private final AttributeType byteCodeAT;
     private final AttributeType descAT;
     private final AttributeType fqcnAT;
@@ -70,29 +67,16 @@
 
     public MetaSyntaxCheckerHandler( Registries targetRegistries, PartitionSchemaLoader loader
) throws NamingException
     {
-        this.targetRegistries = targetRegistries;
-        this.loader = loader;
+        super( targetRegistries, loader );
         this.syntaxCheckerRegistry = targetRegistries.getSyntaxCheckerRegistry();
         this.syntaxRegistry = targetRegistries.getSyntaxRegistry();
         this.factory = new SchemaEntityFactory( targetRegistries );
-        this.oidAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_OID_AT
);
         this.byteCodeAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_BYTECODE_AT
);
         this.descAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_DESCRIPTION_AT
);
         this.fqcnAT = targetRegistries.getAttributeTypeRegistry().lookup( MetaSchemaConstants.M_FQCN_AT
);
     }
 
 
-    private String getOid( Attributes entry ) throws NamingException
-    {
-        Attribute oid = AttributeUtils.getAttribute( entry, oidAT );
-        if ( oid == null )
-        {
-            return null;
-        }
-        return ( String ) oid.get();
-    }
-    
-    
     private SyntaxCheckerDescription getSyntaxCheckerDescription( String schemaName, Attributes
entry ) 
         throws NamingException
     {
@@ -120,21 +104,16 @@
     }
 
     
-    private Schema getSchema( LdapDN name ) throws NamingException
-    {
-        return loader.getSchema( MetaSchemaUtils.getSchemaName( name ) );
-    }
-    
-    
-    private void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean cascade
) throws NamingException
+    protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, boolean
cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( targetEntry, targetRegistries
);
+        
         Schema schema = getSchema( name );
         
         if ( ! schema.isDisabled() )
         {
-            syntaxCheckerRegistry.unregister( oldOid );
+            syntaxCheckerRegistry.unregister( oid );
             SyntaxCheckerDescription syntaxCheckerDescription = 
                 getSyntaxCheckerDescription( schema.getSchemaName(), targetEntry );
             syntaxCheckerRegistry.register( syntaxCheckerDescription, syntaxChecker );
@@ -142,25 +121,17 @@
     }
 
 
-    public void modify( LdapDN name, int modOp, Attributes mods, Attributes entry, 
-        Attributes targetEntry, boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
-    public void modify( LdapDN name, ModificationItemImpl[] mods, Attributes entry, 
-        Attributes targetEntry, boolean cascade ) throws NamingException
-    {
-        modify( name, entry, targetEntry, cascade );
-    }
-
-
     public void add( LdapDN name, Attributes entry ) throws NamingException
     {
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        String oid = getOid( entry );
+        if ( super.targetRegistries.getSyntaxCheckerRegistry().hasSyntaxChecker( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new schema syntaxChecker
is not unique.", 
+                ResultCodeEnum.OTHER );
+        }
         
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( entry, targetRegistries );
         Schema schema = getSchema( name );
@@ -232,6 +203,12 @@
         Schema schema = getSchema( name );
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
+        if ( super.targetRegistries.getSyntaxCheckerRegistry().hasSyntaxChecker( newOid )
)
+        {
+            throw new LdapNamingException( "Oid " + newOid + " for new schema syntaxChecker
is not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         if ( ! schema.isDisabled() )
         {
@@ -262,7 +239,14 @@
         Schema oldSchema = getSchema( oriChildName );
         Schema newSchema = getSchema( newParentName );
         Attributes targetEntry = ( Attributes ) entry.clone();
+        
         String newOid = NamespaceTools.getRdnValue( newRn );
+        if ( super.targetRegistries.getSyntaxCheckerRegistry().hasSyntaxChecker( newOid )
)
+        {
+            throw new LdapNamingException( "Oid " + newOid + " for new schema syntaxChecker
is not unique.", 
+                ResultCodeEnum.OTHER );
+        }
+
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         SyntaxChecker syntaxChecker = factory.getSyntaxChecker( targetEntry, targetRegistries
);
 

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?rev=569837&r1=569836&r2=569837&view=diff
==============================================================================
--- 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 Aug 26 09:42:26 2007
@@ -67,13 +67,13 @@
     protected void modify( LdapDN name, Attributes entry, Attributes targetEntry, 
         boolean cascade ) throws NamingException
     {
-        String oldOid = getOid( entry );
+        String oid = getOid( entry );
         Schema schema = getSchema( name );
         Syntax syntax = factory.getSyntax( targetEntry, targetRegistries, schema.getSchemaName()
);
         
         if ( ! schema.isDisabled() )
         {
-            syntaxRegistry.unregister( oldOid );
+            syntaxRegistry.unregister( oid );
             syntaxRegistry.register( syntax );
         }
     }
@@ -84,6 +84,7 @@
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        checkOidIsUnique( entry );
         
         String schemaName = getSchemaName( name );
         Syntax syntax = factory.getSyntax( entry, targetRegistries, schemaName );
@@ -142,6 +143,8 @@
         Schema schema = getSchema( name );
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRdn );
+        checkOidIsUnique( newOid );
+        
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         Syntax syntax = factory.getSyntax( targetEntry, targetRegistries, schema.getSchemaName()
);
         
@@ -181,6 +184,8 @@
         Schema newSchema = getSchema( newParentName );
         Attributes targetEntry = ( Attributes ) entry.clone();
         String newOid = NamespaceTools.getRdnValue( newRn );
+        checkOidIsUnique( newOid );
+        
         targetEntry.put( new AttributeImpl( MetaSchemaConstants.M_OID_AT, newOid ) );
         Syntax syntax = factory.getSyntax( targetEntry, targetRegistries, newSchema.getSchemaName()
);
 
@@ -208,7 +213,7 @@
     {
         checkNewParent( newParentName );
         String oid = getOid( entry );
-
+        
         Set<SearchResult> dependees = dao.listSyntaxDependents( oid );
         if ( dependees != null && dependees.size() > 0 )
         {



Mime
View raw message