directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r158592 - in directory/apacheds/branches/interceptor_revamp/core/src: main/java/org/apache/ldap/server/jndi/ main/java/org/apache/ldap/server/jndi/invocation/interceptor/ test/org/apache/ldap/server/jndi/invocation/ test/org/apache/ldap/server/jndi/invocation/interceptor/
Date Tue, 22 Mar 2005 11:10:16 GMT
Author: trustin
Date: Tue Mar 22 03:10:11 2005
New Revision: 158592

URL: http://svn.apache.org/viewcvs?view=rev&rev=158592
Log:
* Added InterceptorConfigBuilder which generates appropriate configuration map for each interceptors.

Added:
    directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java
  (with props)
    directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/
    directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/
    directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java
  (with props)
Modified:
    directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
    directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorChain.java

Modified: directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java?view=diff&r1=158591&r2=158592
==============================================================================
--- directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
(original)
+++ directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/CoreContextFactory.java
Tue Mar 22 03:10:11 2005
@@ -50,6 +50,7 @@
 import org.apache.ldap.server.db.ExpressionEvaluator;
 import org.apache.ldap.server.db.SearchEngine;
 import org.apache.ldap.server.db.jdbm.JdbmDatabase;
+import org.apache.ldap.server.jndi.invocation.interceptor.InterceptorConfigBuilder;
 import org.apache.ldap.server.jndi.invocation.interceptor.Interceptor;
 import org.apache.ldap.server.jndi.invocation.interceptor.InterceptorChain;
 import org.apache.ldap.server.jndi.invocation.interceptor.InterceptorContext;
@@ -495,9 +496,10 @@
             // If custom interceptor is not specified, use defaule one.
             interceptor = InterceptorChain.newDefaultChain();
         }
-        // FIXME interceptor config is passed incorrectly
+
         interceptor.init( new InterceptorContext(
-                initialEnv, system, globalRegistries, nexus, initialEnv ) );
+                initialEnv, system, globalRegistries, nexus,
+                InterceptorConfigBuilder.build( initialEnv, EnvKeys.INTERCEPTOR ) ) );
         provider.setInterceptor( interceptor );
 
         // fire up the app partitions now!

Modified: directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorChain.java?view=diff&r1=158591&r2=158592
==============================================================================
--- directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorChain.java
(original)
+++ directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorChain.java
Tue Mar 22 03:10:11 2005
@@ -18,6 +18,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
@@ -55,11 +56,17 @@
      */
     public static final ChainType POSTPROCESS = new ChainType();
     
+    /**
+     * Returns a new chain of default interceptors required to run core.
+     */
     public static InterceptorChain newDefaultChain()
     {
         return newDefaultChain( PREPROCESS );
     }
     
+    /**
+     * Returns a new chain of default interceptors required to run core.
+     */
     public static InterceptorChain newDefaultChain( ChainType type )
     {
         InterceptorChain chain = new InterceptorChain( type );
@@ -100,6 +107,7 @@
     private InterceptorChain parent;
     private final ChainType type;
     private final Map name2entry = new HashMap();
+    private final Map interceptor2entry = new IdentityHashMap();
     private Entry head = new Entry( null, null, "end", FINAL_INTERCEPTOR );
     private final Entry tail = head;
 
@@ -127,7 +135,7 @@
     /**
      * Initializes all interceptors this chain contains.
      */
-    public synchronized void init( InterceptorContext context ) throws NamingException
+    public synchronized void init( InterceptorContext ctx ) throws NamingException
     {
         ListIterator it = getAll().listIterator();
         Interceptor interceptor = null;
@@ -136,7 +144,14 @@
             while( it.hasNext() )
             {
                 interceptor = ( Interceptor ) it.next();
-                interceptor.init( context );
+                String name = getName( interceptor );
+                InterceptorContext newCtx = new InterceptorContext(
+                        ctx.getEnvironment(), ctx.getSystemPartition(),
+                        ctx.getGlobalRegistries(), ctx.getRootNexus(),
+                        InterceptorConfigBuilder.build(
+                                ctx.getConfig(), ( name == null ) ? "" : name ) );
+                
+                interceptor.init( newCtx );
             }
         }
         catch( Throwable t )
@@ -202,7 +217,17 @@
         }
         return e.interceptor;
     }
