You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/04/01 03:01:43 UTC

svn commit: r1670531 [12/14] - in /directory/studio/trunk/plugins/openldap.config.editor: ./ resources/icons/ src/main/java/org/apache/directory/studio/openldap/config/ src/main/java/org/apache/directory/studio/openldap/config/actions/ src/main/java/or...

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationUtils.java?rev=1670531&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationUtils.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationUtils.java Wed Apr  1 01:01:42 2015
@@ -0,0 +1,140 @@
+/*
+ *  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.openldap.config.model.io;
+
+
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.IConnectionListener;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeRootDSERunnable;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+
+/**
+ * This class implements a configuration reader for OpenLDAP.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ConfigurationUtils
+{
+    /** The default OpenLDAP configuration DN */
+    public static final String DEFAULT_CONFIG_DN = "cn=config";
+
+
+    /**
+     * Gets the configuration DN.
+     *
+     * @param browserConnection the browser connection
+     * @return the configuration DN
+     * @throws ConfigurationException if the configuration DN couldn't be found
+     */
+    public static Dn getConfigurationDn( IBrowserConnection browserConnection )
+        throws ConfigurationException
+    {
+        IProgressMonitor progressMonitor = new NullProgressMonitor();
+        StudioProgressMonitor monitor = new StudioProgressMonitor( progressMonitor );
+
+        // Opening the connection (if needed)
+        openConnection( browserConnection.getConnection(), monitor );
+
+        // Load Root DSE (if needed)
+        if ( browserConnection.getRootDSE() == null )
+        {
+            InitializeRootDSERunnable.loadRootDSE( browserConnection, monitor );
+        }
+
+        // Getting the Root DSE
+        IRootDSE rootDse = browserConnection.getRootDSE();
+
+        try
+        {
+            // Getting the 'configcontext' attribute
+            IAttribute configContextAttribute = rootDse.getAttribute( "configcontext" );
+            if ( ( configContextAttribute != null ) && ( configContextAttribute.getValueSize() > 0 ) )
+            {
+                return new Dn( configContextAttribute.getStringValue() );
+            }
+            else
+            {
+                return getDefaultConfigurationDn();
+            }
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            throw new ConfigurationException( e );
+        }
+    }
+
+
+    /**
+     * Gets the default configuration DN.
+     *
+     * @return the default configuration DN
+     * @throws ConfigurationException if an error occurred
+     */
+    public static Dn getDefaultConfigurationDn() throws ConfigurationException
+    {
+        try
+        {
+            return new Dn( DEFAULT_CONFIG_DN );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            throw new ConfigurationException( e );
+        }
+    }
+
+
+    /**
+     * Opens the connection.
+     *
+     * @param connection the connection
+     * @param monitor the monitor
+     */
+    public static void openConnection( Connection connection, StudioProgressMonitor monitor )
+    {
+        if ( connection != null && !connection.getConnectionWrapper().isConnected() )
+        {
+            connection.getConnectionWrapper().connect( monitor );
+            if ( connection.getConnectionWrapper().isConnected() )
+            {
+                connection.getConnectionWrapper().bind( monitor );
+            }
+
+            if ( connection.getConnectionWrapper().isConnected() )
+            {
+                for ( IConnectionListener listener : ConnectionCorePlugin.getDefault()
+                    .getConnectionListeners() )
+                {
+                    listener.connectionOpened( connection, monitor );
+                }
+                ConnectionEventRegistry.fireConnectionOpened( connection, null );
+            }
+        }
+    }
+}

