directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Alderson" <Martin.Alder...@salfordsoftware.co.uk>
Subject Re: Skipping interceptors
Date Wed, 25 Apr 2007 16:16:02 GMT

Ah, I think I've got it.

For anyone interested (not yet tested!):

/////
    private DirectoryServiceConfiguration factoryCfg; // from init()
    private InterceptorConfiguration cfg; // from init()

//....

    private Collection getBypassAndPreviousInterceptors
(Collection<String> interceptors) {
        Invocation invocation = InvocationStack.getInstance().peek();
        
        boolean found = false;
        
        List interceptorConfigurations =
factoryCfg.getStartupConfiguration().getInterceptorConfigurations();
        for (Iterator i = interceptorConfigurations.iterator();
i.hasNext(); ) {
            InterceptorConfiguration configuration =
(InterceptorConfiguration) i.next();
            String name = configuration.getName();
            if (!found || invocation.isBypassed(name)) {
                // Previous interceptor or interceptor to bypass.
                interceptors.add(name);
            }
            if (configuration.equals(cfg)) {
                found = true;
            }
        }
        
        return interceptors;
    }
    
    /**
     * @return A new Invocation that starts where this interceptor left
off.
     */
    private Invocation newContinuationInvocation (Collection
bypassInterceptors) {
        Invocation invocation = InvocationStack.getInstance().peek();
        Collection bypass =
getBypassAndPreviousInterceptors(bypassInterceptors);
        return new Invocation(invocation.getProxy(),
invocation.getCaller(), invocation.getName(),
invocation.getParameters().toArray(), bypass);
    }
/////

Now I can just do something like:

    public boolean hasEntry (NextInterceptor next, LdapDN name) throws
NamingException {
        if (condition) {
            Collection<String> c = new HashSet<String>();
            c.add( "eventService" );  // Interceptor to skip.
            InvocationStack stack = InvocationStack.getInstance();
            stack.push(newContinuationInvocation(c));
            try {
                return factoryCfg.getInterceptorChain().hasEntry( name
);
            } finally {
                stack.pop();
            }
        } else {
            return next.hasEntry(name);
        }
    }


Martin


Mime
View raw message