directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1425172 - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/annotations/ core-annotations/src/main/java/org/apache/directory/server/core/factory/ core-annotations/src/test/java/org/apache/directo...
Date Fri, 21 Dec 2012 22:44:25 GMT
Author: elecharny
Date: Fri Dec 21 22:44:25 2012
New Revision: 1425172

URL: http://svn.apache.org/viewvc?rev=1425172&view=rev
Log:
Added the code that allows a user to load and enable a schema using the @nnotations, like
in : 

    @CreateDS(
        name = "MethodDSWithPartition",
        partitions =
            {
                @CreatePartition(
                ...
        },
        loadedSchemas =
            {
                @LoadSchema(name = "nis", enabled = true),
                @LoadSchema(name = "posix", enabled = false)
        }
        )
    public void testCreateMethodDSWithPartition() throws Exception

This solves DIRSERVER-1784

Added:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/LoadSchema.java
Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
    directory/apacheds/trunk/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java?rev=1425172&r1=1425171&r2=1425172&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
Fri Dec 21 22:44:25 2012
@@ -70,4 +70,9 @@ public @interface CreateDS
     /** authenticators, when empty the default authenticators are used, else this must contain
the complete list */
     CreateAuthenticator[] authenticators() default
         {};
+
+
+    /** The loaded schemas */
+    LoadSchema[] loadedSchemas() default
+        {};
 }

Added: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/LoadSchema.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/LoadSchema.java?rev=1425172&view=auto
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/LoadSchema.java
(added)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/LoadSchema.java
Fri Dec 21 22:44:25 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.annotations;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * An annotation for the schema loading. One can list the schema to be loaded, 
+ * and if they must be enabled or disabled.<br/>
+ * We can only load new schemas, not unload existing ones.However, we 
+ * can disable a schema that has been previously loaded : loading a 
+ * schema that is already loaded will just apply the enabled flag on 
+ * this schema<br/>
+ * Note that a schema may be loaded and disabled.<br/>
+ * Some schema are automatically loaded, and there is no way they can be disabled :<br/>
+ * <ul>
+ *   <li> core</li>
+ *   <li>system</li>
+ * </ul>
+ * 
+ * Here is an exemple :
+ * <pre>
+ * @Schemas( {
+ *     @LoadSchema( name = "nis", enabled="TRUE" ),
+ *     @LoadSchema( name = "posix", enabled="FALSE" ),
+ * })
+ * )
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(
+    { ElementType.METHOD, ElementType.TYPE })
+public @interface LoadSchema
+{
+    /** The schema name */
+    String name();
+
+
+    /** The flag indicating if the schema should be enabled or disabled */
+    boolean enabled() default true;
+}

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=1425172&r1=1425171&r2=1425172&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
Fri Dec 21 22:44:25 2012
@@ -29,6 +29,7 @@ import java.util.Set;
 
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
 import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
 import org.apache.directory.api.ldap.model.ldif.LdifEntry;
 import org.apache.directory.api.ldap.model.ldif.LdifReader;
 import org.apache.directory.api.ldap.model.name.Dn;
@@ -41,6 +42,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreateIndex;
 import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.annotations.LoadSchema;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.interceptor.Interceptor;
 import org.apache.directory.server.core.api.partition.Partition;
@@ -199,6 +201,57 @@ public class DSAnnotationProcessor
             // Inject the partition into the DirectoryService
             service.addPartition( partition );
 
+            SchemaManager schemaManager = service.getSchemaManager();
+
+            // process the schemas
+            for ( LoadSchema loadedSchema : dsBuilder.loadedSchemas() )
+            {
+                String schemaName = loadedSchema.name();
+                Boolean enabled = loadedSchema.enabled();
+
+                // Check if the schema is loaded or not
+                boolean isLoaded = schemaManager.isSchemaLoaded( schemaName );
+
+                if ( !isLoaded )
+                {
+                    // We have to load the schema, if it exists
+                    try
+                    {
+                        isLoaded = schemaManager.load( schemaName );
+                    }
+                    catch ( LdapUnwillingToPerformException lutpe )
+                    {
+                        // Cannot load the schema, it does not exists
+                        LOG.error( lutpe.getMessage() );
+                        continue;
+                    }
+                }
+
+                if ( isLoaded )
+                {
+                    if ( enabled )
+                    {
+                        schemaManager.enable( schemaName );
+
+                        if ( schemaManager.isDisabled( schemaName ) )
+                        {
+                            LOG.error( "Cannot enable " + schemaName );
+                        }
+                    }
+                    else
+                    {
+                        schemaManager.disable( schemaName );
+
+                        if ( schemaManager.isEnabled( schemaName ) )
+                        {
+                            LOG.error( "Cannot disable " + schemaName );
+                        }
+                    }
+                }
+
+                LOG.debug( "Loading schema {}, enabled= {}", schemaName, enabled );
+            }
+
             // Last, process the context entry
             ContextEntry contextEntry = createPartition.contextEntry();
 