-
+    
+    private String getName( Interceptor interceptor )
+    {
+        Entry e = ( Entry ) interceptor2entry.get( interceptor );
+        if( e == null )
+        {
+            return null;
+        }
+        return e.name;
+    }
+    
     /**
      * Adds the specified interceptor with the specified name at the beginning
      * of this chain.
@@ -312,6 +337,7 @@
 
         name2entry.remove( name );
         Interceptor interceptor = entry.interceptor;
+        interceptor2entry.remove( interceptor );
         if( interceptor instanceof InterceptorChain )
         {
             ( ( InterceptorChain ) interceptor ).parent = null;
@@ -333,6 +359,7 @@
     private void register(String name, Entry newEntry) {
         Interceptor interceptor = newEntry.interceptor;
         name2entry.put( name, newEntry );
+        interceptor2entry.put( newEntry.interceptor, newEntry );
         if( interceptor instanceof InterceptorChain )
         {
             ( ( InterceptorChain ) interceptor ).parent = this;

Added: directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java?view=auto&rev=158592
==============================================================================
--- directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java
(added)
+++ directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java
Tue Mar 22 03:10:11 2005
@@ -0,0 +1,39 @@
+package org.apache.ldap.server.jndi.invocation.interceptor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class InterceptorConfigBuilder {
+
+    public static Map build(Map map, String prefix)
+    {
+        Map newMap = new HashMap();
+        Iterator it = map.entrySet().iterator();
+        while( it.hasNext() )
+        {
+            Map.Entry e = (Map.Entry) it.next();
+            String key = e.getKey().toString();
+            if( key.startsWith( prefix ) && key.length() > prefix.length() )
+            {
+                key = key.substring( prefix.length() );
+                if( key.indexOf( '#' ) < 0 )
+                {
+                    continue;
+                }
+                if( key.charAt(0) == '.' || key.charAt(0) == '#' )
+                {
+                    key = key.substring( 1 );
+                }
+                
+                newMap.put( key, e.getValue() );
+            }
+        }
+        
+        return newMap;
+    }
+    
+    private InterceptorConfigBuilder()
+    {
+    }
+}

Propchange: directory/apacheds/branches/interceptor_revamp/core/src/main/java/org/apache/ldap/server/jndi/invocation/interceptor/InterceptorConfigBuilder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java?view=auto&rev=158592
==============================================================================
--- directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java
(added)
+++ directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java
Tue Mar 22 03:10:11 2005
@@ -0,0 +1,105 @@
+package org.apache.ldap.server.jndi.invocation.interceptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.NamingException;
+
+import junit.framework.Assert;
+
+import org.apache.ldap.server.AbstractServerTest;
+import org.apache.ldap.server.jndi.EnvKeys;
+import org.apache.ldap.server.jndi.invocation.Invocation;
+
+public class ConfigurationTest extends AbstractServerTest {
+    
+    private TestInterceptorChain rootChain = new TestInterceptorChain();
+    private TestInterceptorChain childChain = new TestInterceptorChain();
+    private TestInterceptor interceptorA = new TestInterceptor();
+    private TestInterceptor interceptorB = new TestInterceptor();
+    
+    protected void setUp() throws Exception
+    {
+        rootChain.addLast( "A", interceptorA );
+        rootChain.addLast( "child", childChain );
+        childChain.addLast( "B", interceptorB );
+        rootChain.addLast( "default", InterceptorChain.newDefaultChain() );
+        
+        extras.put( EnvKeys.INTERCEPTOR, rootChain );
+        extras.put( EnvKeys.INTERCEPTOR + "#root", "1" );
+        extras.put( EnvKeys.INTERCEPTOR + ".A", "2" );
+        extras.put( EnvKeys.INTERCEPTOR + ".A#A", "3" );
+        extras.put( EnvKeys.INTERCEPTOR + ".A#A.A", "4" );
+        extras.put( EnvKeys.INTERCEPTOR + ".child#child", "5" );
+        extras.put( EnvKeys.INTERCEPTOR + ".child.B", "6" );
+        extras.put( EnvKeys.INTERCEPTOR + ".child.B#B", "7" );
+        extras.put( EnvKeys.INTERCEPTOR + ".child.B#B.B", "8" );
+        
+        super.setUp();
+    }
+    
+    public void testRootChain() throws Exception
+    {
+        Map expected = new HashMap();
+        expected.put( "root", "1" );
+        expected.put( "A#A", "3" );
+        expected.put( "A#A.A", "4" );
+        expected.put( "child#child", "5" );
+        expected.put( "child.B#B", "7" );
+        expected.put( "child.B#B.B", "8" );
+        Assert.assertEquals( expected, rootChain.config );
+    }
+
+    public void testChildChain() throws Exception
+    {
+        Map expected = new HashMap();
+        expected.put( "child", "5" );
+        expected.put( "B#B", "7" );
+        expected.put( "B#B.B", "8" );
+        Assert.assertEquals( expected, childChain.config );
+    }
+    
+    public void testA() throws Exception
+    {
+        Map expected = new HashMap();
+        expected.put( "A", "3" );
+        expected.put( "A.A", "4" );
+        Assert.assertEquals( expected, interceptorA.config );
+    }
+
+    public void testB() throws Exception
+    {
+        Map expected = new HashMap();
+        expected.put( "B", "7" );
+        expected.put( "B.B", "8" );
+        Assert.assertEquals( expected, interceptorB.config );
+    }
+    
+    private static class TestInterceptorChain extends InterceptorChain
+    {
+        private Map config;
+        
+        public synchronized void init(InterceptorContext ctx) throws NamingException {
+            config = ctx.getConfig();
+            super.init(ctx);
+        }
+        
+    }
+
+    private static class TestInterceptor implements Interceptor
+    {
+        private Map config;
+
+        public void init(InterceptorContext context) throws NamingException {
+            config = context.getConfig();
+        }
+
+        public void destroy() {
+        }
+
+        public void process(NextInterceptor nextInterceptor, Invocation invocation) throws
NamingException {
+            nextInterceptor.process( invocation );
+        }
+    }
+    
+}

Propchange: directory/apacheds/branches/interceptor_revamp/core/src/test/org/apache/ldap/server/jndi/invocation/interceptor/ConfigurationTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message