You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2008/06/05 20:58:13 UTC

svn commit: r663698 - in /directory/studio/trunk: ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ ldapbrowser-core/src/main/java/org/apache/d...

Author: seelmann
Date: Thu Jun  5 11:58:13 2008
New Revision: 663698

URL: http://svn.apache.org/viewvc?rev=663698&view=rev
Log:
First fix for DIRSTUDIO-326:
o Changed the way how the schema is loaded
o Schema caching did not work


Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java?rev=663698&r1=663697&r2=663698&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java Thu Jun  5 11:58:13 2008
@@ -25,7 +25,6 @@
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.IConnectionListener;
@@ -34,15 +33,8 @@
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesJob;
 import org.apache.directory.studio.ldapbrowser.core.jobs.ReloadSchemasJob;
-import org.apache.directory.studio.ldapbrowser.core.jobs.SearchJob;
-import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
 import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
 
@@ -79,6 +71,9 @@
                 BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
                     browserConnection, BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_OPENED );
                 EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this );
+                BrowserConnectionUpdateEvent schemaUpdateEvent = new BrowserConnectionUpdateEvent( browserConnection,
+                    BrowserConnectionUpdateEvent.Detail.SCHEMA_UPDATED );
+                EventRegistry.fireBrowserConnectionUpdated( schemaUpdateEvent, this );
             }
         }
     }
@@ -117,78 +112,10 @@
      */
     private static void openBrowserConnection( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
     {
+        ReloadSchemasJob.reloadSchema( false, browserConnection, monitor );
+
         IRootDSE rootDSE = browserConnection.getRootDSE();
         InitializeAttributesJob.initializeAttributes( rootDSE, true, monitor );
-
-        // check schema reload
-        if ( rootDSE != null )
-        {
-            try
-            {
-                monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
-
-                // check if schema is cached
-                Schema schema = browserConnection.getSchema();
-                if ( schema == Schema.DEFAULT_SCHEMA )
-                {
-                    ReloadSchemasJob.reloadSchema( browserConnection, monitor );
-                }
-                else if ( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
-                {
-                    // check if schema is up-to-date
-                    SearchParameter sp = new SearchParameter();
-                    sp.setSearchBase( new LdapDN( rootDSE.getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
-                        .getStringValue() ) );
-                    sp.setFilter( Schema.SCHEMA_FILTER );
-                    sp.setScope( SearchScope.OBJECT );
-                    sp.setReturningAttributes( new String[]
-                        { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
-                            IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
-                    ISearch search = new Search( browserConnection, sp );
-
-                    SearchJob.searchAndUpdateModel( browserConnection, search, monitor );
-                    ISearchResult[] results = search.getSearchResults();
-
-                    if ( results != null && results.length == 1 )
-                    {
-                        String schemaTimestamp = results[0]
-                            .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) != null ? results[0]
-                            .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ).getStringValue() : null;
-                        if ( schemaTimestamp == null )
-                        {
-                            schemaTimestamp = results[0]
-                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) != null ? results[0]
-                                .getAttribute( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ).getStringValue()
-                                : null;
-                        }
-                        String cacheTimestamp = schema.getModifyTimestamp() != null ? schema.getModifyTimestamp()
-                            : schema.getCreateTimestamp();
-                        if ( cacheTimestamp == null
-                            || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp
-                                .compareTo( cacheTimestamp ) > 0 ) )
-                        {
-                            ReloadSchemasJob.reloadSchema( browserConnection, monitor );
-                        }
-                    }
-                    else
-                    {
-                        browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
-                        monitor.reportError( BrowserCoreMessages.model__no_schema_information );
-                    }
-                }
-                else
-                {
-                    browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
-                    monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
-                }
-            }
-            catch ( Exception e )
-            {
-                browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
-                monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
-                e.printStackTrace();
-            }
-        }
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java?rev=663698&r1=663697&r2=663698&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ReloadSchemasJob.java Thu Jun  5 11:58:13 2008
@@ -21,6 +21,10 @@
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
 
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.SearchResult;
+
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
@@ -94,14 +98,9 @@
             { browserConnection.getConnection().getName() } ) );
         monitor.worked( 1 );
 
-        // load root DSE
-        monitor.reportProgress( BrowserCoreMessages.model__loading_rootdse );
-        InitializeAttributesJob.initializeAttributes( browserConnection.getRootDSE(), true, monitor );
-        monitor.worked( 1 );
-        
         // load schema
         monitor.reportProgress( BrowserCoreMessages.model__loading_schema );
-        reloadSchema( browserConnection, monitor );
+        reloadSchema( true, browserConnection, monitor );
         monitor.worked( 1 );
     }
 
@@ -124,25 +123,39 @@
     {
         return BrowserCoreMessages.jobs__reload_schemas_error_1;
     }
