directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r615067 - in /directory/studio/trunk: studio-connection-core/ studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/ studio...
Date Thu, 24 Jan 2008 22:33:42 GMT
Author: seelmann
Date: Thu Jan 24 14:33:40 2008
New Revision: 615067

URL: http://svn.apache.org/viewvc?rev=615067&view=rev
Log:
Fix for DIRSTUDIO-267: Fixed the way of opening a connection. The creation of the JNDI connection
in the connection-core plugin and 
retrieval of RootDSE and schema information in the ldapbrowser-core plugin happened in separate
threads (Jobs). That caused race conditions 
when opening a connection. Now an IConnectionListener interface and a connectionListener extension
point was created, it could be used to 
hook into the "open connection" procedure.

Added:
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java
  (with props)
    directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd
  (with props)
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
  (with props)
Removed:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/OpenBrowserConnectionsJob.java
Modified:
    directory/studio/trunk/studio-connection-core/plugin.xml
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CloseConnectionsJob.java
    directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/OpenConnectionsJob.java
    directory/studio/trunk/studio-ldapbrowser-core/plugin.xml
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/AbstractEclipseJob.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java

Modified: directory/studio/trunk/studio-connection-core/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/plugin.xml?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/plugin.xml (original)
+++ directory/studio/trunk/studio-connection-core/plugin.xml Thu Jan 24 14:33:40 2008
@@ -20,6 +20,7 @@
 -->
 <plugin>
    <extension-point id="org.apache.directory.studio.jndilogger" name="JNDI Logger" schema="src/main/resources/jndiLogger.exsd"/>
+   <extension-point id="org.apache.directory.studio.connectionlistener" name="Connection
Listener" schema="src/main/resources/connectionListener.exsd"/>
    <extension
          point="org.apache.directory.studio.jndilogger">
       <jndiLogger

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
Thu Jan 24 14:33:40 2008
@@ -65,6 +65,9 @@
 
     /** The JNDI loggers. */
     private List<IJndiLogger> jndiLoggers;
+    
+    /** The connection listeners. */
+    private List<IConnectionListener> connectionListeners;
 
     /**
      * The constructor
@@ -276,6 +279,44 @@
         }
         
         return jndiLoggers;
+    }
+    
+    
+    /**
+     * Gets the connection listeners.
+     * 
+     * @return the connection listners
+     */
+    public List<IConnectionListener> getConnectionListners()
+    {
+        if(connectionListeners == null)
+        {
+            connectionListeners = new ArrayList<IConnectionListener>();
+            
+            IExtensionRegistry registry = Platform.getExtensionRegistry();
+            IExtensionPoint extensionPoint = registry
+                .getExtensionPoint( "org.apache.directory.studio.connectionlistener" );
+            IConfigurationElement[] members = extensionPoint.getConfigurationElements();
+            for ( IConfigurationElement member : members )
+            {
+                try
+                {
+                    IConnectionListener listener = ( IConnectionListener ) member.createExecutableExtension(
"class" );
+//                    listener.setId( member.getAttribute( "id" ) );
+//                    listener.setName( member.getAttribute( "name" ) );
+//                    listener.setDescription( member.getAttribute( "description" ) );
+                    connectionListeners.add( listener );
+                }
+                catch ( Exception e )
+                {
+                    getLog().log(
+                        new Status( IStatus.ERROR, ConnectionCorePlugin.PLUGIN_ID, 1,
+                            "Unable to create connection listener " + member.getAttribute(
"class" ), e ) );
+                }
+            }
+        }
+        
+        return connectionListeners;
     }
 
 }

Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java?rev=615067&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java
(added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java
Thu Jan 24 14:33:40 2008
@@ -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.studio.connection.core;
+
+
+/**
+ * A Connection Listener is informed when a connection is opened or closed. 
+ * To register for those events the implementing plug-in must also implement
+ * the org.apache.directory.studio.connection.core.connectionListener 
+ * extension point.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface IConnectionListener
+{
+
+    /**
+     * Called when an {@link Connection} was opened.
+     *
+     * @param connection the opened connection 
+     * @param monitor the progress monitor
+     */
+    public void connectionOpened( Connection connection, StudioProgressMonitor monitor );
+
+
+    /**
+     * Called when an {@link Connection} was closed.
+     *
+     * @param connection the closed connection 
+     * @param monitor the progress monitor
+     */
+    public void connectionClosed( Connection connection, StudioProgressMonitor monitor );

+}

Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/IConnectionListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
Thu Jan 24 14:33:40 2008
@@ -54,6 +54,7 @@
 import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
 import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.IAuthHandler;
