You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/06/22 12:38:01 UTC
svn commit: r191792 [2/3] - in
/directory/apacheds/branches/db_refactor/core: ./ src/main/aspects/
src/main/java/org/apache/ldap/server/authn/
src/main/java/org/apache/ldap/server/authz/
src/main/java/org/apache/ldap/server/exception/ src/main/java/org...
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorChain.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorChain.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorChain.java Wed Jun 22 03:37:56 2005
@@ -19,16 +19,24 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import javax.naming.ConfigurationException;
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import org.apache.ldap.common.filter.ExprNode;
import org.apache.ldap.server.configuration.InterceptorConfiguration;
-import org.apache.ldap.server.invocation.Invocation;
+import org.apache.ldap.server.configuration.MutableInterceptorConfiguration;
+import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
+import org.apache.ldap.server.partition.ContextPartitionNexus;
/**
@@ -43,12 +51,11 @@
{
private final Interceptor FINAL_INTERCEPTOR = new Interceptor()
{
- private InterceptorContext ctx;
+ private ContextPartitionNexus nexus;
-
- public void init( InterceptorContext context )
+ public void init( ContextFactoryConfiguration factoryCfg, InterceptorConfiguration cfg )
{
- ctx = context;
+ this.nexus = factoryCfg.getPartitionNexus();
}
@@ -58,83 +65,154 @@
}
- public void process( NextInterceptor nextInterceptor, Invocation call ) throws NamingException
+ public Attributes getRootDSE( NextInterceptor next ) throws NamingException
{
- if ( parent == null )
- {
- // execute the actual backend operation only when this chain is root.
+ return nexus.getRootDSE();
+ }
- call.execute( ctx.getRootNexus() );
- }
+
+ public Name getMatchedDn( NextInterceptor next, Name dn, boolean normalized ) throws NamingException
+ {
+ return ( Name ) nexus.getMatchedDn( dn, normalized ).clone();
}
- };
- private InterceptorChain parent;
- private final Map name2entry = new HashMap();
+ public Name getSuffix( NextInterceptor next, Name dn, boolean normalized ) throws NamingException
+ {
+ return ( Name ) nexus.getSuffix( dn, normalized ).clone();
+ }
+
+
+ public Iterator listSuffixes( NextInterceptor next, boolean normalized ) throws NamingException
+ {
+ return nexus.listSuffixes( normalized );
+ }
+
+
+ public void delete( NextInterceptor next, Name name ) throws NamingException
+ {
+ nexus.delete( name );
+ }
+
+
+ public void add( NextInterceptor next, String upName, Name normName, Attributes entry ) throws NamingException
+ {
+ nexus.add( upName, normName, entry );
+ }
+
+
+ public void modify( NextInterceptor next, Name name, int modOp, Attributes mods ) throws NamingException
+ {
+ nexus.modify( name, modOp, mods );
+ }
+
+
+ public void modify( NextInterceptor next, Name name, ModificationItem[] mods ) throws NamingException
+ {
+ nexus.modify( name, mods );
+ }
+
+
+ public NamingEnumeration list( NextInterceptor next, Name base ) throws NamingException
+ {
+ return nexus.list( base );
+ }
+
+
+ public NamingEnumeration search( NextInterceptor next, Name base, Map env, ExprNode filter, SearchControls searchCtls ) throws NamingException
+ {
+ return nexus.search( base, env, filter, searchCtls );
+ }
+
+
+ public Attributes lookup( NextInterceptor next, Name name ) throws NamingException
+ {
+ return ( Attributes ) nexus.lookup( name ).clone();
+ }
+
+
+ public Attributes lookup( NextInterceptor next, Name dn, String[] attrIds ) throws NamingException
+ {
+ return ( Attributes ) nexus.lookup( dn, attrIds ).clone();
+ }
+
+
+ public boolean hasEntry( NextInterceptor next, Name name ) throws NamingException
+ {
+ return nexus.hasEntry( name );
+ }
+
+
+ public boolean isSuffix( NextInterceptor next, Name name ) throws NamingException
+ {
+ return nexus.isSuffix( name );
+ }
+
+
+ public void modifyRn( NextInterceptor next, Name name, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ nexus.modifyRn( name, newRn, deleteOldRn );
+ }
+
+
+ public void move( NextInterceptor next, Name oriChildName, Name newParentName ) throws NamingException
+ {
+ nexus.move( oriChildName, newParentName );
+ }
+
+
+ public void move( NextInterceptor next, Name oriChildName, Name newParentName, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ nexus.move( oriChildName, newParentName, newRn, deleteOldRn );
+ }
+ };
- private final Map interceptor2entry = new IdentityHashMap();
+ private final Map name2entry = new HashMap();
- private final Entry tail = new Entry( null, null, "end", FINAL_INTERCEPTOR );
+ private final Entry tail;
- private Entry head = tail;
+ private Entry head;
+ private ContextFactoryConfiguration factoryCfg;
/**
* Create a new interceptor chain.
*/
public InterceptorChain()
{
- this( new ArrayList() );
- }
-
- /**
- * Creates a new interceptor chain
- * @param configurations
- */
- public InterceptorChain( List configurations )
- {
- Iterator it = configurations.iterator();
- while( it.hasNext() )
- {
- InterceptorConfiguration cfg = ( InterceptorConfiguration ) it.next();
- this.addLast( cfg.getName(), cfg.getInterceptor() );
- }
+ MutableInterceptorConfiguration tailCfg = new MutableInterceptorConfiguration();
+ tailCfg.setName( "tail" );
+ tailCfg.setInterceptor( FINAL_INTERCEPTOR );
+ tail = new Entry( null, null, tailCfg );
+ head = tail;
}
/**
* Initializes all interceptors this chain contains.
*/
- public synchronized void init( InterceptorContext ctx ) throws NamingException
+ public synchronized void init( ContextFactoryConfiguration factoryCfg ) throws NamingException
{
- ListIterator it = getAll().listIterator();
+ this.factoryCfg = factoryCfg;
+ // Initialize tail first.
+ FINAL_INTERCEPTOR.init( factoryCfg, null );
+
+ // And register and initialize all interceptors
+ ListIterator i = factoryCfg.getConfiguration().getInterceptorConfigurations().listIterator();
Interceptor interceptor = null;
-
try
{
- while ( it.hasNext() )
+ while( i.hasNext() )
{
- interceptor = ( Interceptor ) it.next();
- interceptor.init( ctx );
+ InterceptorConfiguration cfg = ( InterceptorConfiguration ) i.next();
+ register( cfg );
}
}
catch ( Throwable t )
{
- while ( it.hasPrevious() )
- {
- Interceptor i = ( Interceptor ) it.previous();
-
- try
- {
- i.destroy();
- }
- catch ( Throwable t2 )
- {
- t2.printStackTrace();
- }
- }
+ // destroy if failed to initialize all interceptors.
+ destroy();
if ( t instanceof NamingException )
{
@@ -142,7 +220,7 @@
}
else
{
- throw new InterceptorException( interceptor, null, "Failed to initialize interceptor chain.", t );
+ throw new InterceptorException( interceptor, "Failed to initialize interceptor chain.", t );
}
}
}
@@ -153,163 +231,105 @@
*/
public synchronized void destroy()
{
- ListIterator it = getAllReversed().listIterator();
-
- while ( it.hasNext() )
+ List entries = new ArrayList();
+ Entry e = tail;
+ do
{
- Interceptor interceptor = ( Interceptor ) it.next();
-
- try
- {
- interceptor.destroy();
- }
- catch ( Throwable t )
- {
- t.printStackTrace();
- }
+ entries.add( e );
+ e = e.prevEntry;
}
- }
-
-
- /**
- * Returns the interceptor with the specified <code>name</code>.
- *
- * @return <code>null</code> if there is no interceptor with the specified <code>name</code>.
- */
- public Interceptor get( String name )
- {
- Entry e = ( Entry ) name2entry.get( name );
+ while ( e != null );
- if ( e == null )
+ Iterator i = entries.iterator();
+ while ( i.hasNext() )
{
- return null;
+ e = ( Entry ) i.next();
+ if( e != tail )
+ {
+ try
+ {
+ deregister( e.configuration );
+ }
+ catch ( Throwable t )
+ {
+ t.printStackTrace();
+ }
+ }
}
-
- return e.interceptor;
- }
-
-
- /**
- * Adds the specified interceptor with the specified name at the beginning of this chain.
- */
- public synchronized void addFirst( String name,
- Interceptor interceptor )
- {
- checkAddable( name, interceptor );
- register( name, interceptor, head );
}
/**
* Adds the specified interceptor with the specified name at the end of this chain.
+ * @throws NamingException
*/
- public synchronized void addLast( String name,
- Interceptor interceptor )
- {
- checkAddable( name, interceptor );
- register( name, interceptor, tail );
- }
-
-
- /**
- * Adds the specified interceptor with the specified name just before the interceptor whose name is
- * <code>baseName</code> in this chain.
- */
- public synchronized void addBefore( String baseName, String name, Interceptor interceptor )
- {
- Entry baseEntry = checkOldName( baseName );
- checkAddable( name, interceptor );
- register( name, interceptor, baseEntry );
- }
-
-
- /**
- * Adds the specified interceptor with the specified name just after the interceptor whose name is
- * <code>baseName</code> in this chain.
- */
- public synchronized void addAfter( String baseName, String name, Interceptor interceptor )
+ private void register( InterceptorConfiguration cfg ) throws NamingException
{
- Entry baseEntry = checkOldName( baseName );
- checkAddable( name, interceptor );
- register( name, interceptor, baseEntry );
+ checkAddable( cfg );
+ register0( cfg, tail );
}
/**
* Removes the interceptor with the specified name from this chain.
+ * @throws ConfigurationException
*/
- public synchronized void remove( String name )
+ private void deregister( InterceptorConfiguration cfg ) throws ConfigurationException
{
+ String name = cfg.getName();
Entry entry = checkOldName( name );
-
Entry prevEntry = entry.prevEntry;
-
Entry nextEntry = entry.nextEntry;
+ if( nextEntry == null )
+ {
+ // Don't deregister tail
+ return;
+ }
+
if ( prevEntry == null )
{
nextEntry.prevEntry = null;
-
head = entry;
}
else
{
prevEntry.nextEntry = nextEntry;
-
nextEntry.prevEntry = prevEntry;
}
name2entry.remove( name );
-
- Interceptor interceptor = entry.interceptor;
-
- interceptor2entry.remove( interceptor );
-
- if ( interceptor instanceof InterceptorChain )
- {
- ( ( InterceptorChain ) interceptor ).parent = null;
- }
- }
-
-
- /**
- * Removes all interceptors added to this chain.
- */
- public synchronized void clear()
- {
- Iterator it = new ArrayList( name2entry.keySet() ).iterator();
-
- while ( it.hasNext() )
- {
- this.remove( ( String ) it.next() );
- }
+ entry.configuration.getInterceptor().destroy();
}
- private void register( String name, Interceptor interceptor, Entry nextEntry )
+ private void register0( InterceptorConfiguration cfg, Entry nextEntry ) throws NamingException
{
+ String name = cfg.getName();
+ Interceptor interceptor = cfg.getInterceptor();
+ interceptor.init( factoryCfg, cfg );
+
Entry newEntry;
if( nextEntry == head )
{
- newEntry = new Entry( null, head, name, interceptor );
+ newEntry = new Entry( null, head, cfg );
head.prevEntry = newEntry;
head = newEntry;
}
else if( head == tail )
{
- newEntry = new Entry( null, tail, name, interceptor );
+ newEntry = new Entry( null, tail, cfg );
tail.prevEntry = newEntry;
head = newEntry;
}
else
{
- newEntry = new Entry( nextEntry.prevEntry, nextEntry, name, interceptor );
+ newEntry = new Entry( nextEntry.prevEntry, nextEntry, cfg );
nextEntry.prevEntry.nextEntry = newEntry;
nextEntry.prevEntry = newEntry;
}
name2entry.put( name, newEntry );
- interceptor2entry.put( newEntry.interceptor, newEntry );
}
@@ -318,13 +338,13 @@
*
* @return An interceptor entry with the specified name.
*/
- private Entry checkOldName( String baseName )
+ private Entry checkOldName( String baseName ) throws ConfigurationException
{
Entry e = ( Entry ) name2entry.get( baseName );
if ( e == null )
{
- throw new IllegalArgumentException( "Unknown interceptor name:" + baseName );
+ throw new ConfigurationException( "Unknown interceptor name:" + baseName );
}
return e;
@@ -334,35 +354,42 @@
/**
* Checks the specified interceptor name is already taken and throws an exception if already taken.
*/
- private void checkAddable( String name, Interceptor interceptor )
+ private void checkAddable( InterceptorConfiguration cfg ) throws ConfigurationException
{
- if ( name2entry.containsKey( name ) )
+ if ( name2entry.containsKey( cfg.getName() ) )
{
- throw new IllegalArgumentException( "Other interceptor is using name '" + name + "'" );
+ throw new ConfigurationException( "Other interceptor is using name '" + cfg.getName() + "'" );
}
+ }
+
- if ( interceptor instanceof InterceptorChain )
+ public Attributes getRootDSE() throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
{
- if ( ( ( InterceptorChain ) interceptor ).parent != null )
- {
- throw new IllegalArgumentException( "This interceptor chain has its parent already." );
- }
+ return head.getRootDSE( next );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
}
}
- /**
- * Start invocation chain with the specified invocation.
- *
- * @throws NamingException if invocation failed
- */
- public void process( Invocation invocation ) throws NamingException
+ public Name getMatchedDn( Name dn, boolean normalized ) throws NamingException
{
- Entry head = this.head;
-
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
try
{
- head.interceptor.process( head.nextInterceptor, invocation );
+ return head.getMatchedDn( next, dn, normalized );
}
catch ( NamingException ne )
{
@@ -370,95 +397,585 @@
}
catch ( Throwable e )
{
- throw new InterceptorException( head.interceptor, invocation, "Unexpected exception.", e );
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
}
}
- /**
- * Returns the list of interceptors this chain in the order of evaluation.
- */
- public List getAll()
+ public Name getSuffix( Name dn, boolean normalized ) throws NamingException
{
- List list = new ArrayList();
-
- Entry e = head;
-
- do
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
{
- list.add( e.interceptor );
-
- e = e.nextEntry;
+ return head.getSuffix( next, dn, normalized );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
}
- while ( e != null );
-
- return list;
}
- /**
- * Returns the list of interceptors this chain in the reversed order of evaluation.
- */
- public List getAllReversed()
+ public Iterator listSuffixes( boolean normalized ) throws NamingException
{
- List list = new ArrayList();
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.listSuffixes( next, normalized );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
- Entry e = tail;
- do
+ public void delete( Name name ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
{
- list.add( e.interceptor );
-
- e = e.prevEntry;
+ head.delete( next, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
}
+ }
- while ( e != null );
- return list;
+ public void add( String upName, Name normName, Attributes entry ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.add( next, upName, normName, entry );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
}
- /**
- * Represents an internal entry of this chain.
- */
- private class Entry
+ public void modify( Name name, int modOp, Attributes mods ) throws NamingException
{
- private Entry prevEntry;
-
- private Entry nextEntry;
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.modify( next, name, modOp, mods );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
+ }
- private final Interceptor interceptor;
- private final NextInterceptor nextInterceptor;
+ public void modify( Name name, ModificationItem[] mods ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.modify( next, name, mods );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
+ }
- private Entry( Entry prevEntry, Entry nextEntry,
- String name, Interceptor interceptor )
+ public NamingEnumeration list( Name base ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
{
- if ( interceptor == null )
- {
- throw new NullPointerException( "interceptor" );
- }
- if ( name == null )
+ return head.list( next, base );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public NamingEnumeration search( Name base, Map env, ExprNode filter, SearchControls searchCtls ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.search( next, base, env, filter, searchCtls );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public Attributes lookup( Name name ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.lookup( next, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public Attributes lookup( Name dn, String[] attrIds ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.lookup( next, dn, attrIds );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public boolean hasEntry( Name name ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.hasEntry( next, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public boolean isSuffix( Name name ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ return head.isSuffix( next, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+
+ public void modifyRn( Name name, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.modifyRn( next, name, newRn, deleteOldRn );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
+ }
+
+
+ public void move( Name oriChildName, Name newParentName ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.move( next, oriChildName, newParentName );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
+ }
+
+
+ public void move( Name oriChildName, Name newParentName, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ Interceptor head = this.head.configuration.getInterceptor();
+ NextInterceptor next = this.head.nextInterceptor;
+ try
+ {
+ head.move( next, oriChildName, newParentName, newRn, deleteOldRn );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( head, e );
+ }
+ }
+
+
+ /**
+ * Represents an internal entry of this chain.
+ */
+ private class Entry
+ {
+ private Entry prevEntry;
+
+ private Entry nextEntry;
+
+ private final InterceptorConfiguration configuration;
+
+ private final NextInterceptor nextInterceptor;
+
+
+ private Entry( Entry prevEntry, Entry nextEntry,
+ InterceptorConfiguration configuration )
+ {
+ if ( configuration == null )
{
- throw new NullPointerException( "name" );
+ throw new NullPointerException( "configuration" );
}
this.prevEntry = prevEntry;
this.nextEntry = nextEntry;
- this.interceptor = interceptor;
+ this.configuration = configuration;
this.nextInterceptor = new NextInterceptor()
{
- public void process( Invocation call ) throws NamingException
+ public Attributes getRootDSE() throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.getRootDSE( Entry.this.nextEntry.nextInterceptor );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public Name getMatchedDn( Name dn, boolean normalized ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.getMatchedDn( Entry.this.nextEntry.nextInterceptor, dn, normalized );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public Name getSuffix( Name dn, boolean normalized ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.getSuffix( Entry.this.nextEntry.nextInterceptor, dn, normalized );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public Iterator listSuffixes( boolean normalized ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.listSuffixes( Entry.this.nextEntry.nextInterceptor, normalized );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public void delete( Name name ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.delete( Entry.this.nextEntry.nextInterceptor, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public void add( String upName, Name normName, Attributes entry ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.add( Entry.this.nextEntry.nextInterceptor, upName, normName, entry );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public void modify( Name name, int modOp, Attributes mods ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.modify( Entry.this.nextEntry.nextInterceptor, name, modOp, mods );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public void modify( Name name, ModificationItem[] mods ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.modify( Entry.this.nextEntry.nextInterceptor, name, mods );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public NamingEnumeration list( Name base ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.list( Entry.this.nextEntry.nextInterceptor, base );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public NamingEnumeration search( Name base, Map env, ExprNode filter, SearchControls searchCtls ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.search( Entry.this.nextEntry.nextInterceptor, base, env, filter, searchCtls );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public Attributes lookup( Name name ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.lookup( Entry.this.nextEntry.nextInterceptor, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public Attributes lookup( Name dn, String[] attrIds ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.lookup( Entry.this.nextEntry.nextInterceptor, dn, attrIds );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public boolean hasEntry( Name name ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ return interceptor.hasEntry( Entry.this.nextEntry.nextInterceptor, name );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public boolean isSuffix( Name name ) throws NamingException
{
- Interceptor interceptor = Entry.this.nextEntry.interceptor;
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
try
{
- interceptor.process( Entry.this.nextEntry.nextInterceptor, call );
+ return interceptor.isSuffix( Entry.this.nextEntry.nextInterceptor, name );
}
catch ( NamingException ne )
{
@@ -466,10 +983,71 @@
}
catch ( Throwable e )
{
- throw new InterceptorException( interceptor, call, "Unexpected exception.", e );
+ throwInterceptorException( interceptor, e );
+ throw new InternalError(); // Should be unreachable
+ }
+ }
+
+ public void modifyRn( Name name, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.modifyRn( Entry.this.nextEntry.nextInterceptor, name, newRn, deleteOldRn );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public void move( Name oriChildName, Name newParentName ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.move( Entry.this.nextEntry.nextInterceptor, oriChildName, newParentName );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
+ }
+ }
+
+ public void move( Name oriChildName, Name newParentName, String newRn, boolean deleteOldRn ) throws NamingException
+ {
+ Interceptor interceptor = Entry.this.nextEntry.configuration.getInterceptor();
+
+ try
+ {
+ interceptor.move( Entry.this.nextEntry.nextInterceptor, oriChildName, newParentName, newRn, deleteOldRn );
+ }
+ catch ( NamingException ne )
+ {
+ throw ne;
+ }
+ catch ( Throwable e )
+ {
+ throwInterceptorException( interceptor, e );
}
}
};
}
+ }
+
+
+ private static void throwInterceptorException( Interceptor interceptor, Throwable e ) throws InterceptorException
+ {
+ throw new InterceptorException( interceptor, "Unexpected exception.", e );
}
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorException.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorException.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorException.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/InterceptorException.java Wed Jun 22 03:37:56 2005
@@ -34,11 +34,6 @@
private static final long serialVersionUID = 3258690996517746233L;
/**
- * The Invocation the Interceptor failed on
- */
- private final Invocation invocation;
-
- /**
* The Interceptor causing the failure
*/
private final Interceptor interceptor;
@@ -48,14 +43,10 @@
* Creates an InterceptorException without a message.
*
* @param interceptor the Interceptor causing the failure
- * @param invocation the Invocation the Interceptor failed on
*/
- public InterceptorException( Interceptor interceptor, Invocation invocation )
+ public InterceptorException( Interceptor interceptor )
{
super( ResultCodeEnum.OTHER );
-
- this.invocation = invocation;
-
this.interceptor = interceptor;
}
@@ -64,15 +55,11 @@
* Creates an InterceptorException with a custom message.
*
* @param interceptor the Interceptor causing the failure
- * @param invocation the Invocation the Interceptor failed on
* @param explanation String explanation of why the Interceptor failed
*/
- public InterceptorException( Interceptor interceptor, Invocation invocation, String explanation )
+ public InterceptorException( Interceptor interceptor, String explanation )
{
super( explanation, ResultCodeEnum.OTHER );
-
- this.invocation = invocation;
-
this.interceptor = interceptor;
}
@@ -81,13 +68,11 @@
* Creates an InterceptorException without a message.
*
* @param interceptor the Interceptor causing the failure
- * @param invocation the Invocation the Interceptor failed on
* @param rootCause the root cause of this exception
*/
- public InterceptorException( Interceptor interceptor, Invocation invocation, Throwable rootCause )
+ public InterceptorException( Interceptor interceptor, Throwable rootCause )
{
- this( interceptor, invocation );
-
+ this( interceptor );
super.setRootCause( rootCause );
}
@@ -96,27 +81,14 @@
* Creates an InterceptorException without a message.
*
* @param interceptor the Interceptor causing the failure
- * @param invocation the Invocation the Interceptor failed on
* @param explanation String explanation of why the Interceptor failed
* @param rootCause the root cause of this exception
*/
- public InterceptorException( Interceptor interceptor, Invocation invocation, String explanation,
+ public InterceptorException( Interceptor interceptor, String explanation,
Throwable rootCause )
{
- this( interceptor, invocation, explanation );
-
+ this( interceptor, explanation );
super.setRootCause( rootCause );
- }
-
-
- /**
- * Gets the invovation object this exception is associated with.
- *
- * @return the invovation object this exception is associated with
- */
- public Invocation getInvocation()
- {
- return invocation;
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/NextInterceptor.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/NextInterceptor.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/NextInterceptor.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/interceptor/NextInterceptor.java Wed Jun 22 03:37:56 2005
@@ -17,9 +17,17 @@
package org.apache.ldap.server.interceptor;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
-import org.apache.ldap.server.invocation.Invocation;
+import org.apache.ldap.common.filter.ExprNode;
/**
@@ -32,12 +40,23 @@
*/
public interface NextInterceptor
{
- /**
- * Passes the control of current invocation to the next {@link org.apache.ldap.server.interceptor.Interceptor} in
- * the {@link org.apache.ldap.server.interceptor.InterceptorChain}.
- *
- * @param incovation
- * @throws NamingException
- */
- void process( Invocation incovation ) throws NamingException;
+ Attributes getRootDSE() throws NamingException;
+ Name getMatchedDn( Name dn, boolean normalized ) throws NamingException;
+ Name getSuffix( Name dn, boolean normalized ) throws NamingException;
+ Iterator listSuffixes( boolean normalized ) throws NamingException;
+ void delete( Name name ) throws NamingException;
+ void add( String upName, Name normName, Attributes entry ) throws NamingException;
+ void modify( Name name, int modOp, Attributes mods ) throws NamingException;
+ void modify( Name name, ModificationItem [] mods ) throws NamingException;
+ NamingEnumeration list( Name base ) throws NamingException;
+ NamingEnumeration search( Name base, Map env, ExprNode filter,
+ SearchControls searchCtls ) throws NamingException;
+ Attributes lookup( Name name ) throws NamingException;
+ Attributes lookup( Name dn, String [] attrIds ) throws NamingException;
+ boolean hasEntry( Name name ) throws NamingException;
+ boolean isSuffix( Name name ) throws NamingException;
+ void modifyRn( Name name, String newRn, boolean deleteOldRn ) throws NamingException;
+ void move( Name oriChildName, Name newParentName ) throws NamingException;
+ void move( Name oriChildName, Name newParentName, String newRn,
+ boolean deleteOldRn ) throws NamingException;
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/Invocation.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/Invocation.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/Invocation.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/Invocation.java Wed Jun 22 03:37:56 2005
@@ -17,10 +17,11 @@
package org.apache.ldap.server.invocation;
-import java.io.Serializable;
-import java.util.Stack;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
-import javax.naming.NamingException;
+import javax.naming.Context;
import org.apache.ldap.server.partition.ContextPartition;
@@ -34,82 +35,72 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public abstract class Invocation implements Serializable
+public class Invocation
{
-
- protected transient Object returnValue;
-
- protected transient Stack contextStack;
-
+ private final Context target;
+ private final String name;
+ private final List parameters;
/**
- * Creates a new instance. This constructor does nothing.
+ * Creates a new instance.
*/
- protected Invocation()
+ public Invocation( Context target, String name )
{
+ this( target, name, null );
}
-
/**
- * Returns the returnValue object for this invocation.
- */
- public Object getReturnValue()
- {
- return returnValue;
+ * Creates a new instance.
+ */
+ public Invocation( Context target, String name, Object[] parameters )
+ {
+ if( target == null )
+ {
+ throw new NullPointerException( "target" );
+ }
+ if( name == null )
+ {
+ throw new NullPointerException( "name" );
+ }
+
+ if( parameters == null )
+ {
+ parameters = new Object[ 0 ];
+ }
+
+ this.target = target;
+ this.name = name;
+
+ List paramList = new ArrayList();
+ for( int i = 0; i < parameters.length; i++ )
+ {
+ paramList.add( parameters[ i ] );
+ }
+
+ this.parameters = Collections.unmodifiableList( paramList );
}
-
-
- /**
- * Sets the returnValue object for this invocation.
- */
- public void setReturnValue( Object returnValue )
- {
- this.returnValue = returnValue;
- }
-
-
+
/**
- * Gets the context stack in which this invocation occurs. The
- * context stack is a stack of LdapContexts.
- *
- * @return a stack of LdapContexts in which the invocation occurs
+ * Returns the target context of this invocation.
*/
- public Stack getContextStack()
+ public Context getTarget()
{
- return contextStack;
+ return target;
}
-
-
+
/**
- * Sets the context stack in which this invocation occurs. The context stack
- * is a stack of LdapContexts.
- *
- * @param contextStack a stack of LdapContexts in which the invocation occurs
+ * Returns the name of this invocation.
*/
- public void setContextStack( Stack contextStack )
+ public String getName()
{
- this.contextStack = contextStack;
+ return name;
}
-
-
+
/**
- * Executes this invocation on the specified <code>store</code>. The default
- * implementation calls an abstract method {@link #doExecute(ContextPartition)}
- * and sets the <code>returnValue</code> property of this invocation to its return value.
- *
- * @throws NamingException if the operation failed
+ * Returns the list of parameters
*/
- public void execute( ContextPartition store ) throws NamingException
+ public List getParameters()
{
- setReturnValue( doExecute( store ) );
+ return parameters;
}
-
-
- /**
- * Implement this method to invoke the appropriate operation on the specified
- * <code>store</code>. Returned value will be set as the <code>returnValue</code> proeprty of this invocation.
- *
- * @throws NamingException if the operation failed
- */
- protected abstract Object doExecute( ContextPartition store ) throws NamingException;
}
Added: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/InvocationStack.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/InvocationStack.java?rev=191792&view=auto
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/InvocationStack.java (added)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/InvocationStack.java Wed Jun 22 03:37:56 2005
@@ -0,0 +1,69 @@
+package org.apache.ldap.server.invocation;
+
+
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public final class InvocationStack
+{
+ // I didn't use ThreadLocal to release contexts explicitly.
+ // It seems like JDK 1.5 supports explicit release by introducing
+ // <tt>ThreadLocal.remove()</tt>, but we're still targetting 1.4.
+ private static final Map stacks = new IdentityHashMap();
+
+ public static InvocationStack getInstance()
+ {
+ Thread currentThread = Thread.currentThread();
+ InvocationStack ctx = ( InvocationStack ) stacks.get( currentThread );
+ if( ctx == null )
+ {
+ ctx = new InvocationStack();
+ }
+ return ctx;
+ }
+
+ private final Thread thread;
+ private final List stack = new ArrayList();
+
+ private InvocationStack()
+ {
+ Thread currentThread = Thread.currentThread();
+ this.thread = currentThread;
+ stacks.put( currentThread, this );
+ }
+
+ public Invocation[] toArray()
+ {
+ Invocation[] result = new Invocation[ stack.size() ];
+ result = ( Invocation[] ) stack.toArray( result );
+ return result;
+ }
+
+ public Invocation peek()
+ {
+ return ( Invocation ) this.stack.get( 0 );
+ }
+
+ public void push( Invocation invocation )
+ {
+ this.stack.add( 0, invocation );
+ }
+
+ public Invocation pop()
+ {
+ Invocation invocation = ( Invocation ) this.stack.remove( 0 );
+ if( this.stack.size() == 0 )
+ {
+ stacks.remove( thread );
+ }
+
+ return invocation;
+ }
+}
Propchange: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/invocation/InvocationStack.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextFactoryConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextFactoryConfiguration.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextFactoryConfiguration.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ContextFactoryConfiguration.java Wed Jun 22 03:37:56 2005
@@ -22,7 +22,7 @@
import javax.naming.NamingException;
import org.apache.ldap.server.configuration.StartupConfiguration;
-import org.apache.ldap.server.invocation.Invocation;
+import org.apache.ldap.server.interceptor.InterceptorChain;
import org.apache.ldap.server.partition.ContextPartitionNexus;
import org.apache.ldap.server.schema.GlobalRegistries;
@@ -50,6 +50,11 @@
ContextPartitionNexus getPartitionNexus();
/**
+ * Returns the interceptor chain of this context factory
+ */
+ InterceptorChain getInterceptorChain();
+
+ /**
* Returns <tt>true</tt> if this context is started for the first time
* and bootstrap entries have been created.
*/
@@ -63,11 +68,6 @@
Context getJndiContext( String rootDN ) throws NamingException;
Context getJndiContext( String principal, byte[] credential, String authentication, String rootDN ) throws NamingException;
- /**
- * Invokes {@link Invocation} to this context.
- */
- Object invoke( Invocation call ) throws NamingException;
-
void sync() throws NamingException;
void shutdown() throws NamingException;
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=191792&r1=191791&r2=191792&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 03:37:56 2005
@@ -19,6 +19,7 @@
import java.util.Iterator;
import java.util.Map;
+import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -29,136 +30,310 @@
import org.apache.ldap.common.filter.ExprNode;
import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
-import org.apache.ldap.server.invocation.Add;
-import org.apache.ldap.server.invocation.Delete;
-import org.apache.ldap.server.invocation.GetMatchedDN;
-import org.apache.ldap.server.invocation.GetSuffix;
-import org.apache.ldap.server.invocation.HasEntry;
-import org.apache.ldap.server.invocation.IsSuffix;
-import org.apache.ldap.server.invocation.List;
-import org.apache.ldap.server.invocation.ListSuffixes;
-import org.apache.ldap.server.invocation.Lookup;
-import org.apache.ldap.server.invocation.LookupWithAttrIds;
-import org.apache.ldap.server.invocation.Modify;
-import org.apache.ldap.server.invocation.ModifyMany;
-import org.apache.ldap.server.invocation.ModifyRN;
-import org.apache.ldap.server.invocation.Move;
-import org.apache.ldap.server.invocation.MoveAndModifyRN;
-import org.apache.ldap.server.invocation.Search;
+import org.apache.ldap.server.invocation.Invocation;
+import org.apache.ldap.server.invocation.InvocationStack;
import org.apache.ldap.server.partition.ContextPartition;
import org.apache.ldap.server.partition.ContextPartitionNexus;
class ContextPartitionNexusProxy extends ContextPartitionNexus
{
+ private final Context target;
private final ContextFactoryConfiguration provider;
- ContextPartitionNexusProxy( ContextFactoryConfiguration provider )
+ ContextPartitionNexusProxy( Context target, ContextFactoryConfiguration provider )
{
+ this.target = target;
this.provider = provider;
}
-
+
public LdapContext getLdapContext() {
return this.provider.getPartitionNexus().getLdapContext();
}
+ public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException
+ {
+ throw new IllegalStateException();
+ }
+
+ public void destroy() throws NamingException
+ {
+ throw new IllegalStateException();
+ }
+
+ public ContextPartition getSystemPartition()
+ {
+ return this.provider.getPartitionNexus().getSystemPartition();
+ }
+
+ public Name getSuffix( boolean normalized )
+ {
+ return this.provider.getPartitionNexus().getSuffix( normalized );
+ }
+
+ public void sync() throws NamingException {
+ this.provider.sync();
+ }
+
+ public void close() throws NamingException {
+ this.provider.shutdown();
+ }
+
+ public boolean isInitialized() {
+ return this.provider.isStarted();
+ }
+
public Name getMatchedDn(Name dn, boolean normalized) throws NamingException {
- return ( Name ) this.provider.invoke( new GetMatchedDN( dn, normalized ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "getMatchedDn",
+ new Object[] { dn, normalized? Boolean.TRUE : Boolean.FALSE } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().getMatchedDn( dn, normalized );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public Name getSuffix(Name dn, boolean normalized) throws NamingException {
- return ( Name ) this.provider.invoke( new GetSuffix( dn, normalized ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "getSuffix",
+ new Object[] { dn, normalized? Boolean.TRUE : Boolean.FALSE } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().getSuffix( dn, normalized );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public Iterator listSuffixes(boolean normalized) throws NamingException {
- return ( Iterator ) this.provider.invoke( new ListSuffixes( normalized ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "listSuffixes",
+ new Object[] { normalized? Boolean.TRUE : Boolean.FALSE } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().listSuffixes( normalized );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void delete(Name name) throws NamingException {
- this.provider.invoke( new Delete( name ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "delete",
+ new Object[] { name } ) );
+ try
+ {
+ this.provider.getInterceptorChain().delete( name );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void add(String upName, Name normName, Attributes entry) throws NamingException {
- this.provider.invoke( new Add( upName, normName, entry ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "add",
+ new Object[] { upName, normName, entry } ) );
+ try
+ {
+ this.provider.getInterceptorChain().add( upName, normName, entry );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void modify(Name name, int modOp, Attributes mods) throws NamingException {
- this.provider.invoke( new Modify( name, modOp, mods ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ // TODO Use predefined modOp Interger constants.
+ stack.push( new Invocation(
+ target, "modify",
+ new Object[] { name, new Integer( modOp ), mods } ) );
+ try
+ {
+ this.provider.getInterceptorChain().modify( name, modOp, mods );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void modify(Name name, ModificationItem[] mods) throws NamingException {
- this.provider.invoke( new ModifyMany( name, mods ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "modify",
+ new Object[] { name, mods } ) );
+ try
+ {
+ this.provider.getInterceptorChain().modify( name, mods );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public NamingEnumeration list(Name base) throws NamingException {
- return ( NamingEnumeration ) this.provider.invoke( new List( base ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "list",
+ new Object[] { base } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().list( base );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public NamingEnumeration search(Name base, Map env, ExprNode filter, SearchControls searchCtls) throws NamingException {
- return ( NamingEnumeration ) this.provider.invoke( new Search( base, env, filter, searchCtls ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "search",
+ new Object[] { base, env, filter, searchCtls } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().search( base, env, filter, searchCtls );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public Attributes lookup(Name name) throws NamingException {
- return ( Attributes ) this.provider.invoke( new Lookup( name ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "lookup",
+ new Object[] { name } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().lookup( name );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public Attributes lookup(Name dn, String[] attrIds) throws NamingException {
- return ( Attributes ) this.provider.invoke( new LookupWithAttrIds( dn, attrIds ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "lookup",
+ new Object[] { dn, attrIds } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().lookup( dn, attrIds );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public boolean hasEntry(Name name) throws NamingException {
- return Boolean.TRUE.equals( this.provider.invoke( new HasEntry( name ) ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "hasEntry",
+ new Object[] { name } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().hasEntry( name );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public boolean isSuffix(Name name) throws NamingException {
- return Boolean.TRUE.equals( this.provider.invoke( new IsSuffix( name ) ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "isSuffix",
+ new Object[] { name } ) );
+ try
+ {
+ return this.provider.getInterceptorChain().isSuffix( name );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void modifyRn(Name name, String newRn, boolean deleteOldRn) throws NamingException {
- this.provider.invoke( new ModifyRN( name, newRn, deleteOldRn ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "modifyRn",
+ new Object[] { name, newRn, deleteOldRn? Boolean.TRUE : Boolean.FALSE } ) );
+ try
+ {
+ this.provider.getInterceptorChain().modifyRn( name, newRn, deleteOldRn );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void move(Name oriChildName, Name newParentName) throws NamingException {
- this.provider.invoke( new Move( oriChildName, newParentName ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "move",
+ new Object[] { oriChildName, newParentName } ) );
+ try
+ {
+ this.provider.getInterceptorChain().move( oriChildName, newParentName );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
public void move(Name oriChildName, Name newParentName, String newRn, boolean deleteOldRn) throws NamingException {
- this.provider.invoke( new MoveAndModifyRN( oriChildName, newParentName, newRn, deleteOldRn ) );
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation(
+ target, "move",
+ new Object[] { oriChildName, newParentName, newRn, deleteOldRn? Boolean.TRUE : Boolean.FALSE } ) );
+ try
+ {
+ this.provider.getInterceptorChain().move( oriChildName, newParentName, newRn, deleteOldRn );
+ }
+ finally
+ {
+ stack.pop();
+ }
}
- public void sync() throws NamingException {
- this.provider.sync();
- }
-
- public void close() throws NamingException {
- this.provider.shutdown();
- }
-
- public boolean isInitialized() {
- return this.provider.getPartitionNexus().isInitialized();
- }
-
- public void init( ContextFactoryConfiguration factoryCfg, ContextPartitionConfiguration cfg ) throws NamingException
+ public Attributes getRootDSE() throws NamingException
{
- throw new IllegalStateException();
- }
-
- public void destroy() throws NamingException
- {
- throw new IllegalStateException();
- }
-
- public Name getSuffix( boolean normalized )
- {
- return this.provider.getPartitionNexus().getSuffix( normalized );
- }
-
- public Attributes getRootDSE()
- {
- return this.provider.getPartitionNexus().getRootDSE();
- }
-
- public ContextPartition getSystemPartition()
- {
- return this.provider.getPartitionNexus().getSystemPartition();
+ InvocationStack stack = InvocationStack.getInstance();
+ stack.push( new Invocation( target, "getRootDSE" ) );
+ try
+ {
+ return this.provider.getInterceptorChain().getRootDSE();
+ }
+ finally
+ {
+ stack.pop();
+ }
}
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/DefaultContextFactoryConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/DefaultContextFactoryConfiguration.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/DefaultContextFactoryConfiguration.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/DefaultContextFactoryConfiguration.java Wed Jun 22 03:37:56 2005
@@ -38,8 +38,6 @@
import org.apache.ldap.server.configuration.ConfigurationException;
import org.apache.ldap.server.configuration.StartupConfiguration;
import org.apache.ldap.server.interceptor.InterceptorChain;
-import org.apache.ldap.server.interceptor.InterceptorContext;
-import org.apache.ldap.server.invocation.Invocation;
import org.apache.ldap.server.partition.ContextPartitionNexus;
import org.apache.ldap.server.partition.DefaultContextPartitionNexus;
import org.apache.ldap.server.schema.AttributeTypeRegistry;
@@ -78,9 +76,6 @@
/** The interceptor (or interceptor chain) for this provider */
private InterceptorChain interceptorChain;
- /** PartitionNexus proxy wrapping nexus to inject services */
- private final ContextPartitionNexus proxy = new ContextPartitionNexusProxy(this);
-
/** whether or not this instance has been shutdown */
private boolean started = false;
@@ -150,7 +145,7 @@
}
environment.put( Context.PROVIDER_URL, rootDN );
- return new ServerLdapContext( proxy, environment );
+ return new ServerLdapContext( this, environment );
}
public synchronized void startup( AbstractContextFactory factory, Hashtable env ) throws NamingException
@@ -257,6 +252,11 @@
return partitionNexus;
}
+ public InterceptorChain getInterceptorChain()
+ {
+ return interceptorChain;
+ }
+
public boolean isFirstStart()
{
return firstStart;
@@ -267,17 +267,6 @@
return started;
}
- public Object invoke( Invocation call ) throws NamingException
- {
- if( !started )
- {
- throw new IllegalStateException( "ApacheDS is not started yet." );
- }
-
- interceptorChain.process( call );
- return call.getReturnValue();
- }
-
/**
* Checks to make sure security environment parameters are set correctly.
*
@@ -497,7 +486,7 @@
partitionNexus = new DefaultContextPartitionNexus( new LockableAttributesImpl() );
partitionNexus.init( this, null );
- interceptorChain = new InterceptorChain( configuration.getInterceptorConfigurations() );
- interceptorChain.init( new InterceptorContext( configuration, partitionNexus.getSystemPartition(), globalRegistries, partitionNexus ) );
+ interceptorChain = new InterceptorChain();
+ interceptorChain.init( this );
}
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerContext.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerContext.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerContext.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerContext.java Wed Jun 22 03:37:56 2005
@@ -90,14 +90,13 @@
* @throws NamingException if the environment parameters are not set
* correctly.
*/
- protected ServerContext( ContextPartitionNexus nexusProxy, Hashtable env ) throws NamingException
+ protected ServerContext( ContextFactoryConfiguration cfg, Hashtable env ) throws NamingException
{
- String url;
-
// set references to cloned env and the proxy
- this.nexusProxy = nexusProxy;
-
- this.env = ( Hashtable ) env.clone();
+ this.nexusProxy = new ContextPartitionNexusProxy( this, cfg );
+
+ this.env = ( Hashtable ) cfg.getEnvironment().clone();
+ this.env.putAll( env );
/* --------------------------------------------------------------------
* check for the provider URL property and make sure it exists
@@ -106,18 +105,16 @@
if ( ! env.containsKey( Context.PROVIDER_URL ) )
{
String msg = "Expected property " + Context.PROVIDER_URL;
-
msg += " but could not find it in env!";
throw new ConfigurationException( msg );
}
- url = ( String ) env.get( Context.PROVIDER_URL );
+ String url = ( String ) env.get( Context.PROVIDER_URL );
if ( url == null )
{
String msg = "Expected value for property " + Context.PROVIDER_URL;
-
msg += " but it was set to null in env!";
throw new ConfigurationException( msg );
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java Wed Jun 22 03:37:56 2005
@@ -71,9 +71,9 @@
* @param env the environment used for this context
* @throws NamingException if something goes wrong
*/
- public ServerDirContext( ContextPartitionNexus nexusProxy, Hashtable env ) throws NamingException
+ public ServerDirContext( ContextFactoryConfiguration cfg, Hashtable env ) throws NamingException
{
- super( nexusProxy, env );
+ super( cfg, env );
}
Modified: directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java?rev=191792&r1=191791&r2=191792&view=diff
==============================================================================
--- directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java (original)
+++ directory/apacheds/branches/db_refactor/core/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java Wed Jun 22 03:37:56 2005
@@ -52,9 +52,9 @@
* @param env the JNDI environment parameters
* @throws NamingException the context cannot be created
*/
- public ServerLdapContext( ContextPartitionNexus nexusProxy, Hashtable env ) throws NamingException
+ public ServerLdapContext( ContextFactoryConfiguration cfg, Hashtable env ) throws NamingException
{
- super( nexusProxy, env );
+ super( cfg, env );
}