directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r504453 - in /directory/apacheds/trunk: constants/src/main/java/org/apache/directory/server/constants/ core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/schema/
Date Wed, 07 Feb 2007 06:56:44 GMT
Author: akarasulu
Date: Tue Feb  6 22:56:43 2007
New Revision: 504453

URL: http://svn.apache.org/viewvc?view=rev&rev=504453
Log:
Integrating seelmann's new parsers for ComparatorDescriptions, NormalizerDesc-
-riptions and SyntaxCheckerDescriptions.  When modifies are now performed on
the subschemaSubentry these new schema entities can be created, deleted or 
changed.

NOTE: more javadocs and tests to follow tomorrow.


Modified:
    directory/apacheds/trunk/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.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/MetaNormalizerHandler.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/SchemaEntityFactory.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java

Modified: directory/apacheds/trunk/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java (original)
+++ directory/apacheds/trunk/constants/src/main/java/org/apache/directory/server/constants/MetaSchemaConstants.java Tue Feb  6 22:56:43 2007
@@ -67,4 +67,8 @@
     public static final String M_TYPE_OBJECT_CLASS_AT = "m-typeObjectClass";
     
     public static final String X_HUMAN_READIBLE_AT = "x-humanReadible";
+
+    public static final String COMPARATORS_AT = "comparators";
+    public static final String NORMALIZERS_AT = "normalizers";
+    public static final String SYNTAX_CHECKERS_AT = "syntaxCheckers";
 }

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java (original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java Tue Feb  6 22:56:43 2007
@@ -235,7 +235,7 @@
         assertNull( attributeTypeDescription );
 
         attrs = null;
-        attrs = schemaRoot.getAttributes( "oid=1.3.6.1.4.1.18060.0.4.0.2.10000,ou=attributeTypes,cn=nis" );
+        attrs = schemaRoot.getAttributes( "m-oid=1.3.6.1.4.1.18060.0.4.0.2.10000,ou=attributeTypes,cn=nis" );
         assertNotNull( attrs );
         SchemaEntityFactory factory = new SchemaEntityFactory( registries );
         AttributeType at = factory.getAttributeType( attrs, registries, "nis" );
@@ -290,7 +290,7 @@
         assertEquals( "name", attributeTypeDescription.getSuperType() );
         
         attrs = null;
-        attrs = schemaRoot.getAttributes( "oid=1.3.6.1.4.1.18060.0.4.0.2.10000,ou=attributeTypes,cn=nis" );
+        attrs = schemaRoot.getAttributes( "m-oid=1.3.6.1.4.1.18060.0.4.0.2.10000,ou=attributeTypes,cn=nis" );
         assertNotNull( attrs );
         SchemaEntityFactory factory = new SchemaEntityFactory( registries );
         AttributeType at = factory.getAttributeType( attrs, registries, "nis" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java Tue Feb  6 22:56:43 2007
@@ -40,21 +40,27 @@
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
 import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
 import org.apache.directory.shared.ldap.schema.syntax.DITContentRuleDescription;
 import org.apache.directory.shared.ldap.schema.syntax.DITStructureRuleDescription;
 import org.apache.directory.shared.ldap.schema.syntax.LdapSyntaxDescription;
 import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleDescription;
 import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleUseDescription;
 import org.apache.directory.shared.ldap.schema.syntax.NameFormDescription;
+import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
 import org.apache.directory.shared.ldap.schema.syntax.ObjectClassDescription;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.ComparatorDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.DITContentRuleDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.DITStructureRuleDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.LdapSyntaxDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleUseDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.NameFormDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.NormalizerDescriptionSchemaParser;
 import org.apache.directory.shared.ldap.schema.syntax.parser.ObjectClassDescriptionSchemaParser;
+import org.apache.directory.shared.ldap.schema.syntax.parser.SyntaxCheckerDescriptionSchemaParser;
 
 
 /**
@@ -73,6 +79,9 @@
     private static final String X_SCHEMA = "X-SCHEMA";
     private static final Object X_IS_HUMAN_READABLE = "X-IS-HUMAN-READABLE";
 
+    private static final ComparatorDescription[] EMPTY_COMPARATORS = new ComparatorDescription[0];
+    private static final NormalizerDescription[] EMPTY_NORMALIZERS = new NormalizerDescription[0];
+    private static final SyntaxCheckerDescription[] EMPTY_SYNTAX_CHECKERS = new SyntaxCheckerDescription[0];
     private static final Syntax[] EMPTY_SYNTAXES = new Syntax[0];
     private static final MatchingRule[] EMPTY_MATCHING_RULES = new MatchingRule[0];
     private static final AttributeType[] EMPTY_ATTRIBUTE_TYPES = new AttributeType[0];
@@ -84,6 +93,12 @@
 
     private final Registries globalRegistries;
     
+    private final ComparatorDescriptionSchemaParser comparatorParser =
+        new ComparatorDescriptionSchemaParser();
+    private final NormalizerDescriptionSchemaParser normalizerParser =
+        new NormalizerDescriptionSchemaParser();
+    private final SyntaxCheckerDescriptionSchemaParser syntaxCheckerParser =
+        new SyntaxCheckerDescriptionSchemaParser();
     private final LdapSyntaxDescriptionSchemaParser syntaxParser =
         new LdapSyntaxDescriptionSchemaParser();
     private final MatchingRuleDescriptionSchemaParser matchingRuleParser =
@@ -110,6 +125,94 @@
     public DescriptionParsers( Registries globalRegistries )
     {
         this.globalRegistries = globalRegistries;
+    }
+
+    
+    public SyntaxCheckerDescription[] parseSyntaxCheckers( Attribute attr ) throws NamingException
+    {
+        if ( attr == null || attr.size() == 0 )
+        {
+            return EMPTY_SYNTAX_CHECKERS;
+        }
+        
+        SyntaxCheckerDescription[] syntaxCheckerDescriptions = new SyntaxCheckerDescription[attr.size()];
+        
+        for ( int ii = 0; ii < attr.size(); ii++ )
+        {
+            try
+            {
+                syntaxCheckerDescriptions[ii] = 
+                    syntaxCheckerParser.parseSyntaxCheckerDescription( ( String ) attr.get( ii ) );
+            }
+            catch ( ParseException e )
+            {
+                LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( 
+                    "The following does not conform to the syntaxCheckerDescription syntax: " + attr.get( ii ), 
+                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                iave.setRootCause( e );
+                throw iave;
+            }
+        }
+        
+        return syntaxCheckerDescriptions;
+    }
+    
+    
+    public NormalizerDescription[] parseNormalizers( Attribute attr ) throws NamingException
+    {
+        if ( attr == null || attr.size() == 0 )
+        {
+            return EMPTY_NORMALIZERS;
+        }
+        
+        NormalizerDescription[] normalizerDescriptions = new NormalizerDescription[attr.size()];
+        
+        for ( int ii = 0; ii < attr.size(); ii++ )
+        {
+            try
+            {
+                normalizerDescriptions[ii] = normalizerParser.parseNormalizerDescription( ( String ) attr.get( ii ) );
+            }
+            catch ( ParseException e )
+            {
+                LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( 
+                    "The following does not conform to the normalizerDescription syntax: " + attr.get( ii ), 
+                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                iave.setRootCause( e );
+                throw iave;
+            }
+        }
+        
+        return normalizerDescriptions;
+    }
+    
+
+    public ComparatorDescription[] parseComparators( Attribute attr ) throws NamingException
+    {
+        if ( attr == null || attr.size() == 0 )
+        {
+            return EMPTY_COMPARATORS;
+        }
+        
+        ComparatorDescription[] comparatorDescriptions = new ComparatorDescription[attr.size()];
+        
+        for ( int ii = 0; ii < attr.size(); ii++ )
+        {
+            try
+            {
+                comparatorDescriptions[ii] = comparatorParser.parseComparatorDescription( ( String ) attr.get( ii ) );
+            }
+            catch ( ParseException e )
+            {
+                LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( 
+                    "The following does not conform to the comparatorDescription syntax: " + attr.get( ii ), 
+                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                iave.setRootCause( e );
+                throw iave;
+            }
+        }
+        
+        return comparatorDescriptions;
     }
     
 

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?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- 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 Tue Feb  6 22:56:43 2007
@@ -38,6 +38,7 @@
 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.ComparatorDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -53,6 +54,9 @@
 {
     private static final String OU_OID = "2.5.4.11";
 
+    private static final String SCHEMA_OTHER = "other";
+    private static final Object X_SCHEMA = "X-SCHEMA";
+
     private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
     private final Registries targetRegistries;
@@ -133,11 +137,36 @@
             comparatorRegistry.register( schema.getSchemaName(), oid, comparator );
         }
     }
+    
+    
+    public void add( ComparatorDescription comparatorDescription ) throws NamingException
+    {
+        Comparator comparator = factory.getComparator( comparatorDescription, targetRegistries );
+        String schemaName = SCHEMA_OTHER;
+        
+        if ( comparatorDescription.getExtensions().get( X_SCHEMA ) != null )
+        {
+            schemaName = ( String ) comparatorDescription.getExtensions().get( X_SCHEMA ).get( 0 );
+        }
+        
+        Schema schema = loader.getSchema( schemaName );
+        
+        if ( ! schema.isDisabled() )
+        {
+            comparatorRegistry.register( schemaName, comparatorDescription.getNumericOid(), comparator );
+        }
+    }
 
 
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
         String oid = getOid( entry );
+        delete( oid );
+    }
+
+
+    public void delete( String oid ) throws NamingException
+    {
         if ( matchingRuleRegistry.hasMatchingRule( oid ) )
         {
             throw new LdapOperationNotSupportedException( "The comparator with OID " + oid 
@@ -146,15 +175,13 @@
                 ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
         
-        Schema schema = getSchema( name );
-        
-        if ( ! schema.isDisabled() )
+        if ( comparatorRegistry.hasComparator( oid ) )
         {
-            comparatorRegistry.unregister( getOid( entry ) );
+            comparatorRegistry.unregister( oid );
         }
     }
 
-
+    
     public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
     {
         String oldOid = getOid( entry );

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?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- 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 Tue Feb  6 22:56:43 2007
@@ -37,6 +37,7 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -52,6 +53,9 @@
 {
     private static final String OU_OID = "2.5.4.11";
 
+    private static final String SCHEMA_OTHER = "other";
+    private static final Object X_SCHEMA = "X-SCHEMA";
+
     private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
     private final Registries targetRegistries;
@@ -133,10 +137,34 @@
         }
     }
 
+    
+    public void add( NormalizerDescription normalizerDescription ) throws NamingException
+    {
+        Normalizer normalizer = factory.getNormalizer( normalizerDescription, targetRegistries );
+        String schemaName = SCHEMA_OTHER;
+        
+        if ( normalizerDescription.getExtensions().get( X_SCHEMA ) != null )
+        {
+            schemaName = ( String ) normalizerDescription.getExtensions().get( X_SCHEMA ).get( 0 );
+        }
+        
+        Schema schema = loader.getSchema( schemaName );
+        
+        if ( ! schema.isDisabled() )
+        {
+            normalizerRegistry.register( schemaName, normalizerDescription.getNumericOid(), normalizer );
+        }
+    }
+
 
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
-        String oid = getOid( entry );
+        delete( getOid( entry ) );
+    }
+
+
+    public void delete( String oid ) throws NamingException
+    {
         if ( matchingRuleRegistry.hasMatchingRule( oid ) )
         {
             throw new LdapOperationNotSupportedException( "The normalizer with OID " + oid 
@@ -145,14 +173,12 @@
                 ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
         
-        Schema schema = getSchema( name );
-        
-        if ( ! schema.isDisabled() )
+        if ( normalizerRegistry.hasNormalizer( oid ) )
         {
-            normalizerRegistry.unregister( getOid( entry ) );
+            normalizerRegistry.unregister( oid );
         }
     }
-
+    
 
     public void rename( LdapDN name, Attributes entry, String newRdn ) throws NamingException
     {

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?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- 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 Tue Feb  6 22:56:43 2007
@@ -38,6 +38,7 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
@@ -53,6 +54,9 @@
 {
     private static final String OU_OID = "2.5.4.11";
 
+    private static final String SCHEMA_OTHER = "other";
+    private static final Object X_SCHEMA = "X-SCHEMA";
+
     private final PartitionSchemaLoader loader;
     private final SchemaEntityFactory factory;
     private final Registries targetRegistries;
@@ -134,9 +138,33 @@
     }
 
 
+    public void add( SyntaxCheckerDescription syntaxCheckerDescription ) throws NamingException
+    {
+        SyntaxChecker syntaxChecker = factory.getSyntaxChecker( syntaxCheckerDescription, targetRegistries );
+        String schemaName = SCHEMA_OTHER;
+        
+        if ( syntaxCheckerDescription.getExtensions().get( X_SCHEMA ) != null )
+        {
+            schemaName = ( String ) syntaxCheckerDescription.getExtensions().get( X_SCHEMA ).get( 0 );
+        }
+        
+        Schema schema = loader.getSchema( schemaName );
+        
+        if ( ! schema.isDisabled() )
+        {
+            syntaxCheckerRegistry.register( syntaxCheckerDescription.getNumericOid(), syntaxChecker );
+        }
+    }
+
+
     public void delete( LdapDN name, Attributes entry ) throws NamingException
     {
-        String oid = getOid( entry );
+        delete( getOid( entry ) );
+    }
+
+
+    public void delete( String oid ) throws NamingException
+    {
         if ( syntaxRegistry.hasSyntax( oid ) )
         {
             throw new LdapOperationNotSupportedException( "The syntaxChecker with OID " + oid 
@@ -145,11 +173,9 @@
                 ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
         
-        Schema schema = getSchema( name );
-        
-        if ( ! schema.isDisabled() )
+        if ( syntaxCheckerRegistry.hasSyntaxChecker( oid ) )
         {
-            syntaxCheckerRegistry.unregister( getOid( entry ) );
+            syntaxCheckerRegistry.unregister( oid );
         }
     }
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java Tue Feb  6 22:56:43 2007
@@ -30,11 +30,14 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
 
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.constants.SystemSchemaConstants;
 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.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.MutableSchemaObject;
@@ -43,8 +46,12 @@
 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.directory.shared.ldap.util.Base64;
 
 
 /**
@@ -125,108 +132,67 @@
     }
     
     
-    /**
-     * Retrieve and load a syntaxChecker class from the DIT.
-     * 
-     * @param entry the entry to load the syntaxChecker from
-     * @return the loaded SyntaxChecker
-     * @throws NamingException if anything fails during loading
-     */
-    public SyntaxChecker getSyntaxChecker( Attributes entry, Registries targetRegistries ) throws NamingException
+    private SyntaxChecker getSyntaxChecker( String syntaxOid, String className, Attribute bytecode, Registries targetRegistries )
+        throws NamingException
     {
-        if ( entry == null )
-        {
-            throw new NullPointerException( "entry cannot be null" );
-        }
-        
-        if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
-        {
-            throw new NullPointerException( "entry must have a valid "
-                + MetaSchemaConstants.M_FQCN_AT + " attribute" );
-        }
-        
-        String className = ( String ) entry.get( MetaSchemaConstants.M_FQCN_AT ).get();
-        SyntaxChecker syntaxChecker = null;
         Class clazz = null;
-
-        Attribute byteCodeAttr = AttributeUtils.getAttribute( entry, byteCodeAT );
-        if ( byteCodeAttr == null )
+        SyntaxChecker syntaxChecker = null;
+        
+        try
         {
-            try
+            if ( bytecode == null )
             {
                 clazz = Class.forName( className );
             }
-            catch ( ClassNotFoundException e )
-            {
-                NamingException ne = new NamingException( "SyntaxChecker class "+ className + " was not found" );
-                ne.setRootCause( e );
-                throw ne;
-            }
-        }       
-        else
-        {
-            try
+            else
             {
-                Attribute bytecode = AttributeUtils.getAttribute( entry, byteCodeAT );
                 classLoader.setAttribute( bytecode );
                 clazz = classLoader.loadClass( className );
             }
-            catch ( ClassCastException e )
-            {
-                NamingException ne = new NamingException( "Class "+ className + " does not implement SyntaxChecker" );
-                ne.setRootCause( e );
-                throw ne;
-            }
-            catch ( ClassNotFoundException e )
-            {
-                NamingException ne = new NamingException( "SyntaxChecker class "+ className + " was not found" );
-                ne.setRootCause( e );
-                throw ne;
-            }
         }
-        
+        catch ( ClassNotFoundException e )
+        {
+            LdapNamingException ne = new LdapNamingException( 
+                "Normalizer class "+ className + " was not found", ResultCodeEnum.OTHER );
+            ne.setRootCause( e );
+            throw ne;
+        }
         
         try
         {
             syntaxChecker = ( SyntaxChecker ) clazz.newInstance();
         }
-        catch ( ClassCastException e )
-        {
-            NamingException ne = new NamingException( "Class "+ className + " does not implement SyntaxChecker" );
-            ne.setRootCause( e );
-            throw ne;
-        }
         catch ( InstantiationException e )
         {
-            NamingException ne = new NamingException( "Failed to instantiate syntaxChecker class "+ className 
-                + ".\nCheck that a default constructor exists for the class." );
+            LdapNamingException ne = new LdapNamingException( "Failed to instantiate SyntaxChecker class "+ className 
+                + ".\nCheck that a default constructor exists for the class.", ResultCodeEnum.OTHER );
             ne.setRootCause( e );
             throw ne;
         }
         catch ( IllegalAccessException e )
         {
-            NamingException ne = new NamingException( "Failed to instantiate syntaxChecker class "+ className 
-                + ".\nCheck that a **PUBLIC** accessible default constructor exists for the class." );
+            LdapNamingException ne = new LdapNamingException( "Failed to instantiate SyntaxChecker class "+ className 
+                + ".\nCheck that a **PUBLIC** accessible default constructor exists for the class.", 
+                ResultCodeEnum.OTHER );
             ne.setRootCause( e );
             throw ne;
         }
 
         // try now before returning to check if we can inject a Registries object
         injectRegistries( syntaxChecker, targetRegistries );
-        String syntaxOid = ( String ) AttributeUtils.getAttribute( entry, oidAT ).get();
         injectOid( syntaxOid, syntaxChecker );
         return syntaxChecker;
     }
     
     
     /**
-     * Retrieve and load a Comparator class from the DIT.
+     * Retrieve and load a syntaxChecker class from the DIT.
      * 
-     * @param entry the entry to load the Comparator from
-     * @return the loaded Comparator
+     * @param entry the entry to load the syntaxChecker from
+     * @return the loaded SyntaxChecker
      * @throws NamingException if anything fails during loading
      */
-    public Comparator getComparator( Attributes entry, Registries targetRegistries ) throws NamingException
+    public SyntaxChecker getSyntaxChecker( Attributes entry, Registries targetRegistries ) throws NamingException
     {
         if ( entry == null )
         {
@@ -235,15 +201,40 @@
         
         if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
         {
-            throw new NullPointerException( "entry must have a valid " 
+            throw new NullPointerException( "entry must have a valid "
                 + MetaSchemaConstants.M_FQCN_AT + " attribute" );
         }
-        
+
         String className = ( String ) entry.get( MetaSchemaConstants.M_FQCN_AT ).get();
+        String syntaxOid = ( String ) AttributeUtils.getAttribute( entry, oidAT ).get();
+        return getSyntaxChecker( syntaxOid, className, AttributeUtils.getAttribute( entry, byteCodeAT ), 
+            targetRegistries );
+    }
+    
+    
+    public SyntaxChecker getSyntaxChecker( SyntaxCheckerDescription syntaxCheckerDescription, 
+        Registries targetRegistries ) throws NamingException
+    {
+        BasicAttribute attr = null;
+        
+        if ( syntaxCheckerDescription.getBytecode() != null )
+        {
+            byte[] bytecode = Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() );
+            attr = new BasicAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
+        }
+        
+        return getSyntaxChecker( syntaxCheckerDescription.getNumericOid(), 
+            syntaxCheckerDescription.getFqcn(), attr, targetRegistries );
+    }
+    
+    
+    private Comparator getComparator( String className, Attribute bytecode, Registries targetRegistries ) 
+        throws NamingException
+    {
         Comparator comparator = null;
         Class clazz = null;
-
-        if ( entry.get( MetaSchemaConstants.M_BYTECODE_AT ) == null )
+        
+        if ( bytecode == null ) 
         {
             try
             {
@@ -251,44 +242,32 @@
             }
             catch ( ClassNotFoundException e )
             {
-                NamingException ne = new NamingException( "Comparator class "+ className + " was not found" );
+                LdapNamingException ne = new LdapNamingException( "Comparator class "+ className + " was not found",
+                    ResultCodeEnum.OTHER );
                 ne.setRootCause( e );
                 throw ne;
             }
-        }       
+        }
         else
         {
+            classLoader.setAttribute( bytecode );
             try
             {
-                Attribute bytecode = AttributeUtils.getAttribute( entry, byteCodeAT );
-                classLoader.setAttribute( bytecode );
                 clazz = classLoader.loadClass( className );
             }
-            catch ( ClassCastException e )
-            {
-                NamingException ne = new NamingException( "Class "+ className + " does not implement Comparator" );
-                ne.setRootCause( e );
-                throw ne;
-            }
             catch ( ClassNotFoundException e )
             {
-                NamingException ne = new NamingException( "Comparator class "+ className + " was not found" );
+                LdapNamingException ne = new LdapNamingException( "Comparator class "+ className + " was not found",
+                    ResultCodeEnum.OTHER );
                 ne.setRootCause( e );
                 throw ne;
             }
         }
         
-        
         try
         {
             comparator = ( Comparator ) clazz.newInstance();
         }
-        catch ( ClassCastException e )
-        {
-            NamingException ne = new NamingException( "Class "+ className + " does not implement Comparator" );
-            ne.setRootCause( e );
-            throw ne;
-        }
         catch ( InstantiationException e )
         {
             NamingException ne = new NamingException( "Failed to instantiate comparator class "+ className 
@@ -303,21 +282,35 @@
             ne.setRootCause( e );
             throw ne;
         }
-
-        // try now before returning to check if we can inject a Registries object
+        
         injectRegistries( comparator, targetRegistries );
         return comparator;
     }
     
     
+    public Comparator getComparator( ComparatorDescription comparatorDescription, Registries targetRegistries ) 
+        throws NamingException
+    {
+        BasicAttribute attr = null;
+        
+        if ( comparatorDescription.getBytecode() != null )
+        { 
+            byte[] bytecode = Base64.decode( comparatorDescription.getBytecode().toCharArray() );
+            attr = new BasicAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
+        }
+        
+        return getComparator( comparatorDescription.getFqcn(), attr, targetRegistries );
+    }
+    
+    
     /**
-     * Retrieve and load a Normalizer class from the DIT.
+     * Retrieve and load a Comparator class from the DIT.
      * 
-     * @param entry the entry to load the Normalizer from
-     * @return the loaded Normalizer
+     * @param entry the entry to load the Comparator from
+     * @return the loaded Comparator
      * @throws NamingException if anything fails during loading
      */
-    public Normalizer getNormalizer( Attributes entry, Registries targetRegistries ) throws NamingException
+    public Comparator getComparator( Attributes entry, Registries targetRegistries ) throws NamingException
     {
         if ( entry == null )
         {
@@ -331,66 +324,52 @@
         }
         
         String className = ( String ) entry.get( MetaSchemaConstants.M_FQCN_AT ).get();
-        Normalizer normalizer = null;
+        return getComparator( className, entry.get( MetaSchemaConstants.M_BYTECODE_AT ), targetRegistries );
+    }
+    
+    
+    private Normalizer getNormalizer( String className, Attribute bytecode, Registries targetRegistries ) 
+        throws NamingException
+    {
         Class clazz = null;
-
-        if ( entry.get( MetaSchemaConstants.M_BYTECODE_AT ) == null )
+        Normalizer normalizer = null;
+        
+        try
         {
-            try
+            if ( bytecode == null )
             {
                 clazz = Class.forName( className );
             }
-            catch ( ClassNotFoundException e )
-            {
-                NamingException ne = new NamingException( "Normalizer class "+ className + " was not found" );
-                ne.setRootCause( e );
-                throw ne;
-            }
-        }       
-        else
-        {
-            try
+            else
             {
-                Attribute bytecode = AttributeUtils.getAttribute( entry, byteCodeAT );
                 classLoader.setAttribute( bytecode );
                 clazz = classLoader.loadClass( className );
             }
-            catch ( ClassCastException e )
-            {
-                NamingException ne = new NamingException( "Class "+ className + " does not implement Normalizer" );
-                ne.setRootCause( e );
-                throw ne;
-            }
-            catch ( ClassNotFoundException e )
-            {
-                NamingException ne = new NamingException( "Normalizer class "+ className + " was not found" );
-                ne.setRootCause( e );
-                throw ne;
-            }
         }
-        
+        catch ( ClassNotFoundException e )
+        {
+            LdapNamingException ne = new LdapNamingException( 
+                "Normalizer class "+ className + " was not found", ResultCodeEnum.OTHER );
+            ne.setRootCause( e );
+            throw ne;
+        }
         
         try
         {
             normalizer = ( Normalizer ) clazz.newInstance();
         }
-        catch ( ClassCastException e )
-        {
-            NamingException ne = new NamingException( "Class "+ className + " does not implement Normalizer" );
-            ne.setRootCause( e );
-            throw ne;
-        }
         catch ( InstantiationException e )
         {
-            NamingException ne = new NamingException( "Failed to instantiate normalizer class "+ className 
-                + ".\nCheck that a default constructor exists for the class." );
+            LdapNamingException ne = new LdapNamingException( "Failed to instantiate normalizer class "+ className 
+                + ".\nCheck that a default constructor exists for the class.", ResultCodeEnum.OTHER );
             ne.setRootCause( e );
             throw ne;
         }
         catch ( IllegalAccessException e )
         {
-            NamingException ne = new NamingException( "Failed to instantiate normalizer class "+ className 
-                + ".\nCheck that a **PUBLIC** accessible default constructor exists for the class." );
+            LdapNamingException ne = new LdapNamingException( "Failed to instantiate normalizer class "+ className 
+                + ".\nCheck that a **PUBLIC** accessible default constructor exists for the class.", 
+                ResultCodeEnum.OTHER );
             ne.setRootCause( e );
             throw ne;
         }
@@ -398,6 +377,46 @@
         // try now before returning to check if we can inject a Registries object
         injectRegistries( normalizer, targetRegistries );
         return normalizer;
+    }
+
+    
+    public Normalizer getNormalizer( NormalizerDescription normalizerDescription, Registries targetRegistries )
+        throws NamingException
+    {
+        BasicAttribute attr = null;
+        
+        if ( normalizerDescription.getBytecode() != null )
+        {
+            byte[] bytecode = Base64.decode( normalizerDescription.getBytecode().toCharArray() );
+            attr = new BasicAttribute( MetaSchemaConstants.M_BYTECODE_AT, bytecode );
+        }
+        
+        return getNormalizer( normalizerDescription.getFqcn(), attr, targetRegistries );
+    }
+    
+    
+    /**
+     * Retrieve and load a Normalizer class from the DIT.
+     * 
+     * @param entry the entry to load the Normalizer from
+     * @return the loaded Normalizer
+     * @throws NamingException if anything fails during loading
+     */
+    public Normalizer getNormalizer( Attributes entry, Registries targetRegistries ) throws NamingException
+    {
+        if ( entry == null )
+        {
+            throw new NullPointerException( "entry cannot be null" );
+        }
+        
+        if ( entry.get( MetaSchemaConstants.M_FQCN_AT ) == null )
+        {
+            throw new NullPointerException( "entry must have a valid " 
+                + MetaSchemaConstants.M_FQCN_AT + " attribute" );
+        }
+        
+        String className = ( String ) entry.get( MetaSchemaConstants.M_FQCN_AT ).get();
+        return getNormalizer( className, entry.get( MetaSchemaConstants.M_BYTECODE_AT ), targetRegistries );
     }
     
     

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java Tue Feb  6 22:56:43 2007
@@ -53,6 +53,10 @@
 import org.apache.directory.shared.ldap.schema.NameForm;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 
 
@@ -111,6 +115,8 @@
         "metaDITContentRule",
         "metaNameForm"
     };
+    private static final Object X_SCHEMA = null;
+    private static final String SCHEMA_OTHER = null;
 
     private final PartitionSchemaLoader loader;
     private final MetaSchemaHandler metaSchemaHandler;
@@ -119,9 +125,9 @@
     private final SchemaSubentryModifier subentryModifier;
     private final SchemaChangeHandler[] schemaObjectHandlers = new SchemaChangeHandler[11];
 
-//    private final String comparatorsOid;
-//    private final String normalizersOid;
-//    private final String syntaxCheckersOid;
+    private final String comparatorsOid;
+    private final String normalizersOid;
+    private final String syntaxCheckersOid;
 
     private final String ldapSyntaxesOid;
     private final String matchingRulesOid;
@@ -185,6 +191,16 @@
         this.parsers = new DescriptionParsers( globalRegistries );
         
         OidRegistry oidRegistry = globalRegistries.getOidRegistry();
+        
+        comparatorsOid = oidRegistry.getOid( MetaSchemaConstants.COMPARATORS_AT );
+        opAttr2handlerIndex.put( comparatorsOid, new Integer( COMPARATOR_INDEX ) );
+        
+        normalizersOid = oidRegistry.getOid( MetaSchemaConstants.NORMALIZERS_AT );
+        opAttr2handlerIndex.put( normalizersOid, new Integer( NORMALIZER_INDEX ) );
+        
+        syntaxCheckersOid = oidRegistry.getOid( MetaSchemaConstants.SYNTAX_CHECKERS_AT );
+        opAttr2handlerIndex.put( syntaxCheckersOid, new Integer( SYNTAX_CHECKER_INDEX ) );
+        
         ldapSyntaxesOid = oidRegistry.getOid( SystemSchemaConstants.LDAP_SYNTAXES_AT );
         opAttr2handlerIndex.put( ldapSyntaxesOid, new Integer( SYNTAX_INDEX ) );
         
@@ -563,10 +579,55 @@
         switch( index )
         {
             case( COMPARATOR_INDEX ):
+                MetaComparatorHandler comparatorHandler = ( MetaComparatorHandler ) handler;
+                ComparatorDescription[] removedComparators = parsers.parseComparators( original );
+                ComparatorDescription[] addedComparators = parsers.parseComparators( mods );
+                
+                for ( ComparatorDescription comparatorDescription : removedComparators )
+                {
+                    comparatorHandler.delete( comparatorDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( comparatorDescription ), comparatorDescription );
+                }
+                
+                for ( ComparatorDescription comparatorDescription : addedComparators )
+                {
+                    comparatorHandler.add( comparatorDescription );
+                    subentryModifier.add( getSchema( comparatorDescription ), comparatorDescription );
+                }
                 break;
             case( NORMALIZER_INDEX ):
+                MetaNormalizerHandler normalizerHandler = ( MetaNormalizerHandler ) handler;
+                NormalizerDescription[] removedNormalizers = parsers.parseNormalizers( original );
+                NormalizerDescription[] addedNormalizers = parsers.parseNormalizers( mods );
+                
+                for ( NormalizerDescription normalizerDescription : removedNormalizers )
+                {
+                    normalizerHandler.delete( normalizerDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( normalizerDescription ), normalizerDescription );
+                }
+                
+                for ( NormalizerDescription normalizerDescription : addedNormalizers )
+                {
+                    normalizerHandler.add( normalizerDescription );
+                    subentryModifier.add( getSchema( normalizerDescription ), normalizerDescription );
+                }
                 break;
             case( SYNTAX_CHECKER_INDEX ):
+                MetaSyntaxCheckerHandler syntaxCheckerHandler = ( MetaSyntaxCheckerHandler ) handler;
+                SyntaxCheckerDescription[] removedSyntaxCheckers = parsers.parseSyntaxCheckers( original );
+                SyntaxCheckerDescription[] addedSyntaxCheckers = parsers.parseSyntaxCheckers( mods );
+                
+                for ( SyntaxCheckerDescription syntaxCheckerDescription : removedSyntaxCheckers )
+                {
+                    syntaxCheckerHandler.delete( syntaxCheckerDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription );
+                }
+                
+                for ( SyntaxCheckerDescription syntaxCheckerDescription : addedSyntaxCheckers )
+                {
+                    syntaxCheckerHandler.add( syntaxCheckerDescription );
+                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription );
+                }
                 break;
             case( SYNTAX_INDEX ):
                 MetaSyntaxHandler syntaxHandler = ( MetaSyntaxHandler ) handler;
@@ -709,6 +770,17 @@
         }
     }
 