@@ -358,6 +411,30 @@ public class DSAnnotationProcessor
 
 
     /**
+     * Load the schemas, and enable/disable them.
+     */
+    public static void loadSchemas( Description desc, DirectoryService service )
+    {
+        if ( desc == null )
+        {
+            return;
+        }
+
+        /*for ( Class<?> loadSchema : dsBuilder.additionalInterceptors() )
+        {
+            service.addLast( ( Interceptor ) interceptorClass.newInstance() );
+        }*/
+        LoadSchema loadSchema = desc
+            .getAnnotation( LoadSchema.class );
+
+        if ( loadSchema != null )
+        {
+            System.out.println( loadSchema );
+        }
+    }
+
+
+    /**
      * Apply the LDIF entries to the given service
      */
     public static void applyLdifs( Description desc, DirectoryService service )

Modified: directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java?rev=1425172&r1=1425171&r2=1425172&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
Fri Dec 21 22:44:25 2012
@@ -32,6 +32,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreateIndex;
 import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.annotations.LoadSchema;
 import org.apache.directory.server.core.api.DirectoryService;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
@@ -92,9 +93,16 @@ public class DirectoryServiceAnnotationT
                             @CreateIndex(attribute = "objectClass"),
                             @CreateIndex(attribute = "dc"),
                             @CreateIndex(attribute = "ou")
-                    })
-        })
-    public void testCreateMethodDSWithPartition() throws Exception
+                    }),
+
+        },
+        loadedSchemas =
+            {
+                @LoadSchema(name = "nis", enabled = true),
+                @LoadSchema(name = "posix", enabled = false)
+        }
+        )
+        public void testCreateMethodDSWithPartition() throws Exception
     {
         DirectoryService service = DSAnnotationProcessor.getDirectoryService();
 
@@ -124,6 +132,8 @@ public class DirectoryServiceAnnotationT
             }
         }
 
+        assertTrue( service.getSchemaManager().isEnabled( "nis" ) );
+
         service.shutdown();
         FileUtils.deleteDirectory( service.getInstanceLayout().getInstanceDirectory() );
     }

Modified: directory/apacheds/trunk/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java?rev=1425172&r1=1425171&r2=1425172&view=diff
==============================================================================
--- directory/apacheds/trunk/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
(original)
+++ directory/apacheds/trunk/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Fri Dec 21 22:44:25 2012
@@ -154,6 +154,9 @@ public class FrameworkRunner extends Blo
                 // Stores the defaultDS in the classDS
                 classDS = directoryService;
 
+                // Load the schemas
+                DSAnnotationProcessor.loadSchemas( getDescription(), directoryService );
+
                 // Apply the class LDIFs
                 DSAnnotationProcessor.applyLdifs( getDescription(), directoryService );
             }
@@ -329,39 +332,39 @@ public class FrameworkRunner extends Blo
             // At this point, we know which service to use.
             // Inject it into the class
             Method setService = null;
-            
+
             try
             {
                 setService = getTestClass().getJavaClass().getMethod( SET_SERVICE_METHOD_NAME,
                     DirectoryService.class );
-                
+
                 setService.invoke( getTestClass().getJavaClass(), directoryService );
             }
-            catch ( NoSuchMethodException nsme ) 
+            catch ( NoSuchMethodException nsme )
             {
                 // Do nothing
             }
 
             // if we run this class in a suite, tell it to the test
             Method setLdapServer = null;
-            
+
             try
             {
                 setLdapServer = getTestClass().getJavaClass().getMethod( SET_LDAP_SERVER_METHOD_NAME,
                     LdapServer.class );
             }
-            catch ( NoSuchMethodException nsme ) 
+            catch ( NoSuchMethodException nsme )
             {
                 // Do nothing
             }
-            
+
             Method setKdcServer = null;
-            
+
             try
             {
                 setKdcServer = getTestClass().getJavaClass().getMethod( SET_KDC_SERVER_METHOD_NAME,
KdcServer.class );
             }
-            catch ( NoSuchMethodException nsme ) 
+            catch ( NoSuchMethodException nsme )
             {
                 // Do nothing
             }



Mime
View raw message