+import org.apache.directory.studio.connection.core.IConnectionListener;
 import org.apache.directory.studio.connection.core.ICredentials;
 import org.apache.directory.studio.connection.core.IJndiLogger;
 import org.apache.directory.studio.connection.core.IReferralHandler;
@@ -1156,6 +1157,10 @@
             {
                 referralConnection.getJNDIConnectionWrapper().connect( monitor );
                 referralConnection.getJNDIConnectionWrapper().bind( monitor );
+                for ( IConnectionListener listener : ConnectionCorePlugin.getDefault().getConnectionListners()
)
+                {
+                    listener.connectionOpened( referralConnection, monitor );
+                }
                 ConnectionEventRegistry.fireConnectionOpened( referralConnection, source
);
             }
         }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CloseConnectionsJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CloseConnectionsJob.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CloseConnectionsJob.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/CloseConnectionsJob.java
Thu Jan 24 14:33:40 2008
@@ -22,8 +22,10 @@
 
 
 import org.apache.directory.studio.connection.core.Connection;
-import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.IConnectionListener;
 import org.apache.directory.studio.connection.core.Messages;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 
 
@@ -92,16 +94,27 @@
         monitor.beginTask( " ", connections.length * 6 + 1 ); //$NON-NLS-1$
         monitor.reportProgress( " " ); //$NON-NLS-1$
 
-        for ( int i = 0; i < connections.length; i++ )
+        for ( Connection connection : connections )
         {
-            if ( connections[i].getJNDIConnectionWrapper().isConnected() )
+            if ( connection.getJNDIConnectionWrapper().isConnected() )
             {
                 monitor.setTaskName( Messages.bind( Messages.jobs__close_connections_task,
new String[]
-                    { this.connections[i].getName() } ) );
+                    { connection.getName() } ) );
                 monitor.worked( 1 );
 
-                connections[i].getJNDIConnectionWrapper().unbind();
-                connections[i].getJNDIConnectionWrapper().disconnect();
+                connection.getJNDIConnectionWrapper().unbind();
+                connection.getJNDIConnectionWrapper().disconnect();
+            }
+        }
+
+        for ( Connection connection : connections )
+        {
+            if ( !connection.getJNDIConnectionWrapper().isConnected() )
+            {
+                for ( IConnectionListener listener : ConnectionCorePlugin.getDefault().getConnectionListners()
)
+                {
+                    listener.connectionClosed( connection, monitor );
+                }
             }
         }
     }
@@ -112,11 +125,11 @@
      */
     protected void runNotification()
     {
-        for ( int i = 0; i < connections.length; i++ )
+        for ( Connection connection : connections )
         {
-            if ( !connections[i].getJNDIConnectionWrapper().isConnected() )
+            if ( !connection.getJNDIConnectionWrapper().isConnected() )
             {
-                ConnectionEventRegistry.fireConnectionClosed( connections[i], this );
+                ConnectionEventRegistry.fireConnectionClosed( connection, this );
             }
         }
     }

Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/OpenConnectionsJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/OpenConnectionsJob.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/OpenConnectionsJob.java
(original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/OpenConnectionsJob.java
Thu Jan 24 14:33:40 2008
@@ -22,8 +22,10 @@
 
 
 import org.apache.directory.studio.connection.core.Connection;
-import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.IConnectionListener;
 import org.apache.directory.studio.connection.core.Messages;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
 
 
@@ -88,20 +90,30 @@
      */
     protected void executeBulkJob( StudioProgressMonitor monitor )
     {
-
         monitor.beginTask( " ", connections.length * 6 + 1 ); //$NON-NLS-1$
         monitor.reportProgress( " " ); //$NON-NLS-1$
 
-        for ( int i = 0; i < connections.length; i++ )
+        for ( Connection connection : connections )
         {
-            if ( !connections[i].getJNDIConnectionWrapper().isConnected() )
+            if ( !connection.getJNDIConnectionWrapper().isConnected() )
             {
                 monitor.setTaskName( Messages.bind( Messages.jobs__open_connections_task,
new String[]
-                    { connections[i].getName() } ) );
+                    { connection.getName() } ) );
                 monitor.worked( 1 );
 
-                connections[i].getJNDIConnectionWrapper().connect( monitor );
-                connections[i].getJNDIConnectionWrapper().bind( monitor );
+                connection.getJNDIConnectionWrapper().connect( monitor );
+                connection.getJNDIConnectionWrapper().bind( monitor );
+            }
+        }
+
+        for ( Connection connection : connections )
+        {
+            if ( connection.getJNDIConnectionWrapper().isConnected() )
+            {
+                for ( IConnectionListener listener : ConnectionCorePlugin.getDefault().getConnectionListners()
)
+                {
+                    listener.connectionOpened( connection, monitor );
+                }
             }
         }
     }