Modified: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationWriter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationWriter.java?rev=1670531&r1=1670530&r2=1670531&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationWriter.java (original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationWriter.java Wed Apr  1 01:01:42 2015
@@ -39,20 +39,28 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.name.Rdn;
 import org.apache.directory.api.ldap.model.schema.ObjectClass;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 
+import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPlugin;
+import org.apache.directory.studio.openldap.config.editor.ServerConfigurationEditorUtils;
+import org.apache.directory.studio.openldap.config.model.AuxiliaryObjectClass;
 import org.apache.directory.studio.openldap.config.model.ConfigurationElement;
 import org.apache.directory.studio.openldap.config.model.OlcConfig;
+import org.apache.directory.studio.openldap.config.model.OlcDatabaseConfig;
+import org.apache.directory.studio.openldap.config.model.OlcOverlayConfig;
 import org.apache.directory.studio.openldap.config.model.OpenLdapConfiguration;
 
 
 /**
  * This class implements a configuration reader for OpenLDAP.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class ConfigurationWriter
 {
-    /** The schema */
-    private Schema schema;
+    /** The browserConnection */
+    private IBrowserConnection browserConnection;
 
     /** The configuration */
     private OpenLdapConfiguration configuration;
@@ -64,14 +72,26 @@ public class ConfigurationWriter
     /**
      * Creates a new instance of ConfigWriter.
      *
-     * @param schema
-     *      the schema
+     * @param browserConnection
+     *      the browser connection
      * @param configuration
      *      the configuration
      */
-    public ConfigurationWriter( Schema schema, OpenLdapConfiguration configuration )
+    public ConfigurationWriter( IBrowserConnection browserConnection, OpenLdapConfiguration configuration )
+    {
+        this.browserConnection = browserConnection;
+        this.configuration = configuration;
+    }
+
+
+    /**
+     * Creates a new instance of ConfigWriter.
+     *
+     * @param configuration
+     *      the configuration
+     */
+    public ConfigurationWriter( OpenLdapConfiguration configuration )
     {
-        this.schema = schema;
         this.configuration = configuration;
     }
 
@@ -79,7 +99,7 @@ public class ConfigurationWriter
     /**
      * Converts the configuration bean to a list of LDIF entries.
      */
-    private void convertConfigurationBeanToLdifEntries() throws ConfigurationException
+    private void convertConfigurationBeanToLdifEntries( Dn configurationDn ) throws ConfigurationException
     {
         try
         {
@@ -87,20 +107,38 @@ public class ConfigurationWriter
             {
                 entries = new ArrayList<LdifEntry>();
 
+                // Adding the global configuration
+                addConfigurationBean( configuration.getGlobal(), Dn.EMPTY_DN );
+
+                // Adding databases
+                for ( OlcDatabaseConfig database : configuration.getDatabases() )
+                {
+                    LdifEntry entry = addConfigurationBean( database, configurationDn );
+
+                    if ( entry != null )
+                    {
+                        for ( OlcOverlayConfig overlay : database.getOverlays() )
+                        {
+                            addConfigurationBean( overlay, entry.getDn() );
+                        }
+                    }
+                }
+
+                // Adding other elements
                 for ( OlcConfig configurationBean : configuration.getConfigurationElements() )
                 {
-                    addConfigurationBean( configurationBean );
+                    addConfigurationBean( configurationBean, configurationDn );
                 }
             }
         }
         catch ( Exception e )
         {
-            throw new ConfigurationException( "Unable to convert the configuration bean to LDIF entries", e );
+            throw new ConfigurationException( "Unable to convert the configuration beans to LDIF entries", e );
         }
     }
 
 
-    private void addConfigurationBean( OlcConfig configurationBean ) throws Exception
+    private LdifEntry addConfigurationBean( OlcConfig configurationBean, Dn parentDn ) throws Exception
     {
         if ( configurationBean != null )
         {
@@ -109,10 +147,29 @@ public class ConfigurationWriter
 
             // Creating the entry to hold the bean and adding it to the list
             LdifEntry entry = new LdifEntry();
-            entry.setDn( getDn( configurationBean ) );
+            entry.setDn( getDn( configurationBean, parentDn ) );
             addObjectClassAttribute( entry, getObjectClassNameForBean( beanClass ) );
             entries.add( entry );
 
+            // Checking auxiliary object classes
+            List<AuxiliaryObjectClass> auxiliaryObjectClassesList = configurationBean
+                .getAuxiliaryObjectClasses();
+            if ( ( auxiliaryObjectClassesList != null ) && ( auxiliaryObjectClassesList.size() > 0 ) )
+            {
+                for ( AuxiliaryObjectClass auxiliaryObjectClass : auxiliaryObjectClassesList )
+                {
+                    // Getting the bean class for the auxiliary object class
+                    Class<?> auxiliaryObjectClassBeanClass = auxiliaryObjectClass.getClass();
+
+                    // Updating the objectClass attribute value
+                    addAttributeTypeValue( SchemaConstants.OBJECT_CLASS_AT,
+                        getObjectClassNameForBean( auxiliaryObjectClassBeanClass ), entry );
+
+                    // Adding fields of the auxiliary object class to the entry 
+                    addFieldsToBean( auxiliaryObjectClass, auxiliaryObjectClassBeanClass, entry );
+                }
+            }
+
             // A flag to know when we reached the 'OlcConfig' class when 
             // looping on the class hierarchy of the bean
             boolean olcConfigBeanClassFound = false;
@@ -126,55 +183,69 @@ public class ConfigurationWriter
                     olcConfigBeanClassFound = true;
                 }
 
-                // Looping on all fields of the bean
-                Field[] fields = beanClass.getDeclaredFields();
-                for ( Field field : fields )
-                {
-                    // Making the field accessible (we get an exception if we don't do that)
-                    field.setAccessible( true );
+                // Adding fields of the bean to the entry 
+                addFieldsToBean( configurationBean, beanClass, entry );
 
-                    // Getting the class of the field
-                    Class<?> fieldClass = field.getType();
-                    Object fieldValue = field.get( configurationBean );
+                // Moving to the upper class in the class hierarchy
+                beanClass = beanClass.getSuperclass();
+            }
+
+            return entry;
+        }
+
+        return null;
+    }
 
