directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r193071 - in /directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server: jndi/ partition/ partition/impl/btree/gui/
Date Thu, 23 Jun 2005 04:39:23 GMT
Author: trustin
Date: Wed Jun 22 21:39:22 2005
New Revision: 193071

URL: http://svn.apache.org/viewcvs?rev=193071&view=rev
Log:
* Changed ContextPartition.getSuffix(boolean) to throw NamingException like other methods.
* Added AbstractContextPartition to help users implement their own partitions.

Added:
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java
  (with props)
Modified:
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextPartitionNexusProxy.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
    directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/impl/btree/gui/MainFrame.java

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextPartitionNexusProxy.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextPartitionNexusProxy.java?rev=193071&r1=193070&r2=193071&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextPartitionNexusProxy.java
(original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextPartitionNexusProxy.java
Wed Jun 22 21:39:22 2005
@@ -50,12 +50,12 @@
         return this.provider.getPartitionNexus().getLdapContext();
     }
 
-    public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration
cfg ) throws NamingException
+    public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration
cfg )
     {
         throw new IllegalStateException();
     }
 
-    public void destroy() throws NamingException
+    public void destroy()
     {
         throw new IllegalStateException();
     }
@@ -65,7 +65,7 @@
         return this.provider.getPartitionNexus().getSystemPartition();
     }
 
-    public Name getSuffix( boolean normalized )
+    public Name getSuffix( boolean normalized ) throws NamingException
     {
         return this.provider.getPartitionNexus().getSuffix( normalized );
     }

