directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1036881 - in /directory/studio/trunk/plugins/apacheds.configuration.v2: ./ src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/ src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ src/main/ja...
Date Fri, 19 Nov 2010 14:57:46 GMT
Author: pamarcelot
Date: Fri Nov 19 14:57:46 2010
New Revision: 1036881

URL: http://svn.apache.org/viewvc?rev=1036881&view=rev
Log:
Added dependencies to the configuration reader modules.
Added a job to load the configuration in a background thread (other than the UI thread).
Added a loading page in the Configuration Editor which is dismissed when the configuration
is finally loaded.

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/pom.xml
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/pom.xml?rev=1036881&r1=1036880&r2=1036881&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/pom.xml (original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/pom.xml Fri Nov 19 14:57:46 2010
@@ -110,7 +110,14 @@
             <Bundle-Localization>plugin</Bundle-Localization>
             <Eclipse-LazyStart>true</Eclipse-LazyStart>
             <Bundle-Activator>org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin</Bundle-Activator>
-            <Require-Bundle>
+            <Require-Bundle>org.apache.commons.io;bundle-version="${org.apache.commons.io.version}",
+ org.apache.directory.server.core.api;bundle-version="${org.apache.directory.server.validversion}",
+ org.apache.directory.server.config;bundle-version="${org.apache.directory.server.validversion}",
+ org.apache.directory.server.ldif.partition;bundle-version="${org.apache.directory.server.validversion}",
+ org.apache.directory.server.xdbm.partition;bundle-version="${org.apache.directory.server.validversion}",
+ org.apache.directory.shared.ldap;bundle-version="${org.apache.directory.shared.validversion}",
+ org.apache.directory.shared.ldap.schema;bundle-version="${org.apache.directory.shared.validversion}",
+ org.apache.directory.studio.common.core,
  org.apache.directory.studio.connection.core,
  org.apache.directory.studio.connection.ui,
  org.eclipse.core.runtime,
@@ -148,6 +155,48 @@
   	<!-- Apache Directory Studio library plugins dependencies -->
     <dependency>
       <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.commons.io</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.server.core.api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.server.config</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.server.ldif.partition</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.server.xdbm.partition</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.shared.ldap</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>org.apache.directory.shared.ldap.schema</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
+  	<!-- Apache Directory Studio plugins dependencies -->
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>common.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
       <artifactId>connection.core</artifactId>
       <scope>provided</scope>
     </dependency>

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java?rev=1036881&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java
Fri Nov 19 14:57:46 2010
@@ -0,0 +1,84 @@
+/*
+ *  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.studio.apacheds.configuration.v2.actions;
+
+
+import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
+import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPluginConstants;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormPage;
+
+
+/**
+ * This class implements the create connection action for an ApacheDS 1.5.7 server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EditorAddPageAction extends Action
+{
+    private ServerConfigurationEditor editor;
+
+
+    public EditorAddPageAction( ServerConfigurationEditor editor )
+    {
+        this.editor = editor;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ImageDescriptor getImageDescriptor()
+    {
+        return ApacheDS2ConfigurationPlugin.getDefault().getImageDescriptor(
+            ApacheDS2ConfigurationPluginConstants.IMG_IMPORT );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getText()
+    {
+        return "Add Page";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        try
+        {
+            editor.removePage( 0 );
+            editor.addPage( new FormPage( "id", "title" ) );
+        }
+        catch ( PartInitException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+}

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java?rev=1036881&r1=1036880&r2=1036881&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
Fri Nov 19 14:57:46 2010
@@ -21,6 +21,18 @@
 package org.apache.directory.studio.apacheds.configuration.v2.actions;
 
 
+import java.io.File;
+import java.util.List;
+
+import org.apache.directory.server.config.ConfigPartitionReader;
+import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
+import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationInput;
 import org.eclipse.jface.action.IAction;
@@ -44,14 +56,21 @@ public class OpenConfigurationAction imp
      */
     public void run( IAction action )
     {
-        System.out.println( "Action!" );
-        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         try
         {
-            page.openEditor( new ServerConfigurationInput(),
-                ServerConfigurationEditor.ID );
+            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+            try
+            {
+                page.openEditor( new ServerConfigurationInput(),
+                    ServerConfigurationEditor.ID );
+            }
+            catch ( PartInitException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
         }
-        catch ( PartInitException e )
+        catch ( Exception e )
         {
             // TODO Auto-generated catch block
             e.printStackTrace();

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java?rev=1036881&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
Fri Nov 19 14:57:46 2010
@@ -0,0 +1,86 @@
+/*
+ *  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.studio.apacheds.configuration.v2.editor;
+
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.ProgressBar;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+
+/**
+ * This class represents the General Page of the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LoadingPage extends FormPage
+{
+    /** The Page ID*/
+    public static final String ID = LoadingPage.class.getName(); //$NON-NLS-1$
+
+    /** The Page Title */
+    private static final String TITLE = "Loading Configuration";
+
+
+    /**
+     * Creates a new instance of LoadingPage.
+     *
+     * @param editor
+     *      the associated editor
+     */
+    public LoadingPage( FormEditor editor )
+    {
+        super( editor, ID, TITLE );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createFormContent( IManagedForm managedForm )
+    {
+        ScrolledForm form = managedForm.getForm();
+        form.setText( "Loading Configuration..." );
+
+        Composite parent = form.getBody();
+        parent.setLayout( new GridLayout() );
+
+        FormToolkit toolkit = managedForm.getToolkit();
+        toolkit.decorateFormHeading( form.getForm() );
+
+        Composite composite = toolkit.createComposite( parent );
+        composite.setLayout( new GridLayout() );
+        composite.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, true ) );
+
+        ProgressBar progressBar = new ProgressBar( composite, SWT.INDETERMINATE );
+        progressBar.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false ) );
+
+        Label label = toolkit.createLabel( composite, "Loading the configuration, please
wait..." );
+        label.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false ) );
+    }
+}

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java?rev=1036881&r1=1036880&r2=1036881&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
Fri Nov 19 14:57:46 2010
@@ -20,6 +20,12 @@
 package org.apache.directory.studio.apacheds.configuration.v2.editor;
 
 
