directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r529634 - in /directory/ldapstudio/trunk/ldapstudio-apacheds-configuration: ./ src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/ src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ src/ma...
Date Tue, 17 Apr 2007 15:04:37 GMT
Author: pamarcelot
Date: Tue Apr 17 08:04:36 2007
New Revision: 529634

URL: http://svn.apache.org/viewvc?view=rev&rev=529634
Log:
Added a new Action for creating a new Configuration File from scratch.
Finished work on the Server Configuration Writer.

Added:
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/NewServerConfigurationAction.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriterException.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/plugin.xml
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/OpenServerConfigurationAction.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ExtendedOperationsMasterDetailsBlock.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionDetailsPage.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditor.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
    directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriter.java

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/plugin.xml
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/plugin.xml?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/plugin.xml (original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/plugin.xml Tue Apr 17 08:04:36
2007
@@ -40,6 +40,12 @@
                label="Open..."
                menubarPath="org.apache.directory.ldapstudio.apacheds.configuration.actionset.menu/open"
                style="push"/>
+         <action
+               class="org.apache.directory.ldapstudio.apacheds.configuration.actions.NewServerConfigurationAction"
+               id="org.apache.directory.ldapstudio.apacheds.configuration.newServerConfiguration"
+               label="New Configuration file"
+               menubarPath="org.apache.directory.ldapstudio.apacheds.configuration.actionset.menu/open"
+               style="push"/>
       </actionSet>
    </extension>
    <extension

Added: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/NewServerConfigurationAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/NewServerConfigurationAction.java?view=auto&rev=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/NewServerConfigurationAction.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/NewServerConfigurationAction.java
Tue Apr 17 08:04:36 2007
@@ -0,0 +1,164 @@
+package org.apache.directory.ldapstudio.apacheds.configuration.actions;
+
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.directory.ldapstudio.apacheds.configuration.Activator;
+import org.apache.directory.ldapstudio.apacheds.configuration.editor.ServerConfigurationEditor;
+import org.apache.directory.ldapstudio.apacheds.configuration.editor.ServerConfigurationEditorInput;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.ExtendedOperation;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.IndexedAttribute;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.Interceptor;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.Partition;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfiguration;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the New Server Configuration Action.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewServerConfigurationAction extends Action implements IWorkbenchWindowActionDelegate
+{
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+     */
+    public void run( IAction action )
+    {
+        // Creating the Default ServerConfiguration
+        ServerConfiguration serverConfiguration = new ServerConfiguration();
+
+        // General Settings
+        serverConfiguration.setAllowAnonymousAccess( false );
+        serverConfiguration.setEnableAccessControl( false );
+        serverConfiguration.setEnableChangePassword( false );
+        serverConfiguration.setEnableKerberos( false );
+        serverConfiguration.setEnableNTP( false );
+        serverConfiguration.setMaxSizeLimit( 1000 );
+        serverConfiguration.setMaxThreads( 8 );
+        serverConfiguration.setMaxTimeLimit( 15000 );
+        serverConfiguration.setPassword( "secret" );
+        serverConfiguration.setPort( 10389 );
+        serverConfiguration.setPrincipal( "uid=admin,ou=system" );
+        serverConfiguration.setSynchronizationPeriod( 15000 );
+
+        // System Partition
+        Partition partition = new Partition( "system" );
+        partition.setSuffix( "ou=system" );
+        Attributes attributes = new BasicAttributes( true );
+        Attribute attribute = new BasicAttribute( "objectClass" );
+        attribute.add( "top" );
+        attribute.add( "organizationalUnit" );
+        attribute.add( "extensibleObject" );
+        attributes.put( attribute );
+        attributes.put( new BasicAttribute( "ou", "system" ) );
+        partition.setContextEntry( attributes );
+        partition.setEnableOptimizer( true );
+        partition.setCacheSize( 100 );
+        partition.setSynchronizationOnWrite( true );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.1",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.2",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.3",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.4",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.5",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.6",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "1.3.6.1.4.1.18060.0.4.1.2.7",
100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "ou", 100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "uid", 100 ) );
+        partition.addIndexedAttribute( new IndexedAttribute( "objectClass", 100 ) );
+        partition.setSystemPartition( true );
+        serverConfiguration.addPartition( partition );
+
+        // Interceptors
+        Interceptor interceptor = new Interceptor( "normalizationService" );
+        interceptor.setClassType( "org.apache.directory.server.core.normalization.NormalizationService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "authenticationService" );
+        interceptor.setClassType( "org.apache.directory.server.core.authn.AuthenticationService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "referralService" );
+        interceptor.setClassType( "org.apache.directory.server.core.referral.ReferralService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "authorizationService" );
+        interceptor.setClassType( "org.apache.directory.server.core.authz.AuthorizationService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "defaultAuthorizationService" );
+        interceptor.setClassType( "org.apache.directory.server.core.authz.DefaultAuthorizationService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "exceptionService" );
+        interceptor.setClassType( "org.apache.directory.server.core.exception.ExceptionService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "operationalAttributeService" );
+        interceptor.setClassType( "org.apache.directory.server.core.operational.OperationalAttributeService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "schemaService" );
+        interceptor.setClassType( "org.apache.directory.server.core.schema.SchemaService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "subentryService" );
+        interceptor.setClassType( "org.apache.directory.server.core.subtree.SubentryService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "collectiveAttributeService" );
+        interceptor.setClassType( "org.apache.directory.server.core.collective.CollectiveAttributeService"
);
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "eventService" );
+        interceptor.setClassType( "org.apache.directory.server.core.event.EventService" );
+        serverConfiguration.addInterceptor( interceptor );
+        interceptor = new Interceptor( "triggerService" );
+        interceptor.setClassType( "org.apache.directory.server.core.trigger.TriggerService"
);
+        serverConfiguration.addInterceptor( interceptor );
+
+        // Extended Operations
+        serverConfiguration.addExtendedOperation( new ExtendedOperation(
+            "org.apache.directory.server.ldap.support.extended.GracefulShutdownHandler" )
);
+        serverConfiguration.addExtendedOperation( new ExtendedOperation(
+            "org.apache.directory.server.ldap.support.extended.LaunchDiagnosticUiHandler"
) );
+
+        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+        try
+        {
+            page.openEditor( new ServerConfigurationEditorInput( serverConfiguration ), ServerConfigurationEditor.ID
);
+        }
+        catch ( PartInitException e )
+        {
+            Activator.getDefault().getLog().log(
+                new Status( Status.ERROR, Activator.PLUGIN_ID, Status.OK, e.getMessage(),
e.getCause() ) );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
org.eclipse.jface.viewers.ISelection)
+     */
+    public void selectionChanged( IAction action, ISelection selection )
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+     */
+    public void dispose()
+    {
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+     */
+    public void init( IWorkbenchWindow window )
+    {
+    }
+}

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/OpenServerConfigurationAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/OpenServerConfigurationAction.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/OpenServerConfigurationAction.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/actions/OpenServerConfigurationAction.java
Tue Apr 17 08:04:36 2007
@@ -35,7 +35,7 @@
     public void run( IAction action )
     {
         FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.OPEN );
-        fd.setText( "Open a Server Configuration file" );
+        fd.setText( "Select a file" );
         fd.setFilterExtensions( new String[]
             { "*.xml", "*.*" } );
         fd.setFilterNames( new String[]
@@ -61,6 +61,7 @@
             messageBox.setText( "Error!" );
             messageBox.setMessage( "An error occurred when reading the file." + "\n" + e.getMessage()
);
             messageBox.open();
+            return;
         }
 
         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
@@ -72,6 +73,7 @@
         {
             Activator.getDefault().getLog().log(
                 new Status( Status.ERROR, Activator.PLUGIN_ID, Status.OK, e.getMessage(),
e.getCause() ) );
+            return;
         }
     }
 

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ExtendedOperationsMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ExtendedOperationsMasterDetailsBlock.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ExtendedOperationsMasterDetailsBlock.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ExtendedOperationsMasterDetailsBlock.java
Tue Apr 17 08:04:36 2007
@@ -70,6 +70,9 @@
     /** The Extended Operations List */
     private List<ExtendedOperation> extendedOperations;
 
+    /** The Details Page */
+    private ExtendedOperationDetailsPage detailsPage;
+
     private static final String NEW_NAME = "newExtendedOperation";
 
     // UI Fields
@@ -281,7 +284,8 @@
      */
     protected void registerPages( DetailsPart detailsPart )
     {
-        detailsPart.registerPage( ExtendedOperation.class, new ExtendedOperationDetailsPage(
this ) );
+        detailsPage = new ExtendedOperationDetailsPage( this );
+        detailsPart.registerPage( ExtendedOperation.class, detailsPage );
     }
 
 
@@ -299,10 +303,7 @@
      */
     public void save()
     {
-        serverConfiguration.clearExtendedOperations();
-        for ( ExtendedOperation extendedOperation : extendedOperations )
-        {
-            serverConfiguration.addExtendedOperation( extendedOperation );
-        }
+        detailsPage.commit( true );
+        viewer.setInput( extendedOperations );
     }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
Tue Apr 17 08:04:36 2007
@@ -70,6 +70,9 @@
     /** The Interceptors List */
     private List<Interceptor> interceptors;
 
+    /** The Details Page */
+    private InterceptorDetailsPage detailsPage;
+
     private static final String NEW_NAME = "New Interceptor ";
 
     // UI Fields
@@ -367,7 +370,8 @@
      */
     protected void registerPages( DetailsPart detailsPart )
     {
-        detailsPart.registerPage( Interceptor.class, new InterceptorDetailsPage( this ) );
+        detailsPage = new InterceptorDetailsPage( this );
+        detailsPart.registerPage( Interceptor.class, detailsPage );
     }
 
 
@@ -385,10 +389,7 @@
      */
     public void save()
     {
-        serverConfiguration.clearInterceptors();
-        for ( Interceptor interceptor : interceptors )
-        {
-            serverConfiguration.addInterceptor( interceptor );
-        }
+        detailsPage.commit( true );
+        viewer.setInput( interceptors );
     }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionDetailsPage.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionDetailsPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionDetailsPage.java
Tue Apr 17 08:04:36 2007
@@ -620,6 +620,10 @@
     public void commit( boolean onSave )
     {
         input.setName( nameText.getText() );
+        input.setCacheSize( Integer.parseInt( cacheSizeText.getText() ) );
+        input.setSuffix( suffixText.getText() );
+        input.setEnableOptimizer( enableOptimizerCheckbox.getSelection() );
+        input.setSynchronizationOnWrite( synchOnWriteCheckbox.getSelection() );
     }
 
 

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
Tue Apr 17 08:04:36 2007
@@ -70,6 +70,9 @@
     /** The Interceptors List */
     private List<Partition> partitions;
 
+    /** The Details Page */
+    private PartitionDetailsPage detailsPage;
+
     private static final String NEW_NAME = "New Partition ";
 
     // UI Fields
@@ -295,7 +298,8 @@
      */
     protected void registerPages( DetailsPart detailsPart )
     {
-        detailsPart.registerPage( Partition.class, new PartitionDetailsPage( this ) );
+        detailsPage = new PartitionDetailsPage( this );
+        detailsPart.registerPage( Partition.class, detailsPage );
     }
 
 
@@ -313,10 +317,7 @@
      */
     public void save()
     {
-        serverConfiguration.clearPartitions();
-        for ( Partition partition : partitions )
-        {
-            serverConfiguration.addPartition( partition );
-        }
+        detailsPage.commit( true );
+        viewer.setInput( partitions );
     }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditor.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditor.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditor.java
Tue Apr 17 08:04:36 2007
@@ -21,12 +21,18 @@
 
 
 import org.apache.directory.ldapstudio.apacheds.configuration.Activator;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfiguration;
 import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfigurationWriter;
+import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfigurationWriterException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.forms.editor.FormEditor;
 
 
@@ -41,6 +47,12 @@
     /** The Editor ID */
     public static final String ID = "org.apache.directory.ldapstudio.apacheds.configuration.editor";
 
+    /** The editor input */
+    private IEditorInput input;
+
+    /** The Server Configuration */
+    private ServerConfiguration serverConfiguration;
+
     /** The dirty flag */
     private boolean dirty = false;
 
@@ -57,8 +69,10 @@
     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
     {
         super.init( site, input );
-
+        this.input = input;
         setPartName( input.getName() );
+        serverConfiguration = ( ( ServerConfigurationEditorInput ) input ).getServerConfiguration();
+        dirty = serverConfiguration.getPath() == null;
     }
 
 
@@ -103,8 +117,48 @@
         monitor.worked( 1 );
         extendedOperationsPage.save();
         monitor.worked( 1 );
-        ServerConfigurationWriter writer = new ServerConfigurationWriter();
-        writer.write( ( ( ServerConfigurationEditorInput ) getEditorInput() ).getServerConfiguration()
);
+
+        // Checking if the ServerConfiguration is already existing or if it's a new file.
+        if ( serverConfiguration.getPath() == null )
+        {
+            FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.SAVE );
+            fd.setText( "Select a file" );
+            fd.setFilterExtensions( new String[]
+                { "*.xml", "*.*" } );
+            fd.setFilterNames( new String[]
+                { "XML files", "All files" } );
+            String selectedFile = fd.open();
+            // selected == null if 'cancel' has been pushed
+            if ( selectedFile == null || "".equals( selectedFile ) )
+            {
+                monitor.setCanceled( true );
+                return;
+            }
+
+            // TODO Add the overwrite code...
+
+            serverConfiguration.setPath( selectedFile );
+            setTitleToolTip( input.getToolTipText() );
+        }
+
+        // Saving the ServerConfiguration to disk
+        try
+        {
+            ServerConfigurationWriter writer = new ServerConfigurationWriter();
+            writer.write( serverConfiguration );
+        }
+        catch ( ServerConfigurationWriterException e )
+        {
+            MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+                SWT.OK | SWT.ICON_ERROR );
+            messageBox.setText( "Error!" );
+            messageBox.setMessage( "An error occurred when writing the file to disk." + "\n"
+ e.getMessage() );
+            messageBox.open();
+            setDirty( true );
+            monitor.done();
+            return;
+        }
+
         monitor.worked( 1 );
         setDirty( false );
         monitor.done();

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditorInput.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
Tue Apr 17 08:04:36 2007
@@ -123,4 +123,28 @@
     {
         return null;
     }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj instanceof ServerConfigurationEditorInput )
+        {
+            ServerConfigurationEditorInput input = ( ServerConfigurationEditorInput ) obj;
+
+            if ( input.exists() && exists() )
+            {
+                String inputPath = input.getServerConfiguration().getPath();
+                String myPath = getServerConfiguration().getPath();
+
+                if ( inputPath != null && myPath != null )
+                {
+                    return inputPath.equals( myPath );
+                }
+            }
+        }
+        return false;
+    }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriter.java?view=diff&rev=529634&r1=529633&r2=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriter.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriter.java
Tue Apr 17 08:04:36 2007
@@ -20,8 +20,14 @@
 package org.apache.directory.ldapstudio.apacheds.configuration.model;
 
 
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
 import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamSource;
@@ -43,30 +49,50 @@
 public class ServerConfigurationWriter
 {
     /**
-     * TODO write.
+     * Writes the Server Configuration to disk.
      *
      * @param serverConfiguration
+     *      the Server Configuration
+     * @throws ServerConfigurationWriterException
+     *      if an error occurrs when writing the Server Configuration file
      */
-    public void write( ServerConfiguration serverConfiguration )
+    public void write( ServerConfiguration serverConfiguration ) throws ServerConfigurationWriterException
     {
-        System.out.println( "Writing file to disk." );
+        try
+        {
+            BufferedWriter outFile = new BufferedWriter( new FileWriter( serverConfiguration.getPath()
) );
 
-        Document document = DocumentHelper.createDocument();
-        Element root = document.addElement( "beans" );
+            Document document = DocumentHelper.createDocument();
+            Element root = document.addElement( "beans" );
 
-        // Environment Bean
-        createEnvironmentBean( root, serverConfiguration );
+            // Environment Bean
+            createEnvironmentBean( root, serverConfiguration );
 
-        // Configuration Bean
-        createConfigurationBean( root, serverConfiguration );
+            // Configuration Bean
+            createConfigurationBean( root, serverConfiguration );
 
-        // System Partition Configuration Bean
-        createSystemPartitionConfigurationBean( root, serverConfiguration );
+            // System Partition Configuration Bean
+            createSystemPartitionConfigurationBean( root, serverConfiguration );
 
-        // User Partitions Beans
-        createUserPartitionConfigurationsBean( root, serverConfiguration );
+            // User Partitions Beans
+            createUserPartitionsConfigurationsBean( root, serverConfiguration );
 
-        System.out.println( styleDocument( document ).asXML() );
+            // CustomEditors Bean
+            createCustomEditorsBean( root );
+
+            Document stylizedDocuement = styleDocument( document );
+            stylizedDocuement.addDocType( "beans", "-//SPRING//DTD BEAN//EN",
+                "http://www.springframework.org/dtd/spring-beans.dtd" );
+            outFile.write( stylizedDocuement.asXML() );
+            outFile.close();
+        }
+        catch ( Exception e )
+        {
+            ServerConfigurationWriterException exception = new ServerConfigurationWriterException(
e.getMessage(), e
+                .getCause() );
+            exception.setStackTrace( e.getStackTrace() );
+            throw exception;
+        }
     }
 
 
@@ -88,14 +114,17 @@
         propertyElement.addAttribute( "name", "properties" );
         Element propsElement = propertyElement.addElement( "props" );
 
+        // Key 'java.naming.security.authentication'
         Element propElement = propsElement.addElement( "prop" );
         propElement.addAttribute( "key", "java.naming.security.authentication" );
         propElement.setText( "simple" );
 
+        // Key 'java.naming.security.principal'
         propElement = propsElement.addElement( "prop" );
         propElement.addAttribute( "key", "java.naming.security.principal" );
         propElement.setText( serverConfiguration.getPrincipal() );
 
+        // Key 'java.naming.security.credentials'
         propElement = propsElement.addElement( "prop" );
         propElement.addAttribute( "key", "java.naming.security.credentials" );
         propElement.setText( serverConfiguration.getPassword() );
@@ -154,7 +183,7 @@
 
         // Enable NTP
         propertyElement = configurationBean.addElement( "property" );
-        propertyElement.addAttribute( "name", "enableNTP" );
+        propertyElement.addAttribute( "name", "enableNtp" );
         propertyElement.addAttribute( "value", "" + serverConfiguration.isEnableNTP() );
 
         // EnableKerberos
@@ -180,7 +209,7 @@
         // SystemPartitionConfiguration
         propertyElement = configurationBean.addElement( "property" );
         propertyElement.addAttribute( "name", "systemPartitionConfiguration" );
-        propertyElement.addAttribute( "value", "systemPartitionConfiguration" );
+        propertyElement.addAttribute( "ref", "systemPartitionConfiguration" );
 
         // PartitionConfigurations
         propertyElement = configurationBean.addElement( "property" );
@@ -229,7 +258,8 @@
 
                 interceptorPropertyElement = interceptorBeanElement.addElement( "property"
);
                 interceptorPropertyElement.addAttribute( "name", "interceptor" );
-                interceptorPropertyElement.addElement( "bean" ).addAttribute( "class", interceptor.getClassType()
);
+                interceptorPropertyElement.addElement( "bean" ).addAttribute( "class",
+                    ( interceptor.getClassType() == null ? "" : interceptor.getClassType()
) );
             }
         }
 
@@ -271,8 +301,17 @@
      * @param serverConfiguration
      *      the Server Configuration
      */
-    private void createUserPartitionConfigurationsBean( Element root, ServerConfiguration
serverConfiguration )
+    private void createUserPartitionsConfigurationsBean( Element root, ServerConfiguration
serverConfiguration )
     {
+        int counter = 1;
+        for ( Partition partition : serverConfiguration.getPartitions() )
+        {
+            if ( !partition.isSystemPartition() )
+            {
+                createPartitionConfigurationBean( root, partition, "partition-" + counter
);
+                counter++;
+            }
+        }
     }
 
 
@@ -288,10 +327,109 @@
      */
     private void createPartitionConfigurationBean( Element root, Partition partition, String
name )
     {
-        Element systemPartitionBean = root.addElement( "bean" );
-        systemPartitionBean.addAttribute( "id", name );
-        systemPartitionBean.addAttribute( "class",
+        Element partitionBean = root.addElement( "bean" );
+        partitionBean.addAttribute( "id", name );
+        partitionBean.addAttribute( "class",
             "org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration"
);
+
+        // Name
+        Element propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "name" );
+        propertyElement.addAttribute( "value", partition.getName() );
+
+        // CacheSize
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "cacheSize" );
+        propertyElement.addAttribute( "value", "" + partition.getCacheSize() );
+
+        // Suffix
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "suffix" );
+        propertyElement.addAttribute( "value", partition.getSuffix() );
+
+        // OptimizerEnabled
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "optimizerEnabled" );
+        propertyElement.addAttribute( "value", "" + partition.isEnableOptimizer() );
+
+        // SynchOnWrite
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "synchOnWrite" );
+        propertyElement.addAttribute( "value", "" + partition.isSynchronizationOnWrite()
);
+
+        // Indexed Attributes
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "indexedAttributes" );
+        if ( partition.getIndexedAttributes().size() > 1 )
+        {
+            Element setElement = propertyElement.addElement( "set" );
+            for ( IndexedAttribute indexedAttribute : partition.getIndexedAttributes() )
+            {
+                Element beanElement = setElement.addElement( "bean" );
+                beanElement.addAttribute( "class",
+                    "org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration"
);
+
+                // AttributeID
+                Element beanPropertyElement = beanElement.addElement( "property" );
+                beanPropertyElement.addAttribute( "name", "attributeId" );
+                beanPropertyElement.addAttribute( "value", indexedAttribute.getAttributeId()
);
+
+                // CacheSize
+                beanPropertyElement = beanElement.addElement( "property" );
+                beanPropertyElement.addAttribute( "name", "cacheSize" );
+                beanPropertyElement.addAttribute( "value", "" + indexedAttribute.getCacheSize()
);
+            }
+        }
+
+        // ContextEntry
+        propertyElement = partitionBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "contextEntry" );
+        if ( partition.getContextEntry() != null )
+        {
+            Element valueElement = propertyElement.addElement( "value" );
+
+            Attributes contextEntry = partition.getContextEntry();
+            StringBuffer sb = new StringBuffer();
+            NamingEnumeration<? extends Attribute> ne = contextEntry.getAll();
+            while ( ne.hasMoreElements() )
+            {
+                Attribute attribute = ( Attribute ) ne.nextElement();
+                try
+                {
+                    NamingEnumeration<?> values = attribute.getAll();
+                    while ( values.hasMoreElements() )
+                    {
+                        sb.append( attribute.getID() + ": " + values.nextElement() + "\n"
);
+                    }
+                }
+                catch ( NamingException e )
+                {
+                }
+            }
+
+            valueElement.setText( sb.toString() );
+        }
+    }
+
+
+    /**
+     * Creates the Custom Editors Bean.
+     *
+     * @param root
+     *      the root Element
+     */
+    private void createCustomEditorsBean( Element root )
+    {
+        Element customEditorsBean = root.addElement( "bean" );
+        customEditorsBean.addAttribute( "class", "org.springframework.beans.factory.config.CustomEditorConfigurer"
);
+        Element propertyElement = customEditorsBean.addElement( "property" );
+        propertyElement.addAttribute( "name", "customEditors" );
+        Element mapElement = propertyElement.addElement( "map" );
+        Element entryElement = mapElement.addElement( "entry" );
+        entryElement.addAttribute( "key", "javax.naming.directory.Attributes" );
+        Element entryBeanElement = entryElement.addElement( "bean" );
+        entryBeanElement.addAttribute( "class",
+            "org.apache.directory.server.core.configuration.AttributesPropertyEditor" );
     }
 
 