-                    if ( fieldValue != null )
+
+    private void addFieldsToBean( Object configurationBean, Class<?> beanClass, LdifEntry entry ) throws Exception
+    {
+        if ( ( configurationBean != null ) && ( beanClass != null ) && ( entry != null ) )
+        {
+            // Looping on all fields of the bean
+            Field[] fields = beanClass.getDeclaredFields();
+            for ( Field field : fields )
+            {
+                // Making the field accessible (we get an exception if we don't do that)
+                field.setAccessible( true );
+
+                // Getting the class of the field
+                Class<?> fieldClass = field.getType();
+                Object fieldValue = field.get( configurationBean );
+
+                if ( fieldValue != null )
+                {
+                    // Looking for the @ConfigurationElement annotation
+                    ConfigurationElement configurationElement = field.getAnnotation( ConfigurationElement.class );
+                    if ( configurationElement != null )
                     {
-                        // Looking for the @ConfigurationElement annotation
-                        ConfigurationElement configurationElement = field.getAnnotation( ConfigurationElement.class );
-                        if ( configurationElement != null )
+                        // Checking if we have a value for the attribute type
+                        String attributeType = configurationElement.attributeType();
+                        if ( ( attributeType != null ) && ( !"".equals( attributeType ) ) )
                         {
-                            // Checking if we have a value for the attribute type
-                            String attributeType = configurationElement.attributeType();
-                            if ( ( attributeType != null ) && ( !"".equals( attributeType ) ) )
+                            // Checking if the field is optional and if the default value matches
+                            if ( configurationElement.isOptional() )
                             {
-                                // Checking if the field is optional and if the default value matches
-                                if ( configurationElement.isOptional() )
+                                if ( configurationElement.defaultValue().equalsIgnoreCase( fieldValue.toString() ) )
                                 {
-                                    if ( configurationElement.defaultValue().equalsIgnoreCase( fieldValue.toString() ) )
-                                    {
-                                        // Skipping the addition of the value
-                                        continue;
-                                    }
+                                    // Skipping the addition of the value
+                                    continue;
                                 }
+                            }
 
-                                // Adding values to the entry
-                                addAttributeTypeValues( configurationElement.attributeType(), fieldValue, entry );
+                            // Adding values to the entry
+                            addAttributeTypeValues( configurationElement.attributeType(), fieldValue, entry );
 
-                                continue;
-                            }
+                            continue;
+                        }
 
-                            // Checking if we're dealing with a AdsBaseBean subclass type
-                            if ( OlcConfig.class.isAssignableFrom( fieldClass ) )
-                            {
-                                addConfigurationBean( ( OlcConfig ) fieldValue );
-                                continue;
-                            }
+                        // Checking if we're dealing with a AdsBaseBean subclass type
+                        if ( OlcConfig.class.isAssignableFrom( fieldClass ) )
+                        {
+                            addConfigurationBean( ( OlcConfig ) fieldValue, entry.getDn() );
+                            continue;
                         }
                     }
                 }
-
-                // Moving to the upper class in the class hierarchy
-                beanClass = beanClass.getSuperclass();
             }
         }
     }