+import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
+import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPluginConstants;
+import org.apache.directory.studio.apacheds.configuration.v2.jobs.LoadConfigurationRunnable;
+import org.apache.directory.studio.common.core.jobs.StudioJob;
+import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
@@ -43,6 +49,9 @@ public class ServerConfigurationEditor e
     /** The Page ID*/
     public static final String ID = ServerConfigurationEditor.class.getName();
 
+    /** The configuration bean */
+    private ConfigBean configBean;
+
 
     /**
      * {@inheritDoc}
@@ -51,6 +60,11 @@ public class ServerConfigurationEditor e
     {
         super.init( site, input );
         setPartName( input.getName() );
+
+
+        // Creating and scheduling the job to delete the server
+        StudioJob<StudioRunnableWithProgress> job = new StudioJob<StudioRunnableWithProgress>(
new LoadConfigurationRunnable( this ) );
+        job.schedule();
     }
 
 
@@ -61,11 +75,15 @@ public class ServerConfigurationEditor e
     {
         try
         {
-            addPage( new OverviewPage( this ) );
-            addPage( new LdapLdapsServersPage( this ) );
-            addPage( new KerberosServerPage( this ) );
-            addPage( new PartitionsPage( this ) );
-            addPage( new ReplicationPage( this ) );
+            addPage( new LoadingPage( this ) );
+            setPageImage( 0, ApacheDS2ConfigurationPlugin.getDefault().getImage(
+                ApacheDS2ConfigurationPluginConstants.IMG_IMPORT ) );
+
+            //            addPage( new OverviewPage( this ) );
+            //            addPage( new LdapLdapsServersPage( this ) );
+            //            addPage( new KerberosServerPage( this ) );
+            //            addPage( new PartitionsPage( this ) );
+            //            addPage( new ReplicationPage( this ) );
         }
         catch ( PartInitException e )
         {
@@ -99,6 +117,65 @@ public class ServerConfigurationEditor e
         return true;
     }
 
+
+    /**
+     * Gets the configuration bean.
+     *
+     * @return
+     *      the configuration bean
+     */
+    public ConfigBean getConfigBean()
+    {
+        return configBean;
+    }
+
+
+    /**
+     * Sets the configuration bean.
+     *
+     * @param configBean
+     *      the configuration bean
+     */
+    public void setConfigBean( ConfigBean configBean )
+    {
+        this.configBean = configBean;
+    }
+
+
+    /**
+     * TODO configBeanLoaded.
+     *
+     * @param configBean
+     * @throws PartInitException
+     */
+    public void configBeanLoaded( ConfigBean configBean ) throws PartInitException
+    {
+        setConfigBean( configBean );
+        
+        hideLoadingPageAndDisplayConfigPages();
+    }
+
+
+    /**
+     * TODO hideLoadingPageAndDisplayConfigPages.
+     *
+     * @throws PartInitException
+     */
+    private void hideLoadingPageAndDisplayConfigPages() throws PartInitException
+    {
+        // Removing the loading page
+        removePage( 0 );
+        
+        // Adding the configuration pages
+        addPage( new OverviewPage( this ) );
+        addPage( new LdapLdapsServersPage( this ) );
+        addPage( new KerberosServerPage( this ) );
+        addPage( new PartitionsPage( this ) );
+        addPage( new ReplicationPage( this ) );
+        
+        // Activating the first page
+        setActivePage( 0 );
+    }
 }
 
 /**

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java?rev=1036881&r1=1036880&r2=1036881&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java
Fri Nov 19 14:57:46 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.studio.apacheds.configuration.v2.editor;
 
 
+import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorAddPageAction;
 import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorExportConfigurationAction;
 import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorImportConfigurationAction;
 import org.eclipse.jface.action.IToolBarManager;
@@ -82,6 +83,8 @@ public abstract class ServerConfiguratio
         toolbarManager.add( new EditorImportConfigurationAction() );
         toolbarManager.add( new Separator() );
         toolbarManager.add( new EditorExportConfigurationAction() );
+        toolbarManager.add( new Separator() );
+        toolbarManager.add( new EditorAddPageAction( ( ServerConfigurationEditor ) getEditor()
) );
         toolbarManager.update( true );
 
         createFormContent( parent, toolkit );

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java?rev=1036881&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
Fri Nov 19 14:57:46 2010
@@ -0,0 +1,174 @@
+/*
+ *  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.studio.apacheds.configuration.v2.jobs;
+
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.directory.server.config.ConfigPartitionReader;
+import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
+import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
+import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
+import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
+
+
+/**
+ * This class implements a {@link Job} that is used to delete an LDAP Server.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LoadConfigurationRunnable implements StudioRunnableWithProgress
+{
+    private ServerConfigurationEditor editor;
+    
+    private ConfigBean configBean;
+
+
+    /**
+     * Creates a new instance of StartLdapServerRunnable.
+     * 
+     * @param server
+     *            the LDAP Server
+     */
+    public LoadConfigurationRunnable( ServerConfigurationEditor editor )
+    {
+        super();
+        this.editor = editor;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getErrorMessage()
+    {
+        return "Unable to load the configuration";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getLockedObjects()
+    {
+        return new Object[0];
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getName()
+    {
+        return "Load configuration";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run( StudioProgressMonitor monitor )
+    {
+        try
+        {
+            initConfigBean();
+            
+            Display.getDefault().asyncExec( new Runnable()
+            {
+                public void run()
+                {
+                    try
+                    {
+                        editor.configBeanLoaded( configBean );
+                    }
+                    catch ( PartInitException e )
+                    {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+        catch ( Exception e )
+        {
+            // Reporting the error to the monitor
+            monitor.reportError( e );
+        }
+    }
+    
+
+    private void initConfigBean() throws Exception
+    {
+        SchemaLoader loader = new LdifSchemaLoader( new File(
+            "/Users/pajbam/Development/Apache/ApacheDS/shared/ldap-schema/src/main/resources/schema"
) );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        long t1 = System.currentTimeMillis();
+
+        // We have to load the schema now, otherwise we won't be able
+        // to initialize the Partitions, as we won't be able to parse 
+        // and normalize their suffix DN
+        //schemaManager.loadAllEnabled();
+        schemaManager.loadWithDeps( "adsconfig" );
+
+        long t2 = System.currentTimeMillis();
+
+        System.out.println( "Time = " + ( t2 - t1 ) + "ms" );
+
+        List<Throwable> errors = schemaManager.getErrors();
+
+        if ( errors.size() != 0 )
+        {
+            throw new Exception( "Schema load failed : " + LdapExceptionUtils.printErrors(
errors ) );
+        }
+
+        SingleFileLdifPartition configPartition = new SingleFileLdifPartition(
+            "/Users/pajbam/Development/Apache/ApacheDS/apacheds/server-config/src/main/resources/config.ldif"
);
+        configPartition.setId( "config" );
+        configPartition.setSuffix( new DN( "ou=config" ) );
+        configPartition.setSchemaManager( schemaManager );
+
+        configPartition.initialize();
+        ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition, new
File(
+            "/Users/pajbam/Development/Apache/ApacheDS/apacheds/server-config/src/main/resources/"
) );
+
+        t1 = System.currentTimeMillis();
+
+        configBean = cpReader.readConfig( new DN( "ou=config" ) );
+
+        t2 = System.currentTimeMillis();
+
+        System.out.println( "Time = " + ( t2 - t1 ) + "ms" );
+
+        //            System.out.println( configBean );
+    }
+}



Mime
View raw message