@@ -112,11 +124,11 @@
      */
     protected void runNotification()
     {
-        for ( int i = 0; i < connections.length; i++ )
+        for ( Connection connection : connections )
         {
-            if ( connections[i].getJNDIConnectionWrapper().isConnected() )
+            if ( connection.getJNDIConnectionWrapper().isConnected() )
             {
-                ConnectionEventRegistry.fireConnectionOpened( connections[i], this );
+                ConnectionEventRegistry.fireConnectionOpened( connection, this );
             }
         }
     }

Added: directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd?rev=615067&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd
(added)
+++ directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd
Thu Jan 24 14:33:40 2008
@@ -0,0 +1,160 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.apache.directory.studio.connection.core">
+<annotation>
+      <appInfo>
+         <meta.schema plugin="org.apache.directory.studio.connection.core" id="connectionListener"
name="Connection Listener"/>
+      </appInfo>
+      <documentation>
+         A Connection Listener is informed about opening and closing connections.
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="connectionListener"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The extension-point of this extension.
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  Extension identifier.
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  Name of this extension.
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="connectionListener">
+      <annotation>
+         <appInfo>
+            <meta.element labelAttribute="name" icon="icon"/>
+         </appInfo>
+      </annotation>
+      <complexType>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute translatable="true"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+         <attribute name="description" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute translatable="true"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The specific class implementing the function.
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java" basedOn=":org.apache.directory.studio.connection.core.IConnectionListener"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="since"/>
+      </appInfo>
+      <documentation>
+         1.1.0
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="examples"/>
+      </appInfo>
+      <documentation>
+         &lt;p&gt;
+&lt;pre&gt;
+   &lt;extension
+       point=&quot;org.apache.directory.studio.connectionListener&quot;&gt;
+
+    &lt;valueEditor
+          name=&quot;Browser Listener&quot;
+          class=&quot;org.apache.directory.studio.ldapbrowser.core.BrowserListener&quot;
+          /&gt;
+   &lt;/extension&gt;         
+&lt;/pre&gt;
+&lt;p&gt;
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="apiInfo"/>
+      </appInfo>
+      <documentation>
+         
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="implementation"/>
+      </appInfo>
+      <documentation>
+         
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="copyright"/>
+      </appInfo>
+      <documentation>
+         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
+  &quot;License&quot;); 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
+  &quot;AS IS&quot; 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.
+      </documentation>
+   </annotation>
+
+</schema>