@@ -185,13 +256,15 @@ public class ConfigurationWriter
      *
      * @param bean
      *      the configuration bean
+     * @param parentDn
+     *      the parent dn
      * @return
      *      the Dn associated with the configuration bean based on the given base Dn.
      * @throws LdapInvalidDnException
      * @throws IllegalArgumentException
      * @throws IllegalAccessException
      */
-    private Dn getDn( OlcConfig bean ) throws LdapInvalidDnException, IllegalArgumentException,
+    private Dn getDn( OlcConfig bean, Dn parentDn ) throws LdapInvalidDnException, IllegalArgumentException,
         IllegalAccessException
     {
         // Getting the class of the bean
@@ -239,7 +312,15 @@ public class ConfigurationWriter
                         value = values.toArray()[0];
                     }
 
-                    return bean.getParentDn().add( new Rdn( configurationElement.attributeType(), value.toString() ) );
+                    if ( ( bean.getParentDn() != null ) )
+                    {
+                        return bean.getParentDn()
+                            .add( new Rdn( configurationElement.attributeType(), value.toString() ) );
+                    }
+                    else
+                    {
+                        return parentDn.add( new Rdn( configurationElement.attributeType(), value.toString() ) );
+                    }
                 }
             }
 
@@ -247,7 +328,7 @@ public class ConfigurationWriter
             beanClass = beanClass.getSuperclass();
         }
 
-        return Dn.EMPTY_DN; // TODO Throw an error when we reach that point
+        return Dn.EMPTY_DN;
     }
 
 
@@ -334,22 +415,59 @@ public class ConfigurationWriter
      */
     public String writeToString() throws ConfigurationException
     {
-        return null;
+        // Converting the configuration bean to a list of LDIF entries
+        convertConfigurationBeanToLdifEntries( ConfigurationUtils.getConfigurationDn( browserConnection ) );
+
+        // Building the StringBuilder
+        StringBuilder sb = new StringBuilder();
+        sb.append( "version: 1\n" );
+        for ( LdifEntry entry : entries )
+        {
+            sb.append( entry.toString() );
+        }
+
+        return sb.toString();
     }
 
 
     /**
      * Gets the converted LDIF entries from the configuration bean.
      *
+     * @param browserConnection the browserConnection
      * @return
      *      the list of converted LDIF entries
      * @throws ConfigurationException
      *      if an error occurs during the conversion to LDIF
      */
