directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r686742 - in /directory/studio/trunk/connection-core: plugin.xml src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java src/main/resources/connectionInitializer.exsd
Date Mon, 18 Aug 2008 12:46:46 GMT
Author: seelmann
Date: Mon Aug 18 05:46:45 2008
New Revision: 686742

URL: http://svn.apache.org/viewvc?rev=686742&view=rev
Log:
Fix for DIRSTUDIO-358: Applied patch from Prakash G.R.. It adds an extension point to the
connection plugin that makes it possible to define initial connections for Studio.

Added:
    directory/studio/trunk/connection-core/src/main/resources/connectionInitializer.exsd
Modified:
    directory/studio/trunk/connection-core/plugin.xml
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java

Modified: directory/studio/trunk/connection-core/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/plugin.xml?rev=686742&r1=686741&r2=686742&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/plugin.xml (original)
+++ directory/studio/trunk/connection-core/plugin.xml Mon Aug 18 05:46:45 2008
@@ -21,6 +21,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 id="org.apache.directory.studio.connectionInitializer" name="Connection
Initializer" schema="src/main/resources/connectionInitializer.exsd"/>
    <extension
          point="org.apache.directory.studio.jndilogger">
       <jndiLogger

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java?rev=686742&r1=686741&r2=686742&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
Mon Aug 18 05:46:45 2008
@@ -34,7 +34,13 @@
 import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
 import org.apache.directory.studio.connection.core.io.ConnectionIO;
 import org.apache.directory.studio.connection.core.io.ConnectionIOException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
 
 
 /**
@@ -56,12 +62,62 @@
     public ConnectionManager()
     {
         this.connectionList = new HashSet<Connection>();
+        loadInitializers();
         loadConnections();
         ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner()
);
     }
 
 
     /**
+     * Loads the Connection Initializers. This happens only for the first time, 
+     * which is determined by whether or not the connectionStore file is present.
+     */
+    private void loadInitializers()
+    {
+        File connectionStore = new File( getConnectionStoreFileName() );
+        if ( connectionStore.exists() )
+        {
+            return; // connections are stored from a previous sessions - don't call initializers
+        }
+
+        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
+            "org.apache.directory.studio.connectionInitializer" );
+
+        IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
+        for ( IConfigurationElement configurationElement : configurationElements )
+        {
+            if ( "connection".equals( configurationElement.getName() ) )
+            {
+                addInitialConnection( configurationElement );
+            }
+        }
+    }
+
+
+    /**
+     * Creates the ConnectionParameter from the configElement and creates the connection.
+     * 
+     * @param configurationElement The configuration element
+     */
+    private void addInitialConnection( IConfigurationElement configurationElement )
+    {
+        try
+        {
+            ConnectionParameter connectionParameter = ( ConnectionParameter ) configurationElement
+                .createExecutableExtension( "class" );
+            Connection conn = new Connection( connectionParameter );
+            connectionList.add( conn );
+        }
+        catch ( CoreException e )
+        {
+            Status status = new Status( IStatus.ERROR, ConnectionCorePlugin.PLUGIN_ID,
+                "Exception occured while executing connection initializer: " + e.getMessage(),
e );
+            ConnectionCorePlugin.getDefault().getLog().log( status );
+        }
+    }
+
+
+    /**
      * Gets the Modification Log filename for the corresponding connection.
      *
      * @param connection
@@ -98,8 +154,7 @@
         {
             file.mkdir();
         }
-        return p
-            .append( "search-" + Utils.getFilenameString( connection.getId() ) + "-%u-%g.ldiflog"
).toOSString(); //$NON-NLS-1$ //$NON-NLS-2$
+        return p.append( "search-" + Utils.getFilenameString( connection.getId() ) + "-%u-%g.ldiflog"
).toOSString(); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
 
@@ -151,7 +206,7 @@
      */
     public Connection getConnectionById( String id )
     {
-        for ( Connection conn:connectionList )
+        for ( Connection conn : connectionList )
         {
             if ( conn.getConnectionParameter().getId().equals( id ) )
             {
@@ -172,7 +227,7 @@
      */
     public Connection getConnectionByName( String name )
     {
-        for ( Connection conn:connectionList )
+        for ( Connection conn : connectionList )
         {
             if ( conn.getConnectionParameter().getName().equals( name ) )
             {

Added: directory/studio/trunk/connection-core/src/main/resources/connectionInitializer.exsd
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/resources/connectionInitializer.exsd?rev=686742&view=auto
==============================================================================
--- directory/studio/trunk/connection-core/src/main/resources/connectionInitializer.exsd (added)
+++ directory/studio/trunk/connection-core/src/main/resources/connectionInitializer.exsd Mon
Aug 18 05:46:45 2008
@@ -0,0 +1,132 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.apache.directory.studio.connection.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.apache.directory.studio.connection.core" id="connectionInitializer"
name="Connection Initializer"/>
+      </appinfo>
+      <documentation>
+         A Connection Initializer that creates the default connections in the Connections
View.
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="connection" minOccurs="0" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="connection">
+      <complexType>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn="org.apache.directory.studio.connection.core.ConnectionParameter:"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         1.5.0
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </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>



Mime
View raw message