Propchange: directory/studio/trunk/studio-connection-core/src/main/resources/connectionListener.exsd
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/studio/trunk/studio-ldapbrowser-core/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/plugin.xml?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/plugin.xml (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/plugin.xml Thu Jan 24 14:33:40 2008
@@ -23,5 +23,14 @@
          point="org.eclipse.core.runtime.preferences">
       <initializer class="org.apache.directory.studio.ldapbrowser.core.BrowserCorePreferencesInitializer"/>
    </extension>
+   <extension
+         point="org.apache.directory.studio.connectionlistener">
+      <connectionListener
+            class="org.apache.directory.studio.ldapbrowser.core.BrowserConnectionListener"
+            description="Opens/closes browser connection when the underlying connection is
opened/closed"
+            id="org.apache.directory.studio.ldapbrowser.core.model.impl.BrowserConnection"
+            name="Browser Connection Listener">
+      </connectionListener>
+   </extension>
 
 </plugin>

Added: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java?rev=615067&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
(added)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
Thu Jan 24 14:33:40 2008
@@ -0,0 +1,188 @@
+/*
+ *  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;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.IConnectionListener;
+import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.ldapbrowser.core.events.BrowserConnectionUpdateEvent;
+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;
+
+
+/**
+ * The {@link BrowserConnectionListener} opens and closes the 
+ * {@link IBrowserConnection} if the underlying {@link Connection}
+ * is opened and closed.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserConnectionListener implements IConnectionListener
+{
+
+    /**
+     * This implementation opens the browser connection when the connection was opened.
+     */
+    public void connectionOpened( Connection connection, StudioProgressMonitor monitor )
+    {
+        IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
+            .getBrowserConnection( connection );
+        if ( browserConnection != null )
+        {
+            try
+            {
+                EventRegistry.suspendEventFireingInCurrentThread();
+                openBrowserConnection( browserConnection, monitor );
+            }
+            finally
+            {
+                EventRegistry.resumeEventFireingInCurrentThread();
+                BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
+                    browserConnection, BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_OPENED
);
+                EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent,
this );
+            }
+        }
+    }
+
+
+    /**
+     * This implementation closes the browser connection when the connection was closed.
+     */
+    public void connectionClosed( Connection connection, StudioProgressMonitor monitor )
+    {
+        IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager()
+            .getBrowserConnection( connection );
+        if ( browserConnection != null )
+        {
+            try
+            {
+                EventRegistry.suspendEventFireingInCurrentThread();
+                browserConnection.clearCaches();
+            }
+            finally
+            {
+                EventRegistry.resumeEventFireingInCurrentThread();
+                BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
+                    browserConnection, BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_CLOSED
);
+                EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent,
this );
+            }
+        }
+    }
+
+
+    /**
+     * Opens the browser connection.
+     * 
+     * @param browserConnection the browser connection
+     * @param monitor the progress monitor
+     */
+    private static void openBrowserConnection( IBrowserConnection browserConnection, StudioProgressMonitor
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();
+                return;
+            }
+        }
+    }
+
+}

Propchange: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/AbstractEclipseJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/AbstractEclipseJob.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/AbstractEclipseJob.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/AbstractEclipseJob.java
Thu Jan 24 14:33:40 2008
@@ -22,6 +22,8 @@
 
 
 import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.IConnectionListener;
 import org.apache.directory.studio.connection.core.Messages;
 import org.apache.directory.studio.connection.core.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
@@ -73,17 +75,21 @@
 
         // ensure that connections are opened
         Connection[] connections = getConnections();
-        for ( int i = 0; i < connections.length; i++ )
+        for ( Connection connection : connections )
         {
-            if ( connections[i] != null && !connections[i].getJNDIConnectionWrapper().isConnected()
)
+            if ( connection != null && !connection.getJNDIConnectionWrapper().isConnected()
)
             {
                 monitor.setTaskName( Messages.bind( Messages.jobs__open_connections_task,
new String[]
-                    { connections[i].getName() } ) );
+                    { connection.getName() } ) );
                 monitor.worked( 1 );
 
-                connections[i].getJNDIConnectionWrapper().connect( monitor );
-                connections[i].getJNDIConnectionWrapper().bind( monitor );
-                ConnectionEventRegistry.fireConnectionOpened( connections[i], this );
+                connection.getJNDIConnectionWrapper().connect( monitor );
+                connection.getJNDIConnectionWrapper().bind( monitor );
+                for ( IConnectionListener listener : ConnectionCorePlugin.getDefault().getConnectionListners()
)
+                {
+                    listener.connectionOpened( connection, monitor );
+                }
+                ConnectionEventRegistry.fireConnectionOpened( connection, this );
             }
         }
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/IBrowserConnection.java
Thu Jan 24 14:33:40 2008
@@ -248,4 +248,11 @@
      * @param entry the entry to remove from cache
      */
     public abstract void uncacheEntryRecursive( IEntry entry );
