directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1049592 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: actions/ editor/ jobs/
Date Wed, 15 Dec 2010 15:35:20 GMT
Author: pamarcelot
Date: Wed Dec 15 15:35:19 2010
New Revision: 1049592

URL: http://svn.apache.org/viewvc?rev=1049592&view=rev
Log:
Added support for reading the configuration from a selected connection in the LDAP Browser
view.

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ConnectionServerConfigurationInput.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/EntryBasedConfigurationPartition.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java?rev=1049592&r1=1049591&r2=1049592&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/OpenConfigurationAction.java
Wed Dec 15 15:35:19 2010
@@ -34,11 +34,14 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
 import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
 import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ConnectionServerConfigurationInput;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.NewServerConfigurationInput;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationInput;
+import org.apache.directory.studio.connection.core.Connection;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
@@ -53,29 +56,37 @@ import org.eclipse.ui.PlatformUI;
  */
 public class OpenConfigurationAction implements IObjectActionDelegate
 {
+    /** The selected connection */
+    private Connection selectedConnection;
+
+
     /**
      * {@inheritDoc}
      */
     public void run( IAction action )
     {
-        try
+        if ( selectedConnection != null )
         {
-            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
             try
             {
-                page.openEditor( new NewServerConfigurationInput(), ServerConfigurationEditor.ID
);
+                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+                try
+                {
+                    page.openEditor( new ConnectionServerConfigurationInput( selectedConnection
),
+                        ServerConfigurationEditor.ID );
+                }
+                catch ( PartInitException e )
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
             }
-            catch ( PartInitException e )
+            catch ( Exception e )
             {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
         }
-        catch ( Exception e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
     }
 
 
@@ -84,8 +95,15 @@ public class OpenConfigurationAction imp
      */
     public void selectionChanged( IAction action, ISelection selection )
     {
-        // TODO Auto-generated method stub
-
+        StructuredSelection structuredSelection = ( StructuredSelection ) selection;
+        if ( ( structuredSelection.size() == 1 ) && ( structuredSelection.getFirstElement()
instanceof Connection ) )
+        {
+            selectedConnection = ( Connection ) structuredSelection.getFirstElement();
+        }
+        else
+        {
+            selectedConnection = null;
+        }
     }
 
 
@@ -94,7 +112,6 @@ public class OpenConfigurationAction imp
      */
     public void setActivePart( IAction action, IWorkbenchPart targetPart )
     {
-        // TODO Auto-generated method stub
-
+        // Nothing to do
     }
 }

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ConnectionServerConfigurationInput.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ConnectionServerConfigurationInput.java?rev=1049592&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ConnectionServerConfigurationInput.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ConnectionServerConfigurationInput.java
Wed Dec 15 15:35:19 2010
@@ -0,0 +1,116 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.configuration.v2.editor;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+
+/**
+ * This class represents the Non Existing Server Configuration Input.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ConnectionServerConfigurationInput implements IEditorInput
+{
+    /** The connection */
+    private Connection connection;
+
+
+    /**
+     * Creates a new instance of ConnectionServerConfigurationInput.
+     *
+     * @param connection
+     *      the connection
+     */
+    public ConnectionServerConfigurationInput( Connection connection )
+    {
+        this.connection = connection;
+    }
+
+    
+    /**
+     * Gets the connection.
+     *
+     * @return
+     *      the connection
+     */
+    public Connection getConnection()
+    {
+        return connection;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getToolTipText()
+    {
+        return NLS.bind( "{0} - Configuration", connection.getName() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getName()
+    {
+        return NLS.bind( "{0} - Configuration", connection.getName() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean exists()
+    {
+        return connection != null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ImageDescriptor getImageDescriptor()
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IPersistableElement getPersistable()
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getAdapter( Class adapter )
+    {
+        return null;
+    }
+}

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/EntryBasedConfigurationPartition.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/EntryBasedConfigurationPartition.java?rev=1049592&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/EntryBasedConfigurationPartition.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/EntryBasedConfigurationPartition.java
Wed Dec 15 15:35:19 2010
@@ -0,0 +1,180 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.configuration.v2.jobs;
+
+
+import java.util.UUID;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.interceptor.context.BindOperationContext;
+import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
+import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition;
+import org.apache.directory.server.xdbm.impl.avl.AvlStore;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+
+
+/**
+ * This class implements a read-only configuration partition.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryBasedConfigurationPartition extends AbstractLdifPartition
+{
+    /**
+     * Creates a new instance of ReadOnlyConfigurationPartition.
+     *
+     * @param inputStream
+     *      the input stream
+     * @param schemaManager
+     *      the schema manager
+     */
+    public EntryBasedConfigurationPartition( SchemaManager schemaManager )
+    {
+        setSchemaManager( schemaManager );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void doInit() throws InvalidNameException, Exception
+    {
+        // Initializing the wrapped partition
+        setWrappedPartition( new AvlPartition() );
+        setId( "config" );
+        setSuffix( new DN( "ou=config" ) );
+        wrappedPartition.setSchemaManager( schemaManager );
+        wrappedPartition.initialize();
+
+        // Getting the search engine
+        searchEngine = wrappedPartition.getSearchEngine();
+    }
+
+
+    /**
+     * Adds the given entry.
+     *
+     * @param entry
+     *      the entry
+     * @throws Exception
+     */
+    public void addEntry( Entry entry ) throws Exception
+    {
+        // Adding mandatory operational attributes
+        addMandatoryOpAt( entry );
+
+        // Storing the entry
+        wrappedPartition.getStore().add( entry );
+    }
+
+
+    /**
+     * Adds the CSN and UUID attributes to the entry if they are not present.
+     */
+    private void addMandatoryOpAt( Entry entry ) throws LdapException
+    {
+        // entryCSN
+        if ( entry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+        {
+            entry.add( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()
);
+        }
+
+        // entryUUID
+        if ( entry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+        {
+            String uuid = UUID.randomUUID().toString();
+            entry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void bind( BindOperationContext bindOperationContext ) throws LdapException
+    {
+        wrappedPartition.bind( bindOperationContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void add( AddOperationContext addOperationContext ) throws LdapException
+    {
+        System.out.println( "add" );
+        wrappedPartition.add( addOperationContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void delete( Long id ) throws LdapException
+    {
+        wrappedPartition.delete( id );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void modify( ModifyOperationContext modifyOperationContext ) throws LdapException
+    {
+        wrappedPartition.modify( modifyOperationContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void move( MoveOperationContext moveOperationContext ) throws LdapException
+    {
+        wrappedPartition.move( moveOperationContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void moveAndRename( MoveAndRenameOperationContext moveAndRenameOperationContext
) throws LdapException
+    {
+        wrappedPartition.moveAndRename( moveAndRenameOperationContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rename( RenameOperationContext renameOperationContext ) throws LdapException
+    {
+        wrappedPartition.rename( renameOperationContext );
+    }
+}

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java?rev=1049592&r1=1049591&r2=1049592&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
Wed Dec 15 15:35:19 2010
@@ -23,19 +23,35 @@ package org.apache.directory.studio.apac
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.Control;
 
 import org.apache.directory.server.config.ConfigPartitionReader;
 import org.apache.directory.server.config.ReadOnlyConfigurationPartition;
 import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ConnectionServerConfigurationInput;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.NewServerConfigurationInput;
 import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
 import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
-import org.eclipse.core.runtime.CoreException;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
+import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
+import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
+import org.apache.directory.studio.connection.core.io.StudioNamingEnumeration;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
@@ -104,7 +120,7 @@ public class LoadConfigurationRunnable i
         ConfigBean configBean = null;
         try
         {
-            configBean = getConfiguration( input );
+            configBean = getConfiguration( input, monitor );
             if ( configBean != null )
             {
                 final ConfigBean finalConfigBean = configBean;
@@ -128,62 +144,46 @@ public class LoadConfigurationRunnable i
 
     /**
      * Gets a new default configuration.
-     *
+     * 
+     * @param input
+     *      the editor input
+     * @param monitor
+     *      the studio progress monitor
      * @return
-     *      a new default configuration
+     *      the configuration
      * @throws Exception
      */
-    public ConfigBean getConfiguration( IEditorInput input ) throws Exception
+    public ConfigBean getConfiguration( IEditorInput input, StudioProgressMonitor monitor
) throws Exception
     {
         // Getting the schema manager
         SchemaManager schemaManager = ApacheDS2ConfigurationPlugin.getDefault().getSchemaManager();
 
-        // Getting an input stream to the configuration
-        InputStream is = getInputStream( input );
-        if ( is != null )
-        {
-            // Creating a partition associated from the input stream
-            ReadOnlyConfigurationPartition configurationPartition = new ReadOnlyConfigurationPartition(
-                ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif" ),
schemaManager );
-            configurationPartition.initialize();
-
-            // Reading the configuration partition
-            ConfigPartitionReader cpReader = new ConfigPartitionReader( configurationPartition
);
-            return cpReader.readConfig();
-        }
-
-        return null;
-    }
-
-
-    /**
-     * Gets an input stream from the editor input.
-     *
-     * @param input
-     *      the editor input
-     * @return
-     *      an input stream from the editor input, or <code>null</code>
-     * @throws CoreException
-     * @throws FileNotFoundException
-     */
-    private InputStream getInputStream( IEditorInput input ) throws CoreException, FileNotFoundException
-    {
         String inputClassName = input.getClass().getName();
         // If the input is a NewServerConfigurationInput, then we only 
         // need to get the server configuration and return
         if ( input instanceof NewServerConfigurationInput )
         {
-            return ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif"
);
+            InputStream is = ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif"
);
+            return readConfiguration( schemaManager, is );
+        }
+        // If the input is a ConnectionServerConfigurationInput, then we 
+        // read the server configuration from the selected connection
+        if ( input instanceof ConnectionServerConfigurationInput )
+        {
+            Connection connection = ( ( ConnectionServerConfigurationInput ) input ).getConnection();
+            return readConfiguration( schemaManager, connection, monitor );
         }
         else if ( input instanceof FileEditorInput )
         // The 'FileEditorInput' class is used when the file is opened
         // from a project in the workspace.
         {
-            return ( ( FileEditorInput ) input ).getFile().getContents();
+            InputStream is = ( ( FileEditorInput ) input ).getFile().getContents();
+            return readConfiguration( schemaManager, is );
         }
         else if ( input instanceof IPathEditorInput )
         {
-            return new FileInputStream( new File( ( ( IPathEditorInput ) input ).getPath().toOSString()
) );
+            InputStream is = new FileInputStream( new File( ( ( IPathEditorInput ) input
).getPath().toOSString() ) );
+            return readConfiguration( schemaManager, is );
         }
         else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput"
) //$NON-NLS-1$
             || inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" ) ) //$NON-NLS-1$
@@ -193,7 +193,165 @@ public class LoadConfigurationRunnable i
         // opening a file from the menu File > Open... in Eclipse 3.3.x
         {
             // We use the tooltip to get the full path of the file
-            return new FileInputStream( new File( input.getToolTipText() ) );
+            InputStream is = new FileInputStream( new File( input.getToolTipText() ) );
+            return readConfiguration( schemaManager, is );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Reads the configuration from the given input stream.
+     *
+     * @param schemaManager
+     *      the schema manager
+     * @param is
+     *      the input stream
+     * @return
+     *      the associated configuration bean
+     * @throws Exception
+     */
+    private ConfigBean readConfiguration( SchemaManager schemaManager, InputStream is ) throws
Exception
+    {
+        if ( is != null )
+        {
+            // Creating a partition associated from the input stream
+            ReadOnlyConfigurationPartition configurationPartition = new ReadOnlyConfigurationPartition(
+                ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif" ),
schemaManager );
+            configurationPartition.initialize();
+
+            // Reading the configuration partition
+            return readConfiguration( configurationPartition );
+
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Reads the configuration from the given partition.
+     *
+     * @param partition
+     *      the configuration partition
+     * @return
+     *      the associated configuration bean
+     * @throws LdapException
+     */
+    private ConfigBean readConfiguration( BTreePartition<Long> partition ) throws LdapException
+    {
+        if ( partition != null )
+        {
+            ConfigPartitionReader cpReader = new ConfigPartitionReader( partition );
+            return cpReader.readConfig();
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Reads the configuration from the given connection.
+     *
+     * @param schemaManager
+     *      the schema manager
+     * @param connection
+     *      the connection
+     * @param monitor 
+     *      the studio progress monitor
+     * @return
+     *      the associated configuration bean
+     * @throws Exception
+     */
+    private ConfigBean readConfiguration( SchemaManager schemaManager, Connection connection,
+        StudioProgressMonitor monitor ) throws Exception
+    {
+        if ( connection != null )
+        {
+            ConnectionWrapper connectionWrapper = connection.getConnectionWrapper();
+
+            // Creating and initializing the configuration partition
+            EntryBasedConfigurationPartition configurationPartition = new EntryBasedConfigurationPartition(
+                schemaManager );
+            configurationPartition.initialize();
+
+            // Preparing a few search objects
+            SearchControls searchControls = new SearchControls();
+            searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
+            searchControls.setReturningAttributes( new String[]
+                { "*" } );
+            String searchBase = "ou=config";
+            String filter = "(objectClass=*)";
+            AliasDereferencingMethod aliasDereferencingMethod = AliasDereferencingMethod.ALWAYS;
+            ReferralHandlingMethod referralHandlingMethod = ReferralHandlingMethod.IGNORE;
+            Control[] controls = new Control[0];
+
+            // Looking for the 'ou=config' base entry
+            Entry configEntry = null;
+            StudioNamingEnumeration enumeration = connectionWrapper.search( searchBase, filter,
searchControls,
+                aliasDereferencingMethod, referralHandlingMethod, controls, monitor, null
);
+            if ( enumeration.hasMore() )
+            {
+                // Creating the 'ou=config' base entry
+                SearchResult searchResult = ( SearchResult ) enumeration.next();
+                configEntry = new DefaultEntry( schemaManager, AttributeUtils.toClientEntry(
+                    searchResult.getAttributes(), new DN( searchResult.getName() ) ) );
+            }
+            enumeration.close();
+
+            // Verifying we found the 'ou=config' base entry
+            if ( configEntry == null )
+            {
+                // TODO throw a new error
+            }
+
+            // Creating a list to hold the entries that needs to be checked
+            // for children and added to the partition
+            List<Entry> entries = new ArrayList<Entry>();
+            entries.add( configEntry );
+
+            // Updating the search scope to 'One Level'
+            searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+
+            // Flag used to determine if the current entry is the context entry
+            boolean isContextEntry = true;
+
+            // Looping on the entries list until it's empty
+            while ( !entries.isEmpty() )
+            {
+                // Removing the first entry from the list
+                Entry entry = entries.remove( 0 );
+
+                // Special handling for the context entry
+                if ( isContextEntry )
+                {
+                    // Setting the context entry of the partition
+                    configurationPartition.setContextEntry( entry );
+                    isContextEntry = false;
+                }
+
+                // Adding the entry to the partition
+                configurationPartition.addEntry( entry );
+
+                // Looking for the children of the entry
+                StudioNamingEnumeration childrenEnumeration = connectionWrapper.search( entry.getDn().toString(),
+                    filter, searchControls, aliasDereferencingMethod, referralHandlingMethod,
new Control[0], monitor,
+                    null );
+                while ( childrenEnumeration.hasMore() )
+                {
+                    // Creating the child entry
+                    SearchResult searchResult = ( SearchResult ) childrenEnumeration.next();
+                    Entry childEntry = new DefaultEntry( schemaManager, AttributeUtils.toClientEntry(
+                        searchResult.getAttributes(), new DN( searchResult.getName() ) )
);
+
+                    // Adding the children to the list of entries
+                    entries.add( childEntry );
+                }
+                childrenEnumeration.close();
+            }
+
+            return readConfiguration( configurationPartition );
         }
 
         return null;



Mime
View raw message