yep you got it .... just use bypass instructions. All methods into the
interceptor chain have overload for taking a list of interceptors to bypass
during IC processing.
Alex
On 4/25/07, Martin Alderson <Martin.Alderson@salfordsoftware.co.uk> wrote:
>
>
> 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
>
>
|