-    
+
 
     /**
      * Reloads the schema.
      * 
+     * @param forceReload true to force the reload of the schema, otherwise it would only be reloaded
+     *                    if the server-side schema is newer than the cached schema.
      * @param browserConnection the browser connection
      * @param monitor the progress monitor
      */
-    public static void reloadSchema( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+    public static void reloadSchema( boolean forceReload, IBrowserConnection browserConnection,
+        StudioProgressMonitor monitor )
     {
-        browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+        LdapDN schemaLocation = getSchemaLocation( browserConnection, monitor );
+        if ( schemaLocation == null )
+        {
+            monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
+            return;
+        }
 
-        try
+        Schema schema = browserConnection.getSchema();
+
+        boolean mustReload = forceReload || ( schema == Schema.DEFAULT_SCHEMA )
+            || mustReload( schemaLocation, browserConnection, monitor );
+
+        if ( mustReload )
         {
-            if ( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) != null )
+            browserConnection.setSchema( Schema.DEFAULT_SCHEMA );
+
+            try
             {
                 SearchParameter sp = new SearchParameter();
-                sp.setSearchBase( new LdapDN( browserConnection.getRootDSE().getAttribute( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY )
-                    .getStringValue() ) );
+                sp.setSearchBase( schemaLocation );
                 sp.setFilter( Schema.SCHEMA_FILTER );
                 sp.setScope( SearchScope.OBJECT );
                 sp.setReturningAttributes( new String[]
@@ -150,26 +163,80 @@
                         Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES, Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES,
                         Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE, IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
                         IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP, } );
-                
+
                 LdifEnumeration le = ExportLdifJob.search( browserConnection, sp, monitor );
                 if ( le.hasNext() )
                 {
                     LdifContentRecord schemaRecord = ( LdifContentRecord ) le.next();
-                    Schema schema = new Schema();
+                    schema = new Schema();
                     schema.loadFromRecord( schemaRecord );
                     browserConnection.setSchema( schema );
-                    // TODO: Schema update event
-//                    EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( this,
-//                        ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this );
                 }
                 else
                 {
                     monitor.reportError( BrowserCoreMessages.model__no_schema_information );
                 }
             }
-            else
+            catch ( Exception e )
             {
-                monitor.reportError( BrowserCoreMessages.model__missing_schema_location );
+                monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    /**
+     * Checks if the schema must be reloaded
+     * 
+     * @param browserConnection the browser connection
+     * @param monitor the progress monitor
+     */
+    private static boolean mustReload( LdapDN schemaLocation, IBrowserConnection browserConnection,
+        StudioProgressMonitor monitor )
+    {
+        Schema schema = browserConnection.getSchema();
+
+        try
+        {
+            SearchParameter sp = new SearchParameter();
+            sp.setSearchBase( schemaLocation );
+            sp.setFilter( Schema.SCHEMA_FILTER );
+            sp.setScope( SearchScope.OBJECT );
+            sp
+                .setReturningAttributes( new String[]
+                    { IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP,
+                        IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP } );
+            NamingEnumeration<SearchResult> enumeration = SearchJob.search( browserConnection, sp, monitor );
+            while ( enumeration != null && enumeration.hasMore() )
+            {
+                String createTimestamp = null;
+                String modifyTimestamp = null;
+
+                SearchResult sr = enumeration.next();
+                NamingEnumeration<? extends Attribute> attributes = sr.getAttributes().getAll();
+                while ( attributes.hasMore() )
+                {
+                    Attribute attribute = attributes.next();
+                    if ( attribute.getID().equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) )
+                    {
+                        modifyTimestamp = ( String ) attribute.get();
+                    }
+                    if ( attribute.getID().equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) )
+                    {
+                        createTimestamp = ( String ) attribute.get();
+                    }
+                }
+
+                String schemaTimestamp = modifyTimestamp != null ? modifyTimestamp : createTimestamp;
+                String cacheTimestamp = schema.getModifyTimestamp() != null ? schema.getModifyTimestamp() : schema
+                    .getCreateTimestamp();
+                if ( cacheTimestamp == null
+                    || ( cacheTimestamp != null && schemaTimestamp != null && schemaTimestamp
+                        .compareTo( cacheTimestamp ) > 0 ) )
+                {
+                    return true;
+                }
             }
         }
         catch ( Exception e )
@@ -177,5 +244,47 @@
             monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
             e.printStackTrace();
         }