Added: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java?rev=193071&view=auto
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java
(added)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java
Wed Jun 22 21:39:22 2005
@@ -0,0 +1,244 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.partition;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
+import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
+
+/**
+ * A {@link ContextPartition} that helps users to implement their own partition.
+ * Most methods are implemented by default.  Please look at the description of
+ * each methods for the detail of implementations.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractContextPartition implements ContextPartition
+{
+    /** {@link ContextFactoryConfiguration} specified at {@link #init(ContextFactoryConfiguration,
ContextPartitionConfiguration)}. */
+    private ContextFactoryConfiguration factoryCfg;
+    /** {@link ContextPartitionConfiguration} specified at {@link #init(ContextFactoryConfiguration,
ContextPartitionConfiguration)}. */
+    private ContextPartitionConfiguration cfg;
+    /** <tt>true</tt> if and only if this partition is initialized. */
+    private boolean initialized;
+    
+    protected AbstractContextPartition()
+    {
+    }
+
+    /**
+     * Sets up default properties(<tt>factoryConfiguration</tt> and <tt>configuration</tt>)
and
+     * calls {@link #doInit()} where you have to put your initialization code in.
+     * {@link #isInitialized()} will return <tt>true</tt> if {@link #doInit()}
returns
+     * without any errors.  {@link #destroy()} is called automatically as a clean-up process
+     * if {@link #doInit()} throws an exception.
+     */
+    public final void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration
cfg ) throws NamingException
+    {
+        if( initialized )
+        {
+            // Already initialized.
+            return;
+        }
+
+        this.factoryCfg = factoryCfg;
+        this.cfg = cfg;
+        try{
+            doInit();
+            initialized = true;
+        }
+        finally
+        {
+            if( !initialized )
+            {
+                destroy();
+            }
+        }
+    }
+
+    /**
+     * Override this method to put your initialization code.
+     */
+    protected void doInit() throws NamingException
+    {
+    }
+    
+    /**
+     * Calls {@link #doDestroy()} where you have to put your destroy code in,
+     * and clears default properties.  Once this method is invoked, {@link #isInitialized()}
+     * will return <tt>false</tt> even if {@link #doDestroy()} failed.
+     */
+    public final void destroy() throws NamingException
+    {
+        if( cfg == null )
+        {
+            // Already destroyed.
+            return;
+        }
+
+        try
+        {
+            doDestroy();
+        }
+        finally
+        {
+            initialized = false;
+            factoryCfg = null;
+            cfg = null;
+        }
+    }
+
+    /**
+     * Override this method to put your initialization code.
+     */
+    protected void doDestroy() throws NamingException
+    {
+    }
+
+    /**
+     * Returns <tt>true</tt> if this context partition is initialized successfully.
+     */
+    public final boolean isInitialized()
+    {
+        return initialized;
+    }
+
+    /**
+     * Returns {@link ContextFactoryConfiguration} that is provided from
+     * {@link #init(ContextFactoryConfiguration, ContextPartitionConfiguration)}.
+     */
+    public final ContextFactoryConfiguration getFactoryConfiguration()
+    {
+        return factoryCfg;
+    }
+    
+    /**
+     * Returns {@link ContextPartitionConfiguration} that is provided from
+     * {@link #init(ContextFactoryConfiguration, ContextPartitionConfiguration)}.
+     */
+    public final ContextPartitionConfiguration getConfiguration()
+    {
+        return cfg;
+    }
+
+    public final Name getSuffix( boolean normalized ) throws NamingException
+    {
+        if( normalized )
+        {
+            return getConfiguration().getNormalizedSuffix(
+                    getFactoryConfiguration().getGlobalRegistries().getMatchingRuleRegistry()
);
+        }
+        else
+        {
+            return new LdapName( getConfiguration().getSuffix() );
+        }
+    }
+
+    public final boolean isSuffix( Name name ) throws NamingException
+    {
+        return getSuffix( true ).equals( name ) || getSuffix( false ).equals( name );
+    }
+
+    /**
+     * This method does nothing by default.
+     */
+    public void sync() throws NamingException
+    {
+    }
+    
+    /**
+     * This method calls {@link #lookup(Name)} and return <tt>true</tt>
+     * if it returns an entry by default.  Please override this method if
+     * there is more effective way for your implementation.
+     */
+    public boolean hasEntry( Name name ) throws NamingException
+    {
+        try
+        {
+            return lookup( name ) != null;
+        }
+        catch( NameNotFoundException e )
+        {
+            return false;
+        }
+    }
+
+    /**
+     * This method calls {@link ContextPartition#lookup(Name, String[])}
+     * with null <tt>attributeIds</tt> by default.  Please override
+     * this method if there is more effective way for your implementation.
+     */
+    public Attributes lookup( Name name ) throws NamingException
+    {
+        return lookup( name, null );
+    }
+
+    /**
+     * This method forwards the request to
+     * {@link ContextPartition#modify(Name, ModificationItem[])} after
+     * translating parameters to {@link ModificationItem}<tt>[]</tt> by default.
+     * Please override this method if there is more effactive way for your
+     * implementation.
+     */
+    public void modify( Name name, int modOp, Attributes mods ) throws NamingException
+    {
+        List items = new ArrayList( mods.size() );
+        NamingEnumeration e = mods.getAll();
+        while( e.hasMore() )
+        {
+            items.add( new ModificationItem( modOp, ( Attribute ) e.next() ) );
+        }
+        
+        ModificationItem[] itemsArray = new ModificationItem[ items.size() ];
+        itemsArray = ( ModificationItem[] ) items.toArray( itemsArray );
+        modify( name, itemsArray );
+    }
+
+    /**
+     * This method calls {@link ContextPartition#modifyRn(Name, String, boolean)}
+     * and {@link ContextPartition#move(Name, Name)} subsequently by default.
+     * Please override this method if there is more effactive way for your
+     * implementation.
+     */
+    public void move( Name oldName, Name newParentName, String newRn, boolean deleteOldRn
) throws NamingException
+    {
+        modifyRn( oldName, newRn, deleteOldRn );
+        move( oldName, newParentName );
+    }
+
+    /**
+     * This method throws {@link OperationNotSupportedException} by default.
+     * Please override this method to implement move operation.
+     */
+    public void move( Name oldName, Name newParentName ) throws NamingException
+    {
+        throw new OperationNotSupportedException();
+    }
+}

