directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r487941 - in /directory/branches/trunks/schema/apacheds: bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/ core/src/main/java/org/apache/directory/server/core/schema/ schema-bootstrap/src/main/schema/
Date Sun, 17 Dec 2006 04:47:09 GMT
Author: akarasulu
Date: Sat Dec 16 20:47:09 2006
New Revision: 487941

URL: http://svn.apache.org/viewvc?view=rev&rev=487941
Log:
changes ...

 o implemented loading for:
	- comparators
	- syntaxCheckers
	- normalizers
	- syntaxes
 o changed m-humanReadible to x-humanReadible since it is used as an extension
 o added code to handle all types in the partition schema loader


Modified:
    directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
    directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
    directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
    directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema

Modified: directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java?view=diff&rev=487941&r1=487940&r2=487941
==============================================================================
--- directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
(original)
+++ directory/branches/trunks/schema/apacheds/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/AttributesFactory.java
Sat Dec 16 20:47:09 2006
@@ -87,7 +87,7 @@
     private static final String M_TYPE_OBJECT_CLASS_AT = "m-typeObjectClass";
     private static final String M_FQCN_AT = "m-fqcn";
     // private static final String M_BYTECODE_AT = "m-bytecode";
-    private static final String M_HUMAN_READIBLE_AT = "m-humanReadible";
+    private static final String X_HUMAN_READIBLE_AT = "x-humanReadible";
     private static final String M_COLLECTIVE_AT = "m-collective";
     private static final String M_SYNTAX_AT = "m-syntax";
     private static final String M_NO_USER_MODIFICATION_AT = "m-noUserModification";
@@ -153,7 +153,7 @@
     {
         BasicAttributes entry = new BasicAttributes( OBJECT_CLASS_AT, "top", true );
         entry.get( OBJECT_CLASS_AT ).add( META_SYNTAX_OC );
-        entry.put( M_HUMAN_READIBLE_AT, getBoolean( syntax.isHumanReadible() ) );
+        entry.put( X_HUMAN_READIBLE_AT, getBoolean( syntax.isHumanReadible() ) );
         injectCommon( syntax, entry );
         return entry;
     }