+
+        return false;
+    }
+
+
+    private static LdapDN getSchemaLocation( IBrowserConnection browserConnection, StudioProgressMonitor monitor )
+    {
+        try
+        {
+            SearchParameter sp = new SearchParameter();
+            sp.setSearchBase( new LdapDN() );
+            sp.setScope( SearchScope.OBJECT );
+            sp.setReturningAttributes( new String[]
+                { IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY } );
+            NamingEnumeration<SearchResult> enumeration = SearchJob.search( browserConnection, sp, monitor );
+            while ( enumeration != null && enumeration.hasMore() )
+            {
+                SearchResult sr = enumeration.next();
+                NamingEnumeration<? extends Attribute> attributes = sr.getAttributes().getAll();
+                while ( attributes.hasMore() )
+                {
+                    Attribute attribute = attributes.next();
+                    if ( attribute.getID().equalsIgnoreCase( IRootDSE.ROOTDSE_ATTRIBUTE_SUBSCHEMASUBENTRY ) )
+                    {
+                        String value = ( String ) attribute.get();
+                        if ( LdapDN.isValid( value ) )
+                        {
+                            LdapDN dn = new LdapDN( value );
+                            return dn;
+                        }
+                    }
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            monitor.reportError( BrowserCoreMessages.model__error_loading_schema, e );
+            return null;
+        }
+
+        return null;
     }
+
 }

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java?rev=663698&r1=663697&r2=663698&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java (original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java Thu Jun  5 11:58:13 2008
@@ -142,7 +142,6 @@
         entryToChildrenInfoMap.clear();
         entryToChildrenFilterMap.clear();
 
-        schema = Schema.DEFAULT_SCHEMA;
         rootDSE = new RootDSE( this );
         cacheEntry( rootDSE );
 

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java?rev=663698&r1=663697&r2=663698&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java (original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/dialogs/properties/SchemaPropertyPage.java Thu Jun  5 11:58:13 2008
@@ -33,8 +33,8 @@
 import org.apache.directory.studio.ldapbrowser.core.model.schema.Schema;
 import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
@@ -45,24 +45,41 @@
 import org.eclipse.ui.dialogs.PropertyPage;
 
 
+/**
+ * Property page to shows some meta information of the schema an the 
+ * schema cache. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SchemaPropertyPage extends PropertyPage implements IWorkbenchPropertyPage
 {
 
+    /** Text field containing the DN of the schema entry. */
     private Text dnText;
 
+    /** Text field containing the create timestamp of the schema entry. */
     private Text ctText;
 
+    /** Text field containing the modify timestamp of the schema entry. */
     private Text mtText;
 
+    /** Button to reload the scheam. */
     private Button reloadSchemaButton;
 
+    /** Text field containing the path to the schema cache file. */
     private Text cachePathText;
 
+    /** Text field containing last modify date of the schema cache file. */
     private Text cacheDateText;
 
+    /** Text field containing the size of the schema cache file. */
     private Text cacheSizeText;
 
 
+    /**
+     * Instantiates a new schema property page.
+     */
     public SchemaPropertyPage()
     {
         super();
@@ -70,9 +87,11 @@
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     protected Control createContents( Composite parent )
     {
-
         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
 
         Group infoGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
@@ -93,17 +112,12 @@
         GridData gd = new GridData();
         gd.verticalAlignment = SWT.BOTTOM;
         reloadSchemaButton.setLayoutData( gd );
-        reloadSchemaButton.addSelectionListener( new SelectionListener()
+        reloadSchemaButton.addSelectionListener( new SelectionAdapter()
         {
             public void widgetSelected( SelectionEvent e )
             {
                 reloadSchema();
             }
-
-
-            public void widgetDefaultSelected( SelectionEvent e )
-            {
-            }
         } );
 
         BaseWidgetUtils.createSpacer( composite, 1 );
@@ -123,25 +137,32 @@
         cacheSizeText = BaseWidgetUtils.createWrappedLabeledText( cacheComposite, "", 1 );
 
         IBrowserConnection connection = RootDSEPropertyPage.getConnection( getElement() );
-        this.connectionUpdated( connection );
+        update( connection );
 
         return composite;
     }
 
 
+    /**
+     * Reloads schema.
+     */
     private void reloadSchema()
     {
         final IBrowserConnection browserConnection = RootDSEPropertyPage.getConnection( getElement() );
         ReloadSchemasJob job = new ReloadSchemasJob( browserConnection );
         RunnableContextJobAdapter.execute( job );
-        this.connectionUpdated( browserConnection );
+        update( browserConnection );
     }
 
 
-    private void connectionUpdated( IBrowserConnection connection )
+    /**
+     * Updates the text fields.
+     * 
+     * @param connection the connection
+     */
+    private void update( IBrowserConnection connection )
     {
-
-        if ( !this.dnText.isDisposed() )
+        if ( !dnText.isDisposed() )
         {
             Schema schema = null;
             if ( connection != null )
@@ -209,9 +230,14 @@
     }
 
 
+    /**
+     * Checks if is disposed.
+     * 
+     * @return true, if is disposed
+     */
     public boolean isDisposed()
     {
-        return this.dnText.isDisposed();
+        return dnText.isDisposed();
     }
 
 }