Propchange: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/AbstractContextPartition.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java?rev=193071&r1=193070&r2=193071&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
(original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/ContextPartition.java
Wed Jun 22 21:39:22 2005
@@ -60,8 +60,6 @@
     /**
      * Closes or shuts down this ContextPartition.  Operations against closed
      * ContextPartitions will fail.
-     *
-     * @throws NamingException if there are problems shutting down
      */
     void destroy() throws NamingException;
 
@@ -88,7 +86,7 @@
      * @return Name representing the distinguished/absolute name of this
      * ContextPartitions root context.
      */
-    Name getSuffix( boolean normalized ) ;
+    Name getSuffix( boolean normalized ) throws NamingException;
 
     
     /**
@@ -184,10 +182,10 @@
     Attributes lookup( Name name ) throws NamingException;
 
     /**
-     * Looks up an entry by distinguished name.  This is a simplified version
-     * of the search operation used to point read an entry used for convenience
-     * with a set of attributes to return.  If the attributes are null or emty
-     * this defaults to the lookup opertion without the attributes.
+     * Looks up an entry by distinguished/absolute name.  This is a simplified
+     * version of the search operation used to point read an entry used for
+     * convenience with a set of attributes to return.  If the attributes is
+     * null or empty, the returned entry will contain all attributes.
      *
      * @param dn the normalized distinguished name of the object to lookup
      * @param attrIds the set of attributes to return

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java?rev=193071&r1=193070&r2=193071&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
(original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
Wed Jun 22 21:39:22 2005
@@ -418,7 +418,7 @@
      * BackendNexus.
      * @throws ConfigurationException 
      */
-    private void register( ContextPartition partition ) throws ConfigurationException
+    private void register( ContextPartition partition ) throws NamingException
     {
         String key = partition.getSuffix( true ).toString();
         if( partitions.containsKey( key ) )
@@ -444,7 +444,7 @@
      * @param partition ContextPartition component to unregister with this
      * BackendNexus.
      */
-    private void unregister( ContextPartition partition )
+    private void unregister( ContextPartition partition ) throws NamingException
     {
         Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
         namingContexts.remove( partition.getSuffix( false ).toString() );
@@ -653,7 +653,7 @@
     /**
      * @see ContextPartition#isSuffix(javax.naming.Name)
      */
-    public boolean isSuffix( Name dn ) throws NamingException
+    public boolean isSuffix( Name dn )
     {
         return partitions.containsKey( dn.toString() );
     }

Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/impl/btree/gui/MainFrame.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/impl/btree/gui/MainFrame.java?rev=193071&r1=193070&r2=193071&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/impl/btree/gui/MainFrame.java
(original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/partition/impl/btree/gui/MainFrame.java
Wed Jun 22 21:39:22 2005
@@ -303,7 +303,14 @@
             {
                 System.out.println( "action command = " 
                     + an_event.getActionCommand() );
-				doFilterDialog( an_event.getActionCommand() );
+                try
+                {
+                    doFilterDialog( an_event.getActionCommand() );
+                }
+                catch( NamingException e )
+                {
+                    e.printStackTrace();
+                }
             }
         };
 
@@ -388,7 +395,7 @@
      * @return the DN of the selected tree node or the root Dn of the tree if 
      * nothing has been selected yet.
      */
-    public String getSelectedDn()
+    public String getSelectedDn() throws NamingException
     {
         TreePath path = tree.getSelectionModel().getSelectionPath();
         
@@ -549,7 +556,7 @@
     }
 
 
-    public void doFilterDialog( final String mode )
+    public void doFilterDialog( final String mode ) throws NamingException
     {
         final FilterDialog dialog = new FilterDialog( mode, this, true );
 



Mime
View raw message