Modified: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java?view=diff&rev=487941&r1=487940&r2=487941
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
(original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
Sat Dec 16 20:47:09 2006
@@ -21,6 +21,7 @@
 
 
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -39,12 +40,25 @@
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.AbstractSchemaLoader;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.server.schema.registries.DITContentRuleRegistry;
+import org.apache.directory.server.schema.registries.DITStructureRuleRegistry;
+import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
+import org.apache.directory.server.schema.registries.MatchingRuleUseRegistry;
+import org.apache.directory.server.schema.registries.NameFormRegistry;
+import org.apache.directory.server.schema.registries.NormalizerRegistry;
+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.server.schema.registries.SyntaxCheckerRegistry;
+import org.apache.directory.server.schema.registries.SyntaxRegistry;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
 
 
 /**
@@ -175,19 +189,195 @@
         {
             return;
         }
+
+        loadComparators( schema, registries.getComparatorRegistry() );
+        loadNormalizers( schema, registries.getNormalizerRegistry() );
+        loadSyntaxCheckers( schema, registries.getSyntaxCheckerRegistry() );
+        loadSyntaxes( schema, registries.getSyntaxRegistry() );
+        loadMatchingRules( schema, registries.getMatchingRuleRegistry() );
+        loadAttributeTypes( schema, registries.getAttributeTypeRegistry() );
+        loadObjectClasses( schema, registries.getObjectClassRegistry() );
+        loadMatchingRuleUses( schema, registries.getMatchingRuleUseRegistry() );
+        loadDitContentRules( schema, registries.getDitContentRuleRegistry() );
+        loadNameForms( schema, registries.getNameFormRegistry() );
         
-        // TODO Auto-generated method stub: NOT FINISHED YET!!!!!!!!!!!!!
+        // order does matter here so some special trickery is needed
+        // we cannot load a DSR before the DSRs it depends on are loaded?
+        // TODO need ot confirm this ( or we must make the class for this and use deferred

+        // resolution until everything is available?
+        
+        loadDitStructureRules( schema, registries.getDitStructureRuleRegistry() );
         
-        // load the schema entities here ....
-
         notifyListenerOrRegistries( schema, registries );
     }
 
+    
+    private void loadMatchingRuleUses( Schema schema, MatchingRuleUseRegistry matchingRuleUseRegistry
)
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+
+    private void loadDitStructureRules( Schema schema, DITStructureRuleRegistry registry
) throws NamingException
+    {
+        // TODO Auto-generated method stub
+    }
+
+
+    private void loadNameForms( Schema schema, NameFormRegistry registry ) throws NamingException
+    {
+        // TODO Auto-generated method stub
+    }
+
+
+    private void loadDitContentRules( Schema schema, DITContentRuleRegistry registry ) throws
NamingException
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+
+    private void loadObjectClasses( Schema schema, ObjectClassRegistry registry ) throws
NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=objectClasses,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+        }
+    }
+
+
+    private void loadAttributeTypes( Schema schema, AttributeTypeRegistry registry ) throws
NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=attributeTypes,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+        }
+    }
+
+
+    private void loadMatchingRules( Schema schema, MatchingRuleRegistry registry ) throws
NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=matchingRules,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+        }
+    }
+
+
+    private void loadSyntaxes( Schema schema, SyntaxRegistry registry ) throws NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=syntaxes,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            Syntax syntax = factory.getSyntax( result.getAttributes() );
+            registry.register( schema.getSchemaName(), syntax );
+        }
+    }
+
+
+    private void loadSyntaxCheckers( Schema schema, SyntaxCheckerRegistry registry ) throws
NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=syntaxCheckers,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            SyntaxChecker sc = factory.getSyntaxChecker( result.getAttributes() );
+            registry.register( schema.getSchemaName(), sc.getSyntaxOid(), sc );
+        }
+    }
+
+
+    private void loadNormalizers( Schema schema, NormalizerRegistry registry ) throws NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=normalizers,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+        
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            Normalizer normalizer = factory.getNormalizer( result.getAttributes() );
+            String oid = ( String ) result.getAttributes().get( "m-oid" ).get();
+            registry.register( schema.getSchemaName(), oid, normalizer );
+        }
+    }
+
+
+    private void loadComparators( Schema schema, ComparatorRegistry registry ) throws NamingException
+    {
+        LdapDN dn = new LdapDN( "ou=comparators,cn=" + schema.getSchemaName() + ",ou=schema"
);
+        dn.normalize( this.attrRegistry.getNormalizerMapping() );
+
+        if ( ! partition.hasEntry( dn ) )
+        {
+            return;
+        }
+        
+        NamingEnumeration list = partition.list( dn );
+        while ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            Comparator comparator = factory.getComparator( result.getAttributes() );
+            String oid = ( String ) result.getAttributes().get( "m-oid" ).get();
+            registry.register( schema.getSchemaName(), oid, comparator );
+        }
+    }
+
 
     public void loadWithDependencies( Schema schema, Registries registries ) throws NamingException
     {
         HashMap<String,Schema> notLoaded = new HashMap<String,Schema>();
-        notLoaded.put( schema.getSchemaName(), schema );
+        notLoaded.put( schema.getSchemaName(), schema );                        
         Properties props = new Properties();
         loadDepsFirst( new Stack<String>(), notLoaded, schema, registries, props );
     }

Modified: directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java?view=diff&rev=487941&r1=487940&r2=487941
==============================================================================
--- directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
(original)
+++ directory/branches/trunks/schema/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaEntityFactory.java
Sat Dec 16 20:47:09 2006
@@ -21,6 +21,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -30,6 +31,10 @@
 
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.server.schema.registries.SyntaxCheckerRegistry;
+import org.apache.directory.shared.ldap.schema.AbstractSyntax;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
 
 
@@ -58,7 +63,6 @@
         this.registries = registries;
         this.classLoader = new AttributeClassLoader();
     }
-    
 
     
     public Schema getSchema( Attributes entry ) throws NamingException
@@ -108,7 +112,7 @@
     
     
     /**
-     * Example of how to retrieve and load a syntaxChecker class from the DIT.
+     * Retrieve and load a syntaxChecker class from the DIT.
      * 
      * @param entry the entry to load the syntaxChecker from
      * @return the loaded SyntaxChecker
@@ -196,6 +200,182 @@
     
     
     /**
+     * Retrieve and load a Comparator class from the DIT.
+     * 
+     * @param entry the entry to load the Comparator from
+     * @return the loaded Comparator
+     * @throws NamingException if anything fails during loading
+     */
+    public Comparator getComparator( Attributes entry ) throws NamingException
+    {
+        if ( entry == null )
+        {
+            throw new NullPointerException( "entry cannot be null" );
+        }
+        
+        if ( entry.get( "m-fqcn" ) == null )
+        {
+            throw new NullPointerException( "entry must have a valid m-fqcn attribute" );
+        }
+        
+        String className = ( String ) entry.get( "m-fqcn" ).get();
+        Comparator comparator = null;
+        Class clazz = null;
+
+        if ( entry.get( "m-bytecode" ) == null )
+        {
+            try
+            {
+                clazz = Class.forName( className );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                NamingException ne = new NamingException( "Comparator class "+ className
+ " was not found" );
+                ne.setRootCause( e );
+                throw ne;
+            }
+        }       
+        else
+        {
+            try
+            {
+                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" );
+                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 
+                + ".\nCheck that a default constructor exists for the class." );
+            ne.setRootCause( e );
+            throw ne;
+        }
+        catch ( IllegalAccessException e )
+        {
+            NamingException ne = new NamingException( "Failed to instantiate comparator class
"+ className 
+                + ".\nCheck that a **PUBLIC** accessible default constructor exists for the
class." );
+            ne.setRootCause( e );
+            throw ne;
+        }
+
+        // try now before returning to check if we can inject a Registries object
+        injectRegistries( comparator );
+        return comparator;
+    }
+    
+    
+    /**
+     * 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 ) throws NamingException
+    {
+        if ( entry == null )
+        {
+            throw new NullPointerException( "entry cannot be null" );
+        }
+        
+        if ( entry.get( "m-fqcn" ) == null )
+        {
+            throw new NullPointerException( "entry must have a valid m-fqcn attribute" );
+        }
+        
+        String className = ( String ) entry.get( "m-fqcn" ).get();
+        Normalizer normalizer = null;
+        Class clazz = null;
+
+        if ( entry.get( "m-bytecode" ) == null )
+        {
+            try
+            {
+                clazz = Class.forName( className );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                NamingException ne = new NamingException( "Normalizer class "+ className
+ " was not found" );
+                ne.setRootCause( e );
+                throw ne;
+            }
+        }       
+        else
+        {
+            try
+            {
+                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;
+            }
+        }
+        
+        
+        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." );
+            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." );
+            ne.setRootCause( e );
+            throw ne;
+        }
+
+        // try now before returning to check if we can inject a Registries object
+        injectRegistries( normalizer );
+        return normalizer;
+    }
+    
+    
+    /**
      * Uses reflection to see if a setRegistries( Registries ) method exists on the
      * object's class.  If so then the registries are dependency injected into the 
      * new schema object.
@@ -252,6 +432,54 @@
                 + " could not have the Registries dependency injected." );
             ne.setRootCause( e );
             throw ne;
+        }
+    }
+
+
+    public Syntax getSyntax( Attributes entry ) throws NamingException
+    {
+        String oid = ( String ) entry.get( "m-oid" ).get();
+        boolean isHumanReadible = false;
+        String description = null;
+        
+        if ( entry.get( "x-humanReadible" ) != null )
+        {
+            String val = ( String ) entry.get( "x-humanReadible" ).get();
+            isHumanReadible = val.toUpperCase().equals( "TRUE" );
+        }
+        
+        if ( entry.get( "m-description" ) != null )
+        {
+            description = ( String ) entry.get( "m-description" ).get(); 
+            return new SyntaxImpl( oid, description, isHumanReadible, registries.getSyntaxCheckerRegistry()
);
+        }
+        return new SyntaxImpl( oid, isHumanReadible, registries.getSyntaxCheckerRegistry()
);
+    }
+    
+    
+    class SyntaxImpl extends AbstractSyntax
+    {
+        private static final long serialVersionUID = 1L;
+        private final SyntaxCheckerRegistry registry;
+
+        
+        protected SyntaxImpl( String oid, boolean isHumanReadible, SyntaxCheckerRegistry
registry )
+        {
+            super( oid, isHumanReadible );
+            this.registry = registry;
+        }
+
+        
+        protected SyntaxImpl( String oid, String description, boolean isHumanReadible, SyntaxCheckerRegistry
registry )
+        {
+            super( oid, description, isHumanReadible );
+            this.registry = registry;
+        }
+
+        
+        public SyntaxChecker getSyntaxChecker() throws NamingException
+        {
+            return registry.lookup( oid );
         }
     }
 }

Modified: directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema
URL: http://svn.apache.org/viewvc/directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema?view=diff&rev=487941&r1=487940&r2=487941
==============================================================================
--- directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema
(original)
+++ directory/branches/trunks/schema/apacheds/schema-bootstrap/src/main/schema/apachemeta.schema
Sat Dec 16 20:47:09 2006
@@ -76,7 +76,7 @@
 #         | 1.3.6.1.4.1.18060.0.4.0.2.31 | m-matchingRuleSyntax        |
 #         | 1.3.6.1.4.1.18060.0.4.0.2.32 | m-fqcn                      |
 #         | 1.3.6.1.4.1.18060.0.4.0.2.33 | m-bytecode                  |
-#         | 1.3.6.1.4.1.18060.0.4.0.2.34 | m-humanReadible             |
+#         | 1.3.6.1.4.1.18060.0.4.0.2.34 | x-humanReadible             |
 #         | 1.3.6.1.4.1.18060.0.4.0.2.35 | m-extensionSyntax           |
 #         | 1.3.6.1.4.1.18060.0.4.0.2.36 | m-extensionMatchingRule     |
 #         | 1.3.6.1.4.1.18060.0.4.0.2.37 | m-disabled                  |
@@ -595,8 +595,8 @@
     SINGLE-VALUE
 )
 
-# --- m-bytecode AttributeType ------------------------------------------------
-attributetype ( 1.3.6.1.4.1.18060.0.4.0.2.34 NAME 'm-humanReadible'
+# --- x-humanReadible AttributeType ------------------------------------------------
+attributetype ( 1.3.6.1.4.1.18060.0.4.0.2.34 NAME 'x-humanReadible'
     DESC 'whether or not a syntax is human readible'
     EQUALITY booleanMatch
     SYNTAX 1.3.6.1.4.1.1466.115.121.1.7



Mime
View raw message