-    public List<LdifEntry> getConvertedLdifEntries() throws ConfigurationException
+    /**
+     * TODO getConvertedLdifEntries.
+     *
+     * @return
+     * @throws ConfigurationException
+     */
+    public List<LdifEntry> getConvertedLdifEntries()
+        throws ConfigurationException
     {
         // Converting the configuration bean to a list of LDIF entries
-        convertConfigurationBeanToLdifEntries();
+        convertConfigurationBeanToLdifEntries( ConfigurationUtils.getConfigurationDn( browserConnection ) );
+
+        // Returning the list of entries
+        return entries;
+    }
+
+
+    /**
+     * Gets the converted LDIF entries from the configuration bean.
+     *
+     * @return
+     *      the list of converted LDIF entries
+     * @throws ConfigurationException
+     *      if an error occurs during the conversion to LDIF
+     */
+    public List<LdifEntry> getConvertedLdifEntries( Dn configurationDn ) throws ConfigurationException
+    {
+        // Converting the configuration bean to a list of LDIF entries
+        convertConfigurationBeanToLdifEntries( configurationDn );
 
         // Returning the list of entries
         return entries;
@@ -368,19 +486,28 @@ public class ConfigurationWriter
     private void addObjectClassAttribute( LdifEntry entry, String objectClass )
         throws LdapException
     {
-        ObjectClass objectClassObject = schema.getObjectClassDescription( objectClass );
-        if ( objectClassObject != null )
+        try
         {
-            // Building the list of 'objectClass' attribute values
-            Set<String> objectClassAttributeValues = new HashSet<String>();
-            computeObjectClassAttributeValues( objectClassAttributeValues, objectClassObject );
+            ObjectClass objectClassObject = ServerConfigurationEditorUtils.getObjectClass( OpenLdapConfigurationPlugin
+                .getDefault().getSchemaManager(), objectClass );
+
+            if ( objectClassObject != null )
+            {
+                // Building the list of 'objectClass' attribute values
+                Set<String> objectClassAttributeValues = new HashSet<String>();
+                computeObjectClassAttributeValues( objectClassAttributeValues, objectClassObject );
 
-            // Adding values to the entry
-            addAttributeTypeValues( SchemaConstants.OBJECT_CLASS_AT, objectClassAttributeValues, entry );
+                // Adding values to the entry
+                addAttributeTypeValues( SchemaConstants.OBJECT_CLASS_AT, objectClassAttributeValues, entry );
+            }
+            else
+            {
+                // TODO: throw an exception 
+            }
         }
-        else
+        catch ( Exception e )
         {
-            // TODO: throw an exception 
+            throw new LdapException( e );
         }
     }
 
@@ -399,34 +526,46 @@ public class ConfigurationWriter
     private void computeObjectClassAttributeValues( Set<String> objectClassAttributeValues, ObjectClass objectClass )
         throws LdapException
     {
-        ObjectClass topObjectClass = schema.getObjectClassDescription( SchemaConstants.TOP_OC );
-        if ( topObjectClass != null )
+        try
         {
-            // TODO throw new exception (there should be a top object class 
-        }
+            SchemaManager schemaManager = OpenLdapConfigurationPlugin.getDefault().getSchemaManager();
 
-        if ( topObjectClass.equals( objectClass ) )
-        {
-            objectClassAttributeValues.add( objectClass.getName() );
-        }
-        else
-        {
-            objectClassAttributeValues.add( objectClass.getName() );
+            ObjectClass topObjectClass = ServerConfigurationEditorUtils.getObjectClass( schemaManager,
+                SchemaConstants.TOP_OC );
 
-            List<String> superiors = objectClass.getSuperiorOids();
-            if ( ( superiors != null ) && ( superiors.size() > 0 ) )
+            if ( topObjectClass != null )
             {
-                for ( String superior : superiors )
-                {
-                    ObjectClass superiorObjectClass = schema.getObjectClassDescription( superior );
-                    computeObjectClassAttributeValues( objectClassAttributeValues, superiorObjectClass );
-                }
+                // TODO throw new exception (there should be a top object class 
+            }
+
+            if ( topObjectClass.equals( objectClass ) )
+            {
+                objectClassAttributeValues.add( objectClass.getName() );
             }
             else
             {
-                objectClassAttributeValues.add( topObjectClass.getName() );
+                objectClassAttributeValues.add( objectClass.getName() );
+
+                List<String> superiors = objectClass.getSuperiorOids();
+                if ( ( superiors != null ) && ( superiors.size() > 0 ) )
+                {
+                    for ( String superior : superiors )
+                    {
+                        ObjectClass superiorObjectClass = ServerConfigurationEditorUtils.getObjectClass( schemaManager,
+                            superior );
+                        computeObjectClassAttributeValues( objectClassAttributeValues, superiorObjectClass );
+                    }
+                }
+                else
+                {
+                    objectClassAttributeValues.add( topObjectClass.getName() );
+                }
             }
         }
+        catch ( Exception e )
+        {
+            throw new LdapException( e );
+        }
     }
 
 

Modified: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/SaveConfigurationRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/SaveConfigurationRunnable.java?rev=1670531&r1=1670530&r2=1670531&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/SaveConfigurationRunnable.java (original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/SaveConfigurationRunnable.java Wed Apr  1 01:01:42 2015
@@ -1,5 +1,4 @@
 /*
-/*
  *  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
@@ -23,13 +22,12 @@ package org.apache.directory.studio.open
 
 import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
-import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.ui.IEditorInput;
 
 import org.apache.directory.studio.openldap.config.editor.ConnectionServerConfigurationInput;
+import org.apache.directory.studio.openldap.config.editor.DirectoryServerConfigurationInput;
 import org.apache.directory.studio.openldap.config.editor.ServerConfigurationEditor;
 import org.apache.directory.studio.openldap.config.editor.ServerConfigurationEditorUtils;
 
@@ -99,22 +97,18 @@ public class SaveConfigurationRunnable i
                 IEditorInput input = editor.getEditorInput();
                 boolean success = false;
 
-                // If the input is a ConnectionServerConfigurationInput, then we 
-                // read the server configuration from the selected connection
                 if ( input instanceof ConnectionServerConfigurationInput )
                 {
-                    ConnectionServerConfigurationInput connectionServerConfigurationInput = ( ConnectionServerConfigurationInput ) input;
-
-                    // Getting the browser connection associated with the connection in the input
-                    IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
-                        .getBrowserConnection( connectionServerConfigurationInput.getConnection() );
-
-                    ConfigurationWriter configurationWriter = new ConfigurationWriter( browserConnection.getSchema(),
-                        editor.getConfiguration() );
-
                     // Saving the ServerConfiguration to the connection
                     ServerConfigurationEditorUtils.saveConfiguration( ( ConnectionServerConfigurationInput ) input,
-                        configurationWriter, monitor );
+                        editor, monitor );
+                    success = true;
+                }
+                else if ( input instanceof DirectoryServerConfigurationInput )
+                {
+                    // Saving the ServerConfiguration to the 'slapd.d' directory
+                    ServerConfigurationEditorUtils.saveConfiguration( editor.getConfiguration(),
+                        ( ( DirectoryServerConfigurationInput ) input ).getDirectory() );
                     success = true;
                 }
 

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/IndicesWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/IndicesWidget.java?rev=1670531&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/IndicesWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/IndicesWidget.java Wed Apr  1 01:01:42 2015
@@ -0,0 +1,328 @@
+/*
+ *  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.openldap.config.model.widgets;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPlugin;
+import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPluginConstants;
+import org.apache.directory.studio.openldap.config.editor.dialogs.IndexDialog;
+import org.apache.directory.studio.openldap.config.model.OlcDbIndex;
+
+
+/**
+ * The IndicesWidget provides a table viewer to add/edit/remove an index.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class IndicesWidget extends BrowserWidget
+{
+    /** The indices list */
+    private List<String> indices = new ArrayList<String>();
+
+    /** The connection */
+    private IBrowserConnection browserConnection;
+
+    // UI widgets
+    private Composite composite;
+    private Table table;
+    private TableViewer tableViewer;
+    private Button addButton;
+    private Button editButton;
+    private Button deleteButton;
+
+    // Listeners
+    private ISelectionChangedListener tableViewerSelectionChangedListener = new ISelectionChangedListener()
+    {
+        public void selectionChanged( SelectionChangedEvent event )
+        {
+            StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+
+            editButton.setEnabled( !selection.isEmpty() );
+            deleteButton.setEnabled( !selection.isEmpty() );
+        }
+    };
+    private IDoubleClickListener tableViewerDoubleClickListener = new IDoubleClickListener()
+    {
+        public void doubleClick( DoubleClickEvent event )
+        {
+            editIndex();
+        }
+    };
+    private SelectionListener addButtonListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            addIndex();
+        }
+    };
+    private SelectionListener editButtonListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            editIndex();
+        }
+    };
+    private SelectionListener deleteButtonListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            deleteIndex();
+        }
+    };
+
+
+    /**
+     * Creates a new instance of LockDetectWidget.
+     *
+     * @param connection the browserConnection
+     */
+    public IndicesWidget( IBrowserConnection browserConnection )
+    {
+        this.browserConnection = browserConnection;
+    }
+
+
+    /**
+     * Creates the widget.
+     * 
+     * @param parent the parent
+     */
+    public void createWidget( Composite parent )
+    {
+        createWidget( parent, null );
+    }
+
+
+    /**
+     * Creates the widget.
+     * 
+     * @param parent the parent
+     * @param toolkit the toolkit
+     */
+    public void createWidget( Composite parent, FormToolkit toolkit )
+    {
+        // Composite
+        if ( toolkit != null )
+        {
+            composite = toolkit.createComposite( parent );
+        }
+        else
+        {
+            composite = new Composite( parent, SWT.NONE );
+        }
+        GridLayout compositeGridLayout = new GridLayout( 2, false );
+        compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
+        composite.setLayout( compositeGridLayout );
+
+        // Table and Table Viewer
+        if ( toolkit != null )
+        {
+            table = toolkit.createTable( composite, SWT.NULL );
+        }
+        else
+        {
+            table = new Table( composite, SWT.NULL );
+        }
+        GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 3 );
+        gd.heightHint = 20;
+        gd.widthHint = 100;
+        table.setLayoutData( gd );
+        tableViewer = new TableViewer( table );
+        tableViewer.setContentProvider( new ArrayContentProvider() );
+        tableViewer.setLabelProvider( new LabelProvider()
+        {
+            public Image getImage( Object element )
+            {
+                return OpenLdapConfigurationPlugin.getDefault().getImage(
+                    OpenLdapConfigurationPluginConstants.IMG_INDEX );
+            }
+        } );
+        tableViewer.addSelectionChangedListener( tableViewerSelectionChangedListener );
+        tableViewer.addDoubleClickListener( tableViewerDoubleClickListener );
+        tableViewer.setInput( indices );
+
+        // Add Button
+        if ( toolkit != null )
+        {
+            addButton = toolkit.createButton( composite, "Add...", SWT.PUSH );
+        }
+        else
+        {
+            addButton = BaseWidgetUtils.createButton( composite, "Add...", 1 );
+        }
+        addButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        addButton.addSelectionListener( addButtonListener );
+
+        // Edit Button
+        if ( toolkit != null )
+        {
+            editButton = toolkit.createButton( composite, "Edit...", SWT.PUSH );
+        }
+        else
+        {
+            editButton = BaseWidgetUtils.createButton( composite, "Edit...", SWT.PUSH );
+        }
+        editButton.setEnabled( false );
+        editButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        editButton.addSelectionListener( editButtonListener );
+
+        // Delete Button
+        if ( toolkit != null )
+        {
+            deleteButton = toolkit.createButton( composite, "Delete", SWT.PUSH );
+        }
+        else
+        {
+            deleteButton = BaseWidgetUtils.createButton( composite, "Delete", SWT.PUSH );
+        }
+        deleteButton.setEnabled( false );
+        deleteButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+        deleteButton.addSelectionListener( deleteButtonListener );
+    }
+
+
+    /**
+     * Returns the primary control associated with this widget.
+     *
+     * @return the primary control associated with this widget.
+     */
+    public Control getControl()
+    {
+        return composite;
+    }
+
+
+    /**
+     * Sets the indices.
+     *
+     * @param indices the indices
+     */
+    public void setIndices( List<String> indices )
+    {
+        if ( ( indices != null ) && ( indices.size() > 0 ) )
+        {
+            this.indices.addAll( indices );
+        }
+
+        tableViewer.refresh();
+    }
+
+
+    /**
+     * Gets the indices.
+     *
+     * @return the indices
+     */
+    public List<String> getIndices()
+    {
+        return indices;
+    }
+
+
+    /**
+     * This method is called when the 'Add...' button is clicked.
+     */
+    private void addIndex()
+    {
+        IndexDialog dialog = new IndexDialog( addButton.getShell(), null,
+            browserConnection );
+        if ( dialog.open() == IndexDialog.OK )
+        {
+            OlcDbIndex newIndex = dialog.getNewIndex();
+            indices.add( newIndex.toString() );
+            tableViewer.refresh();
+            tableViewer.setSelection( new StructuredSelection( newIndex.toString() ) );
+            notifyListeners();
+        }
+    }
+
+
+    /**
+     * This method is called when the 'Edit...' button is clicked
+     * or the table viewer is double-clicked.
+     */
+    private void editIndex()
+    {
+        StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+
+        if ( !selection.isEmpty() )
+        {
+            String selectedIndex = ( String ) selection.getFirstElement();
+
+            IndexDialog dialog = new IndexDialog( addButton.getShell(), new OlcDbIndex( selectedIndex ),
+                browserConnection );
+            if ( dialog.open() == IndexDialog.OK )
+            {
+                OlcDbIndex newIndex = dialog.getNewIndex();
+                int selectedIndexPosition = indices.indexOf( selectedIndex );
+                indices.remove( selectedIndex );
+                indices.add( selectedIndexPosition, newIndex.toString() );
+                tableViewer.refresh();
+                tableViewer.setSelection( new StructuredSelection( newIndex.toString() ) );
+                notifyListeners();
+            }
+        }
+    }
+
+
+    /**
+     * This method is called when the 'Delete' button is clicked.
+     */
+    private void deleteIndex()
+    {
+        StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+
+        if ( !selection.isEmpty() )
+        {
+            String selectedIndex = ( String ) selection.getFirstElement();
+
+            indices.remove( selectedIndex );
+            tableViewer.refresh();
+            notifyListeners();
+        }
+    }
+}

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/LockDetectWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/LockDetectWidget.java?rev=1670531&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/LockDetectWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/widgets/LockDetectWidget.java Wed Apr  1 01:01:42 2015
@@ -0,0 +1,192 @@
+/*
+ *  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.openldap.config.model.widgets;
+
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import org.apache.directory.studio.openldap.config.model.OlcBdbConfigLockDetectEnum;
+
+
+/**
+ * The LockDetectWidget provides a combo to select the Lock Detect value.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LockDetectWidget extends BrowserWidget
+{
+    /** The combo viewer's values */
+    private Object[] comboViewerValues = new Object[]
+        {
+            new NoneObject(),
+            OlcBdbConfigLockDetectEnum.DEFAULT,
+            OlcBdbConfigLockDetectEnum.RANDOM,
+            OlcBdbConfigLockDetectEnum.OLDEST,
+            OlcBdbConfigLockDetectEnum.YOUNGEST,
+            OlcBdbConfigLockDetectEnum.FEWEST
+    };
+
+    /** The selected value */
+    private OlcBdbConfigLockDetectEnum value;
+
+    // UI widgets
+    private ComboViewer comboViewer;
+
+
+    /**
+     * Creates a new instance of LockDetectWidget.
+     */
+    public LockDetectWidget()
+    {
+    }
+
+
+    /**
+     * Creates the widget.
+     * 
+     * @param parent the parent
+     */
+    public void createWidget( Composite parent )
+    {
+        createWidget( parent, null );
+    }
+
+
+    /**
+     * Creates the widget.
+     * 
+     * @param parent the parent
+     * @param toolkit the toolkit
+     */
+    public void createWidget( Composite parent, FormToolkit toolkit )
+    {
+        // Combo
+        comboViewer = new ComboViewer( parent );
+        comboViewer.setContentProvider( new ArrayContentProvider() );
+        comboViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof NoneObject )
+                {
+                    return "(No value)";
+                }
+                else if ( element instanceof OlcBdbConfigLockDetectEnum )
+                {
+                    OlcBdbConfigLockDetectEnum lockDetect = ( OlcBdbConfigLockDetectEnum ) element;
+
+                    switch ( lockDetect )
+                    {
+                        case OLDEST:
+                            return "Oldest";
+                        case YOUNGEST:
+                            return "Youngest";
+                        case FEWEST:
+                            return "Fewest";
+                        case RANDOM:
+                            return "Random";
+                        case DEFAULT:
+                            return "Default";
+                    }
+                }
+
+                return super.getText( element );
+            }
+        } );
+        comboViewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                value = null;
+
+                StructuredSelection selection = ( StructuredSelection ) comboViewer.getSelection();
+
+                if ( !selection.isEmpty() )
+                {
+                    Object selectedObject = selection.getFirstElement();
+
+                    if ( selectedObject instanceof OlcBdbConfigLockDetectEnum )
+                    {
+                        value = ( OlcBdbConfigLockDetectEnum ) selectedObject;
+                    }
+                }
+
+                notifyListeners();
+            }
+        } );
+        comboViewer.setInput( comboViewerValues );
+        comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
+    }
+
+
+    /**
+     * Sets the value.
+     *
+     * @param value the value
+     */
+    public void setValue( OlcBdbConfigLockDetectEnum value )
+    {
+        this.value = value;
+
+        if ( value == null )
+        {
+            comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
+        }
+        else
+        {
+            comboViewer.setSelection( new StructuredSelection( value ) );
+        }
+    }
+
+
+    /**
+     * Gets the value.
+     *
+     * @return the value
+     */
+    public OlcBdbConfigLockDetectEnum getValue()
+    {
+        return value;
+    }
+
+
+    /**
+     * Returns the primary control associated with this widget.
+     *
+     * @return the primary control associated with this widget.
+     */
+    public Control getControl()
+    {
+        return comboViewer.getControl();
+    }
+
+    class NoneObject
+    {
+    }
+}