org.xcmis.search.content.interceptors
Class InterceptorChain

java.lang.Object
  extended by org.xcmis.search.content.interceptors.InterceptorChain
All Implemented Interfaces:
Startable

public class InterceptorChain
extends Object
implements Startable

Knows how to build and manage an chain of interceptors. Also in charge with invoking methods on the chain.


Constructor Summary
InterceptorChain(CommandInterceptor first)
          Constructs an interceptor chain having the supplied interceptor as first.
 
Method Summary
 boolean addAfterInterceptor(CommandInterceptor toAdd, Class<? extends CommandInterceptor> afterInterceptor)
          Adds a new interceptor in list after an interceptor of a given type.
 boolean addBeforeInterceptor(CommandInterceptor toAdd, Class<? extends CommandInterceptor> beforeInterceptor)
          Adds a new interceptor in list after an interceptor of a given type.
 void addInterceptor(CommandInterceptor interceptor, int position)
          Inserts the given interceptor at the specified position in the chain (o based indexing).
 void appendIntereceptor(CommandInterceptor ci)
          Appends at the end.
 List<CommandInterceptor> asList()
          Returns an unmofiable list with all the interceptors in sequence.
 boolean containsInstance(CommandInterceptor interceptor)
          Checks whether the chain contains the supplied interceptor instance.
 CommandInterceptor getFirstInChain()
           
 String getInterceptorDetails()
           
 List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass)
          Returns all interceptors which extend the given command interceptor.
 List<CommandInterceptor> getInterceptorsWithClassName(String fqName)
          Returns all the interceptors that have the fully qualified name of their class equal with the supplied class name.
 Object invoke(InvocationContext ctx, VisitableCommand command)
          Walks the command through the interceptor chain.
 void removeInterceptor(Class<? extends CommandInterceptor> clazz)
          Removes all the occurences of supplied interceptor type from the chain.
 void removeInterceptor(int position)
          Removes the interceptor at the given postion.
 void setFirstInChain(CommandInterceptor interceptor)
          Mainly used by unit tests to replace the interceptor chain with the starting point passed in.
 int size()
          Returns the number of interceptors in the chain.
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterceptorChain

public InterceptorChain(CommandInterceptor first)
Constructs an interceptor chain having the supplied interceptor as first.

Method Detail

addAfterInterceptor

public boolean addAfterInterceptor(CommandInterceptor toAdd,
                                   Class<? extends CommandInterceptor> afterInterceptor)
Adds a new interceptor in list after an interceptor of a given type.

Parameters:
toAdd -
afterInterceptor -
Returns:
true if the interceptor was added; i.e. the afterInterceptor exists

addBeforeInterceptor

public boolean addBeforeInterceptor(CommandInterceptor toAdd,
                                    Class<? extends CommandInterceptor> beforeInterceptor)
Adds a new interceptor in list after an interceptor of a given type.

Parameters:
toAdd -
beforeInterceptor -
Returns:
true if the interceptor was added; i.e. the afterInterceptor exists

addInterceptor

public void addInterceptor(CommandInterceptor interceptor,
                           int position)
Inserts the given interceptor at the specified position in the chain (o based indexing).

Parameters:
interceptor - CommandInterceptor
position - int
Throws:
IllegalArgumentException - if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)

appendIntereceptor

public void appendIntereceptor(CommandInterceptor ci)
Appends at the end.

Parameters:
ci - CommandInterceptor

asList

public List<CommandInterceptor> asList()
Returns an unmofiable list with all the interceptors in sequence. If first in chain is null an empty list is returned.


containsInstance

public boolean containsInstance(CommandInterceptor interceptor)
Checks whether the chain contains the supplied interceptor instance.


getFirstInChain

public CommandInterceptor getFirstInChain()
Returns:
the first interceptor in the chain.

getInterceptorDetails

public String getInterceptorDetails()

getInterceptorsWhichExtend

public List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass)
Returns all interceptors which extend the given command interceptor.

Parameters:
interceptorClass -

getInterceptorsWithClassName

public List<CommandInterceptor> getInterceptorsWithClassName(String fqName)
Returns all the interceptors that have the fully qualified name of their class equal with the supplied class name.

Parameters:
fqName - String

invoke

public Object invoke(InvocationContext ctx,
                     VisitableCommand command)
              throws Throwable
Walks the command through the interceptor chain. The received ctx is being passed in.

Throws:
Throwable

removeInterceptor

public void removeInterceptor(Class<? extends CommandInterceptor> clazz)
Removes all the occurences of supplied interceptor type from the chain.


removeInterceptor

public void removeInterceptor(int position)
Removes the interceptor at the given postion.

Throws:
IllegalArgumentException - if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)

setFirstInChain

public void setFirstInChain(CommandInterceptor interceptor)
Mainly used by unit tests to replace the interceptor chain with the starting point passed in.

Parameters:
interceptor - interceptor to be used as the first interceptor in the chain.

size

public int size()
Returns the number of interceptors in the chain.


start

public void start()
Specified by:
start in interface Startable
See Also:
Startable.start()

stop

public void stop()
Specified by:
stop in interface Startable
See Also:
Startable.stop()


Copyright © 2010 eXo Platform SAS. All Rights Reserved.