+
+
+    /**
+     * Clears all caches.
+     */
+    public abstract void clearCaches();
+    
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/BrowserConnection.java
Thu Jan 24 14:33:40 2008
@@ -29,16 +29,11 @@
 
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.studio.connection.core.Connection;
-import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
-import org.apache.directory.studio.connection.core.ConnectionFolder;
 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.event.ConnectionEventRegistry;
-import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
 import org.apache.directory.studio.ldapbrowser.core.BookmarkManager;
 import org.apache.directory.studio.ldapbrowser.core.SearchManager;
-import org.apache.directory.studio.ldapbrowser.core.events.BrowserConnectionUpdateEvent;
-import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.internal.search.LdapSearchPageScoreComputer;
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
@@ -55,7 +50,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class BrowserConnection implements ConnectionUpdateListener, IBrowserConnection, Serializable
+public class BrowserConnection implements IBrowserConnection, Serializable
 {
 
     private static final long serialVersionUID = 2987596234755856270L;
@@ -120,8 +115,6 @@
         this.schema = Schema.DEFAULT_SCHEMA;
         this.rootDSE = new RootDSE( this );
         cacheEntry( this.rootDSE );
-
-        ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner()
);
     }
 
 
@@ -135,9 +128,9 @@
 
 
     /**
-     * CClears all caches.
+     * {@inheritDoc}
      */
-    private void clearCaches()
+    public void clearCaches()
     {
         for ( int i = 0; i < getSearchManager().getSearchCount(); i++ )
         {
@@ -528,65 +521,4 @@
         return connection;
     }
 
-
-    /**
-     * This implementation does nothing.
-     */
-    public void connectionAdded( Connection connection )
-    {
-    }
-
-
-    /**
-     * This implementation does nothing.
-     */
-    public void connectionRemoved( Connection connection )
-    {
-    }
-
-
-    /**
-     * This implementation does nothing.
-     */
-    public void connectionUpdated( Connection connection )
-    {
-    }
-
-
-    /**
-     * This implementation opens the browser connection when the connection was opened.
-     */
-    public void connectionOpened( Connection connection )
-    {
-        if ( this.connection == connection )
-        {
-            new OpenBrowserConnectionsJob( this ).execute();
-            BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
this,
-                BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_OPENED );
-            EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this
);
-        }
-    }
-
-
-    /**
-     * This implementation closes the browser connection when the connection was closed.
-     */
-    public void connectionClosed( Connection connection )
-    {
-        if ( this.connection == connection )
-        {
-            clearCaches();
-            BrowserConnectionUpdateEvent browserConnectionUpdateEvent = new BrowserConnectionUpdateEvent(
this,
-                BrowserConnectionUpdateEvent.Detail.BROWSER_CONNECTION_CLOSED );
-            EventRegistry.fireBrowserConnectionUpdated( browserConnectionUpdateEvent, this
);
-        }
-    }
-
-
-    /**
-     * This implementation does nothing.
-     */
-    public void connectionFolderModified( ConnectionFolder connectionFolder )
-    {
-    }
 }

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DelegateEntry.java
Thu Jan 24 14:33:40 2008
@@ -101,12 +101,17 @@
      */
     protected IEntry getDelegate()
     {
+        // always get the fresh entry from cache
+        IBrowserConnection conn = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnectionById(
connectionId );
+        delegate = conn.getEntryFromCache( dn );
+        
         if ( delegate != null
             && !delegate.getBrowserConnection().getConnection().getJNDIConnectionWrapper().isConnected()
)
         {
             entryDoesNotExist = false;
             delegate = null;
         }
+        
         return delegate;
     }
 

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java?rev=615067&r1=615066&r2=615067&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/impl/DummyConnection.java
Thu Jan 24 14:33:40 2008
@@ -266,4 +266,13 @@
     public void uncacheEntryRecursive( IEntry entry )
     {
     }
+
+
+    /** 
+     * {@inheritDoc}
+     */
+    public void clearCaches()
+    {
+    }
+
 }



Mime
View raw message