Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 61817 invoked from network); 23 Feb 2009 19:26:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Feb 2009 19:26:52 -0000 Received: (qmail 56552 invoked by uid 500); 23 Feb 2009 19:26:52 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 56495 invoked by uid 500); 23 Feb 2009 19:26:52 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 56486 invoked by uid 99); 23 Feb 2009 19:26:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 11:26:51 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 19:26:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 60C3E238889F; Mon, 23 Feb 2009 19:26:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r747107 - in /directory/studio/trunk: ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/ ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ ldapbrowser-ui/src/main... Date: Mon, 23 Feb 2009 19:26:29 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090223192630.60C3E238889F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: seelmann Date: Mon Feb 23 19:26:28 2009 New Revision: 747107 URL: http://svn.apache.org/viewvc?rev=747107&view=rev Log: o DIRSTUDIO-465: Refresh browser view after RootDSE is reloaded o Extracted code do load RootDSE into its own runnable Added: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeRootDSERunnable.java Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java?rev=747107&r1=747106&r2=747107&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java (original) +++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java Mon Feb 23 19:26:28 2009 @@ -32,6 +32,7 @@ import org.apache.directory.studio.ldapbrowser.core.events.EntryUpdateListener; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; +import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IStructuredSelection; @@ -216,7 +217,7 @@ // AttributesInitializedEvent is fired. If this causes // a refresh of the tree before the children are initialized // another InitializeChildrenJob is executed. - if ( event instanceof AttributesInitializedEvent ) + if ( event instanceof AttributesInitializedEvent && !( event.getModifiedEntry() instanceof IRootDSE ) ) { return; } Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java?rev=747107&r1=747106&r2=747107&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java Mon Feb 23 19:26:28 2009 @@ -287,8 +287,12 @@ LdapDN dn = new LdapDN( record.getDnLine().getValueAsString() ); IEntry entry = browserConnection.getEntryFromCache( dn ); LdapDN parentDn = DnUtils.getParent( dn ); - IEntry parentEntry = parentDn != null ? browserConnection.getEntryFromCache( parentDn ) - : null; + IEntry parentEntry = null; + while(parentEntry == null && parentDn != null) + { + parentEntry = browserConnection.getEntryFromCache( parentDn ); + parentDn = DnUtils.getParent( parentDn ); + } if ( record instanceof LdifChangeDeleteRecord ) { Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java?rev=747107&r1=747106&r2=747107&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeAttributesRunnable.java Mon Feb 23 19:26:28 2009 @@ -24,34 +24,24 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.naming.InvalidNameException; - -import org.apache.directory.shared.ldap.name.LdapDN; import org.apache.directory.shared.ldap.schema.parsers.AttributeTypeDescription; 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.jobs.StudioBulkRunnableWithProgress; +import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob; import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent; import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; 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.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; import org.apache.directory.studio.ldapbrowser.core.model.ISearch; -import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope; -import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry; -import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry; import org.apache.directory.studio.ldapbrowser.core.model.impl.Search; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; @@ -71,14 +61,6 @@ /** The flag if operational attributes should be initialized. */ private boolean initOperationalAttributes; - /** The requested attributes when reading the Root DSE. */ - public static final String[] ROOT_DSE_ATTRIBUTES = - { IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS, IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY, - IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDLDAPVERSION, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDSASLMECHANISM, - IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL, - IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES, IRootDSE.ROOTDSE_ATTRIBUTE_VENDORNAME, - IRootDSE.ROOTDSE_ATTRIBUTE_VENDORVERSION, ISearch.ALL_OPERATIONAL_ATTRIBUTES }; - /** * Creates a new instance of InitializeAttributesRunnable. @@ -229,10 +211,9 @@ if ( entry instanceof IRootDSE ) { // special handling for Root DSE - loadRootDSE( entry.getBrowserConnection(), monitor ); - - entry.setAttributesInitialized( true ); - entry.setChildrenInitialized( true ); + InitializeRootDSERunnable runnable = new InitializeRootDSERunnable( ( IRootDSE ) entry ); + StudioConnectionJob job = new StudioConnectionJob( runnable ); + job.execute(); } else { @@ -274,244 +255,4 @@ entry.setAttributesInitialized( true ); } } - - - /** - * Loads the Root DSE. - * - * @param browserConnection the browser connection - * @param monitor the progress monitor - * - * @throws Exception the exception - */ - static synchronized void loadRootDSE( IBrowserConnection browserConnection, StudioProgressMonitor monitor ) - { - // delete old children - IEntry[] oldChildren = browserConnection.getRootDSE().getChildren(); - if ( oldChildren != null ) - { - for ( IEntry entry : oldChildren ) - { - if ( entry != null ) - { - browserConnection.getRootDSE().deleteChild( entry ); - } - } - } - browserConnection.getRootDSE().setChildrenInitialized( false ); - - // delete old attributes - IAttribute[] oldAttributes = browserConnection.getRootDSE().getAttributes(); - if ( oldAttributes != null ) - { - for ( IAttribute oldAttribute : oldAttributes ) - { - browserConnection.getRootDSE().deleteAttribute( oldAttribute ); - } - } - - // load well-known Root DSE attributes and operational attributes - ISearch search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, - ROOT_DSE_ATTRIBUTES, SearchScope.OBJECT, 0, 0, Connection.AliasDereferencingMethod.NEVER, - Connection.ReferralHandlingMethod.IGNORE, false, null ); - SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); - - // load all user attributes - search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, new String[] - { ISearch.ALL_USER_ATTRIBUTES }, SearchScope.OBJECT, 0, 0, Connection.AliasDereferencingMethod.NEVER, - Connection.ReferralHandlingMethod.IGNORE, false, null ); - SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); - - // the list of entries under the Root DSE - Map rootDseEntries = new HashMap(); - - // 1st: add base DNs, either the specified or from the namingContexts attribute - if ( !browserConnection.isFetchBaseDNs() && browserConnection.getBaseDN() != null - && !"".equals( browserConnection.getBaseDN().toString() ) ) - { - // only add the specified base DN - LdapDN dn = browserConnection.getBaseDN(); - IEntry entry = browserConnection.getEntryFromCache( dn ); - if ( entry == null ) - { - entry = new BaseDNEntry( ( LdapDN ) dn.clone(), browserConnection ); - browserConnection.cacheEntry( entry ); - } - rootDseEntries.put( dn, entry ); - } - else - { - // get base DNs from namingContexts attribute - Set namingContextSet = new HashSet(); - IAttribute attribute = browserConnection.getRootDSE().getAttribute( - IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS ); - if ( attribute != null ) - { - String[] values = attribute.getStringValues(); - for ( int i = 0; i < values.length; i++ ) - { - namingContextSet.add( values[i] ); - } - } - - if ( !namingContextSet.isEmpty() ) - { - for ( String namingContext : namingContextSet ) - { - if ( !"".equals( namingContext ) ) { //$NON-NLS-1$ - try - { - LdapDN dn = new LdapDN( namingContext ); - IEntry entry = browserConnection.getEntryFromCache( dn ); - if ( entry == null ) - { - entry = new BaseDNEntry( dn, browserConnection ); - browserConnection.cacheEntry( entry ); - } - rootDseEntries.put( dn, entry ); - } - catch ( InvalidNameException e ) - { - monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e ); - } - } - else - { - // special handling of empty namingContext (Novell eDirectory): - // perform a one-level search and add all result DNs to the set - searchRootDseEntries( browserConnection, rootDseEntries, monitor ); - } - } - } - else - { - // special handling of non-existing namingContexts attribute (Oracle Internet Directory) - // perform a one-level search and add all result DNs to the set - searchRootDseEntries( browserConnection, rootDseEntries, monitor ); - } - } - - // 2nd: add schema sub-entry - IEntry[] schemaEntries = getDirectoryMetadataEntries( browserConnection, - IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ); - for ( IEntry entry : schemaEntries ) - { - if ( entry instanceof DirectoryMetadataEntry ) - { - ( ( DirectoryMetadataEntry ) entry ).setSchemaEntry( true ); - } - rootDseEntries.put( entry.getDn(), entry ); - } - - // get other meta data entries - IAttribute[] rootDseAttributes = browserConnection.getRootDSE().getAttributes(); - if ( rootDseAttributes != null ) - { - for ( IAttribute attribute : rootDseAttributes ) - { - IEntry[] metadataEntries = getDirectoryMetadataEntries( browserConnection, attribute.getDescription() ); - for ( IEntry entry : metadataEntries ) - { - rootDseEntries.put( entry.getDn(), entry ); - } - } - } - - // try to init entries - StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor ); - for ( IEntry entry : rootDseEntries.values() ) - { - initBaseEntry( entry, dummyMonitor ); - } - - // set flags - browserConnection.getRootDSE().setHasMoreChildren( false ); - browserConnection.getRootDSE().setAttributesInitialized( true ); - browserConnection.getRootDSE().setChildrenInitialized( true ); - browserConnection.getRootDSE().setHasChildrenHint( true ); - browserConnection.getRootDSE().setDirectoryEntry( true ); - } - - - private static void initBaseEntry( IEntry entry, StudioProgressMonitor monitor ) - { - IBrowserConnection browserConnection = entry.getBrowserConnection(); - LdapDN dn = entry.getDn(); - - // search the entry - AliasDereferencingMethod derefAliasMethod = browserConnection.getAliasesDereferencingMethod(); - ReferralHandlingMethod handleReferralsMethod = browserConnection.getReferralsHandlingMethod(); - ISearch search = new Search( null, browserConnection, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, - SearchScope.OBJECT, 1, 0, derefAliasMethod, handleReferralsMethod, true, null ); - SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); - - ISearchResult[] results = search.getSearchResults(); - if ( results != null && results.length == 1 ) - { - // add entry to Root DSE - ISearchResult result = results[0]; - entry = result.getEntry(); - browserConnection.getRootDSE().addChild( entry ); - } - else - { - // DN exists in the Root DSE, but doesn't exist in directory - browserConnection.uncacheEntryRecursive( entry ); - } - } - - - private static IEntry[] getDirectoryMetadataEntries( IBrowserConnection browserConnection, - String metadataAttributeName ) - { - List metadataEntryDnList = new ArrayList(); - IAttribute attribute = browserConnection.getRootDSE().getAttribute( metadataAttributeName ); - if ( attribute != null ) - { - String[] values = attribute.getStringValues(); - for ( String dn : values ) - { - if ( dn != null && !"".equals( dn ) ) - { - try - { - metadataEntryDnList.add( new LdapDN( dn ) ); - } - catch ( InvalidNameException e ) - { - } - } - } - } - - IEntry[] metadataEntries = new IEntry[metadataEntryDnList.size()]; - for ( int i = 0; i < metadataEntryDnList.size(); i++ ) - { - LdapDN dn = metadataEntryDnList.get( i ); - metadataEntries[i] = browserConnection.getEntryFromCache( dn ); - if ( metadataEntries[i] == null ) - { - metadataEntries[i] = new DirectoryMetadataEntry( dn, browserConnection ); - metadataEntries[i].setDirectoryEntry( true ); - browserConnection.cacheEntry( metadataEntries[i] ); - } - } - return metadataEntries; - } - - - private static void searchRootDseEntries( IBrowserConnection browserConnection, Map rootDseEntries, - StudioProgressMonitor monitor ) - { - ISearch search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, - ISearch.NO_ATTRIBUTES, SearchScope.ONELEVEL, 0, 0, Connection.AliasDereferencingMethod.NEVER, - Connection.ReferralHandlingMethod.IGNORE, false, null ); - SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); - ISearchResult[] results = search.getSearchResults(); - for ( ISearchResult searchResult : results ) - { - IEntry entry = searchResult.getEntry(); - rootDseEntries.put( entry.getDn(), entry ); - } - } } Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java?rev=747107&r1=747106&r2=747107&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java (original) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeChildrenRunnable.java Mon Feb 23 19:26:28 2009 @@ -29,6 +29,7 @@ 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.jobs.StudioBulkRunnableWithProgress; +import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob; import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; @@ -151,8 +152,10 @@ { if ( entry instanceof IRootDSE ) { - // special handling for Root DSE. - InitializeAttributesRunnable.loadRootDSE( browserConnection, monitor ); + // special handling for Root DSE + InitializeRootDSERunnable runnable = new InitializeRootDSERunnable( ( IRootDSE ) entry ); + StudioConnectionJob job = new StudioConnectionJob( runnable ); + job.execute(); continue; } Added: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeRootDSERunnable.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeRootDSERunnable.java?rev=747107&view=auto ============================================================================== --- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeRootDSERunnable.java (added) +++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/InitializeRootDSERunnable.java Mon Feb 23 19:26:28 2009 @@ -0,0 +1,391 @@ +/* + * 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.ldapbrowser.core.jobs; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.naming.InvalidNameException; + +import org.apache.directory.shared.ldap.name.LdapDN; +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.jobs.StudioBulkRunnableWithProgress; +import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor; +import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages; +import org.apache.directory.studio.ldapbrowser.core.events.AttributesInitializedEvent; +import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry; +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.IEntry; +import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE; +import org.apache.directory.studio.ldapbrowser.core.model.ISearch; +import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult; +import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope; +import org.apache.directory.studio.ldapbrowser.core.model.impl.BaseDNEntry; +import org.apache.directory.studio.ldapbrowser.core.model.impl.DirectoryMetadataEntry; +import org.apache.directory.studio.ldapbrowser.core.model.impl.Search; + + +/** + * Runnable to initialize the Root DSE. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class InitializeRootDSERunnable implements StudioBulkRunnableWithProgress +{ + + /** The requested attributes when reading the Root DSE. */ + public static final String[] ROOT_DSE_ATTRIBUTES = + { IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS, IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY, + IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDLDAPVERSION, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDSASLMECHANISM, + IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDEXTENSION, IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDCONTROL, + IRootDSE.ROOTDSE_ATTRIBUTE_SUPPORTEDFEATURES, IRootDSE.ROOTDSE_ATTRIBUTE_VENDORNAME, + IRootDSE.ROOTDSE_ATTRIBUTE_VENDORVERSION, ISearch.ALL_OPERATIONAL_ATTRIBUTES }; + + private IRootDSE rootDSE; + + + /** + * Creates a new instance of InitializeRootDSERunnable. + * + * @param rootDSE the root DSE + */ + public InitializeRootDSERunnable( IRootDSE rootDSE ) + { + this.rootDSE = rootDSE; + } + + + /** + * {@inheritDoc} + */ + public Connection[] getConnections() + { + return new Connection[] + { rootDSE.getBrowserConnection().getConnection() }; + } + + + /** + * {@inheritDoc} + */ + public String getName() + { + return BrowserCoreMessages.jobs__init_entries_title_attonly; + } + + + /** + * {@inheritDoc} + */ + public Object[] getLockedObjects() + { + return new IEntry[] + { rootDSE }; + } + + + /** + * {@inheritDoc} + */ + public String getErrorMessage() + { + return BrowserCoreMessages.jobs__init_entries_error_1; + } + + + /** + * {@inheritDoc} + */ + public void run( StudioProgressMonitor monitor ) + { + monitor.beginTask( " ", 3 ); //$NON-NLS-1$ + monitor.reportProgress( " " ); //$NON-NLS-1$ + + monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_task, new String[] + { rootDSE.getDn().getUpName() } ) ); + monitor.worked( 1 ); + + monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__init_entries_progress_att, + new String[] + { rootDSE.getDn().getUpName() } ) ); + + loadRootDSE( rootDSE.getBrowserConnection(), monitor ); + } + + + /** + * {@inheritDoc} + */ + public void runNotification() + { + EventRegistry.fireEntryUpdated( new AttributesInitializedEvent( rootDSE ), this ); + } + + + /** + * Loads the Root DSE. + * + * @param browserConnection the browser connection + * @param monitor the progress monitor + * + * @throws Exception the exception + */ + private static synchronized void loadRootDSE( IBrowserConnection browserConnection, StudioProgressMonitor monitor ) + { + // delete old children + IEntry[] oldChildren = browserConnection.getRootDSE().getChildren(); + if ( oldChildren != null ) + { + for ( IEntry entry : oldChildren ) + { + if ( entry != null ) + { + browserConnection.getRootDSE().deleteChild( entry ); + } + } + } + browserConnection.getRootDSE().setChildrenInitialized( false ); + + // delete old attributes + IAttribute[] oldAttributes = browserConnection.getRootDSE().getAttributes(); + if ( oldAttributes != null ) + { + for ( IAttribute oldAttribute : oldAttributes ) + { + browserConnection.getRootDSE().deleteAttribute( oldAttribute ); + } + } + + // load well-known Root DSE attributes and operational attributes + ISearch search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, + ROOT_DSE_ATTRIBUTES, SearchScope.OBJECT, 0, 0, Connection.AliasDereferencingMethod.NEVER, + Connection.ReferralHandlingMethod.IGNORE, false, null ); + SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); + + // load all user attributes + search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, new String[] + { ISearch.ALL_USER_ATTRIBUTES }, SearchScope.OBJECT, 0, 0, Connection.AliasDereferencingMethod.NEVER, + Connection.ReferralHandlingMethod.IGNORE, false, null ); + SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); + + // the list of entries under the Root DSE + Map rootDseEntries = new HashMap(); + + // 1st: add base DNs, either the specified or from the namingContexts attribute + if ( !browserConnection.isFetchBaseDNs() && browserConnection.getBaseDN() != null + && !"".equals( browserConnection.getBaseDN().toString() ) ) + { + // only add the specified base DN + LdapDN dn = browserConnection.getBaseDN(); + IEntry entry = browserConnection.getEntryFromCache( dn ); + if ( entry == null ) + { + entry = new BaseDNEntry( ( LdapDN ) dn.clone(), browserConnection ); + browserConnection.cacheEntry( entry ); + } + rootDseEntries.put( dn, entry ); + } + else + { + // get base DNs from namingContexts attribute + Set namingContextSet = new HashSet(); + IAttribute attribute = browserConnection.getRootDSE().getAttribute( + IRootDSE.ROOTDSE_ATTRIBUTE_NAMINGCONTEXTS ); + if ( attribute != null ) + { + String[] values = attribute.getStringValues(); + for ( int i = 0; i < values.length; i++ ) + { + namingContextSet.add( values[i] ); + } + } + + if ( !namingContextSet.isEmpty() ) + { + for ( String namingContext : namingContextSet ) + { + if ( !"".equals( namingContext ) ) { //$NON-NLS-1$ + try + { + LdapDN dn = new LdapDN( namingContext ); + IEntry entry = browserConnection.getEntryFromCache( dn ); + if ( entry == null ) + { + entry = new BaseDNEntry( dn, browserConnection ); + browserConnection.cacheEntry( entry ); + } + rootDseEntries.put( dn, entry ); + } + catch ( InvalidNameException e ) + { + monitor.reportError( BrowserCoreMessages.model__error_setting_base_dn, e ); + } + } + else + { + // special handling of empty namingContext (Novell eDirectory): + // perform a one-level search and add all result DNs to the set + searchRootDseEntries( browserConnection, rootDseEntries, monitor ); + } + } + } + else + { + // special handling of non-existing namingContexts attribute (Oracle Internet Directory) + // perform a one-level search and add all result DNs to the set + searchRootDseEntries( browserConnection, rootDseEntries, monitor ); + } + } + + // 2nd: add schema sub-entry + IEntry[] schemaEntries = getDirectoryMetadataEntries( browserConnection, + IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ); + for ( IEntry entry : schemaEntries ) + { + if ( entry instanceof DirectoryMetadataEntry ) + { + ( ( DirectoryMetadataEntry ) entry ).setSchemaEntry( true ); + } + rootDseEntries.put( entry.getDn(), entry ); + } + + // get other meta data entries + IAttribute[] rootDseAttributes = browserConnection.getRootDSE().getAttributes(); + if ( rootDseAttributes != null ) + { + for ( IAttribute attribute : rootDseAttributes ) + { + IEntry[] metadataEntries = getDirectoryMetadataEntries( browserConnection, attribute.getDescription() ); + for ( IEntry entry : metadataEntries ) + { + rootDseEntries.put( entry.getDn(), entry ); + } + } + } + + // try to init entries + StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor ); + for ( IEntry entry : rootDseEntries.values() ) + { + initBaseEntry( entry, dummyMonitor ); + } + + // set flags + browserConnection.getRootDSE().setHasMoreChildren( false ); + browserConnection.getRootDSE().setAttributesInitialized( true ); + browserConnection.getRootDSE().setOperationalAttributesInitialized( true ); + browserConnection.getRootDSE().setChildrenInitialized( true ); + browserConnection.getRootDSE().setHasChildrenHint( true ); + browserConnection.getRootDSE().setDirectoryEntry( true ); + } + + + private static void initBaseEntry( IEntry entry, StudioProgressMonitor monitor ) + { + IBrowserConnection browserConnection = entry.getBrowserConnection(); + LdapDN dn = entry.getDn(); + + // search the entry + AliasDereferencingMethod derefAliasMethod = browserConnection.getAliasesDereferencingMethod(); + ReferralHandlingMethod handleReferralsMethod = browserConnection.getReferralsHandlingMethod(); + ISearch search = new Search( null, browserConnection, dn, ISearch.FILTER_TRUE, ISearch.NO_ATTRIBUTES, + SearchScope.OBJECT, 1, 0, derefAliasMethod, handleReferralsMethod, true, null ); + SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); + + ISearchResult[] results = search.getSearchResults(); + if ( results != null && results.length == 1 ) + { + // add entry to Root DSE + ISearchResult result = results[0]; + entry = result.getEntry(); + browserConnection.getRootDSE().addChild( entry ); + } + else + { + // DN exists in the Root DSE, but doesn't exist in directory + browserConnection.uncacheEntryRecursive( entry ); + } + } + + + private static IEntry[] getDirectoryMetadataEntries( IBrowserConnection browserConnection, + String metadataAttributeName ) + { + List metadataEntryDnList = new ArrayList(); + IAttribute attribute = browserConnection.getRootDSE().getAttribute( metadataAttributeName ); + if ( attribute != null ) + { + String[] values = attribute.getStringValues(); + for ( String dn : values ) + { + if ( dn != null && !"".equals( dn ) ) + { + try + { + metadataEntryDnList.add( new LdapDN( dn ) ); + } + catch ( InvalidNameException e ) + { + } + } + } + } + + IEntry[] metadataEntries = new IEntry[metadataEntryDnList.size()]; + for ( int i = 0; i < metadataEntryDnList.size(); i++ ) + { + LdapDN dn = metadataEntryDnList.get( i ); + metadataEntries[i] = browserConnection.getEntryFromCache( dn ); + if ( metadataEntries[i] == null ) + { + metadataEntries[i] = new DirectoryMetadataEntry( dn, browserConnection ); + metadataEntries[i].setDirectoryEntry( true ); + browserConnection.cacheEntry( metadataEntries[i] ); + } + } + return metadataEntries; + } + + + private static void searchRootDseEntries( IBrowserConnection browserConnection, Map rootDseEntries, + StudioProgressMonitor monitor ) + { + ISearch search = new Search( null, browserConnection, LdapDN.EMPTY_LDAPDN, ISearch.FILTER_TRUE, + ISearch.NO_ATTRIBUTES, SearchScope.ONELEVEL, 0, 0, Connection.AliasDereferencingMethod.NEVER, + Connection.ReferralHandlingMethod.IGNORE, false, null ); + SearchRunnable.searchAndUpdateModel( browserConnection, search, monitor ); + ISearchResult[] results = search.getSearchResults(); + for ( ISearchResult searchResult : results ) + { + IEntry entry = searchResult.getEntry(); + rootDseEntries.put( entry.getDn(), entry ); + } + } +} Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java?rev=747107&r1=747106&r2=747107&view=diff ============================================================================== --- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java (original) +++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/browser/BrowserViewUniversalListener.java Mon Feb 23 19:26:28 2009 @@ -485,7 +485,7 @@ // AttributesInitializedEvent is fired. If this causes // a refresh of the tree before the children are initialized // another InitializeChildrenJob is executed. - if ( event instanceof AttributesInitializedEvent ) + if ( event instanceof AttributesInitializedEvent && !( event.getModifiedEntry() instanceof IRootDSE ) ) { return; }