@@ -301,35 +439,23 @@
      * @param document
      *      the Dom4j Document
      * @return
+     *      the stylized Document
+     * @throws TransformerException 
      */
-    private Document styleDocument( Document document )
+    private Document styleDocument( Document document ) throws TransformerException
     {
         // load the transformer using JAXP
         TransformerFactory factory = TransformerFactory.newInstance();
         Transformer transformer = null;
-        try
-        {
-            transformer = factory.newTransformer( new StreamSource( Activator.class
-                .getResourceAsStream( "template.xslt" ) ) );
-        }
-        catch ( TransformerConfigurationException e1 )
-        {
-            // TODO Auto-generated catch block
-            e1.printStackTrace();
-        }
+
+        transformer = factory
+            .newTransformer( new StreamSource( Activator.class.getResourceAsStream( "template.xslt"
) ) );
 
         // now lets style the given document
         DocumentSource source = new DocumentSource( document );
         DocumentResult result = new DocumentResult();
-        try
-        {
-            transformer.transform( source, result );
-        }
-        catch ( TransformerException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+
+        transformer.transform( source, result );
 
         // return the transformed document
         Document transformedDoc = result.getDocument();

Added: directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriterException.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriterException.java?view=auto&rev=529634
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriterException.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-apacheds-configuration/src/main/java/org/apache/directory/ldapstudio/apacheds/configuration/model/ServerConfigurationWriterException.java
Tue Apr 17 08:04:36 2007
@@ -0,0 +1,51 @@
+/*
+ *  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.ldapstudio.apacheds.configuration.model;
+
+
+/**
+ * This class represents the Server Configuration Writer Exception, that can be thrown
+ * when an error is detected when writing the Server Configuration file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerConfigurationWriterException extends Exception
+{
+    /** The Serial Version UID */
+    private static final long serialVersionUID = -2360825137845553569L;
+
+
+    /**
+     * Creates a new instance of ServerConfigurationParserException.
+     *
+     * @param message
+     *      the detail message (which is saved for later retrieval by the 
+     *      getMessage() method).
+     * @param cause
+     *      the cause (which is saved for later retrieval by the getCause() 
+     *      method). (A null value is permitted, and indicates that the cause 
+     *      is nonexistent or unknown.)
+     */
+    public ServerConfigurationWriterException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}



Mime
View raw message