+    
+    public String getSchema( AbstractSchemaDescription desc ) 
+    {
+        if ( desc.getExtensions().containsKey( X_SCHEMA ) )
+        {
+            return desc.getExtensions().get( X_SCHEMA ).get( 0 );
+        }
+        
+        return SCHEMA_OTHER;
+    }
+    
 
     /**
      * Handles the modify remove operation on the subschemaSubentry for schema entities. 
@@ -725,10 +797,34 @@
         switch( index )
         {
             case( COMPARATOR_INDEX ):
+                MetaComparatorHandler comparatorHandler = ( MetaComparatorHandler ) handler;
+                ComparatorDescription[] comparatorDescriptions = parsers.parseComparators( mods );
+                
+                for ( ComparatorDescription comparatorDescription : comparatorDescriptions )
+                {
+                    comparatorHandler.delete( comparatorDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( comparatorDescription ), comparatorDescription );
+                }
                 break;
             case( NORMALIZER_INDEX ):
+                MetaNormalizerHandler normalizerHandler = ( MetaNormalizerHandler ) handler;
+                NormalizerDescription[] normalizerDescriptions = parsers.parseNormalizers( mods );
+                
+                for ( NormalizerDescription normalizerDescription : normalizerDescriptions )
+                {
+                    normalizerHandler.delete( normalizerDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( normalizerDescription ), normalizerDescription );
+                }
                 break;
             case( SYNTAX_CHECKER_INDEX ):
+                MetaSyntaxCheckerHandler syntaxCheckerHandler = ( MetaSyntaxCheckerHandler ) handler;
+                SyntaxCheckerDescription[] syntaxCheckerDescriptions = parsers.parseSyntaxCheckers( mods );
+                
+                for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions )
+                {
+                    syntaxCheckerHandler.delete( syntaxCheckerDescription.getNumericOid() );
+                    subentryModifier.delete( getSchema( syntaxCheckerDescription ), syntaxCheckerDescription );
+                }
                 break;
             case( SYNTAX_INDEX ):
                 MetaSyntaxHandler syntaxHandler = ( MetaSyntaxHandler ) handler;
@@ -831,10 +927,31 @@
         switch( index )
         {
             case( COMPARATOR_INDEX ):
+                MetaComparatorHandler comparatorHandler = ( MetaComparatorHandler ) handler;
+                ComparatorDescription[] comparatorDescriptions = parsers.parseComparators( mods );
+                
+                for ( ComparatorDescription comparatorDescription : comparatorDescriptions )
+                {
+                    comparatorHandler.add( comparatorDescription );
+                }
                 break;
             case( NORMALIZER_INDEX ):
+                MetaNormalizerHandler normalizerHandler = ( MetaNormalizerHandler ) handler;
+                NormalizerDescription[] normalizerDescriptions = parsers.parseNormalizers( mods );
+                
+                for ( NormalizerDescription normalizerDescription : normalizerDescriptions )
+                {
+                    normalizerHandler.add( normalizerDescription );
+                }
                 break;
             case( SYNTAX_CHECKER_INDEX ):
+                MetaSyntaxCheckerHandler syntaxCheckerHandler = ( MetaSyntaxCheckerHandler ) handler;
+                SyntaxCheckerDescription[] syntaxCheckerDescriptions = parsers.parseSyntaxCheckers( mods );
+                
+                for ( SyntaxCheckerDescription syntaxCheckerDescription : syntaxCheckerDescriptions )
+                {
+                    syntaxCheckerHandler.add( syntaxCheckerDescription );
+                }
                 break;
             case( SYNTAX_INDEX ):
                 MetaSyntaxHandler syntaxHandler = ( MetaSyntaxHandler ) handler;

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java?view=diff&rev=504453&r1=504452&r2=504453
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java Tue Feb  6 22:56:43 2007
@@ -27,10 +27,13 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
 import org.apache.directory.server.core.invocation.InvocationStack;
 import org.apache.directory.server.core.partition.PartitionNexusProxy;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.utils.AttributesFactory;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.DITContentRule;
@@ -41,6 +44,10 @@
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
+import org.apache.directory.shared.ldap.util.Base64;
 
 
 /**
@@ -79,7 +86,7 @@
     private LdapDN getDn( SchemaObject obj ) throws NamingException
     {
         StringBuffer buf = new StringBuffer();
-        buf.append( "oid=" ).append( obj.getOid() ).append( ",ou=" );
+        buf.append( "m-oid=" ).append( obj.getOid() ).append( ",ou=" );
 
         if ( obj instanceof Syntax )
         {
@@ -134,5 +141,131 @@
         PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
         LdapDN dn = getDn( obj );
         proxy.delete( dn, BYPASS );
+    }
+
+
+    public void delete( String schemaName, NormalizerDescription normalizerDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + normalizerDescription.getNumericOid() + ",ou=normalizers,cn=" 
+            + schemaName + ",ou=schema" );
+        proxy.delete( dn, BYPASS );
+    }
+
+
+    public void delete( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + syntaxCheckerDescription.getNumericOid() + ",ou=syntaxCheckers,cn=" 
+            + schemaName + ",ou=schema" );
+        proxy.delete( dn, BYPASS );
+    }
+
+
+    public void delete( String schemaName, ComparatorDescription comparatorDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + comparatorDescription.getNumericOid() + ",ou=comparators,cn=" 
+            + schemaName + ",ou=schema" );
+        proxy.delete( dn, BYPASS );
+    }
+
+
+    public void add( String schemaName, ComparatorDescription comparatorDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + comparatorDescription.getNumericOid() + ",ou=comparators,cn=" 
+            + schemaName + ",ou=schema" );
+        Attributes attrs = getAttributes( schemaName, comparatorDescription );
+        proxy.add( dn, attrs, BYPASS );
+    }
+    
+    
+    private Attributes getAttributes( String schemaName, ComparatorDescription comparatorDescription )
+    {
+        AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top", true );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaComparator" );
+        attributes.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getNumericOid() );
+        attributes.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() );
+
+        if ( comparatorDescription.getBytecode() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_BYTECODE_AT, 
+                Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
+        }
+        
+        if ( comparatorDescription.getDescription() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() );
+        }
+        
+        return attributes;
+    }
+
+
+    public void add( String schemaName, NormalizerDescription normalizerDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + normalizerDescription.getNumericOid() + ",ou=normalizers,cn=" 
+            + schemaName + ",ou=schema" );
+        Attributes attrs = getAttributes( schemaName, normalizerDescription );
+        proxy.add( dn, attrs, BYPASS );
+    }
+    
+    
+    private Attributes getAttributes( String schemaName, NormalizerDescription normalizerDescription )
+    {
+        AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top", true );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaNormalizer" );
+        attributes.put( MetaSchemaConstants.M_OID_AT, normalizerDescription.getNumericOid() );
+        attributes.put( MetaSchemaConstants.M_FQCN_AT, normalizerDescription.getFqcn() );
+
+        if ( normalizerDescription.getBytecode() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_BYTECODE_AT, 
+                Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
+        }
+        
+        if ( normalizerDescription.getDescription() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_DESCRIPTION_AT, normalizerDescription.getDescription() );
+        }
+        
+        return attributes;
+    }
+
+
+    public void add( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription ) throws NamingException
+    {
+        PartitionNexusProxy proxy = InvocationStack.getInstance().peek().getProxy();
+        LdapDN dn = new LdapDN( "m-oid=" + syntaxCheckerDescription.getNumericOid() + ",ou=syntaxCheckers,cn=" 
+            + schemaName + ",ou=schema" );
+        Attributes attrs = getAttributes( schemaName, syntaxCheckerDescription );
+        proxy.add( dn, attrs, BYPASS );
+    }
+    
+    
+    private Attributes getAttributes( String schemaName, SyntaxCheckerDescription syntaxCheckerDescription )
+    {
+        AttributesImpl attributes = new AttributesImpl( SystemSchemaConstants.OBJECT_CLASS_AT, "top", true );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaTop" );
+        attributes.get( SystemSchemaConstants.OBJECT_CLASS_AT ).add( "metaSyntaxChecker" );
+        attributes.put( MetaSchemaConstants.M_OID_AT, syntaxCheckerDescription.getNumericOid() );
+        attributes.put( MetaSchemaConstants.M_FQCN_AT, syntaxCheckerDescription.getFqcn() );
+
+        if ( syntaxCheckerDescription.getBytecode() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_BYTECODE_AT, 
+                Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
+        }
+        
+        if ( syntaxCheckerDescription.getDescription() != null )
+        {
+            attributes.put( MetaSchemaConstants.M_DESCRIPTION_AT, syntaxCheckerDescription.getDescription() );
+        }
+        
+        return attributes;
     }
 }



Mime
View raw message