Class ListenerChain

java.lang.Object
org.xwiki.rendering.listener.chaining.ListenerChain

public class ListenerChain extends Object
Stores information about the listeners in the chain and the order in which they need to be called. Also sports a feature that allows pushing and popping listeners that are stackable. This feature is useful since listeners can hold stateful information and sometimes you may need to push new versions of them to start with new state information. For example this is used in the XWiki Syntax Renderer when group event is found to start the rendering for that group using reset state information.
Since:
1.8RC1
Version:
$Id: c8b50060b2849637a5976d7139beb6418ec0ef36 $
  • Constructor Details

    • ListenerChain

      public ListenerChain()
  • Method Details

    • addListener

      public void addListener(ChainingListener listener)
      Parameters:
      listener - the chaining listener to add to the chain. If an instance of that listener is already present then we stack the new instance instead.
    • removeListener

      public void removeListener(Class<? extends ChainingListener> listenerClass)
      Parameters:
      listenerClass - the listener to remove from the chain. If more than one instance of that listener exist in the chain then remove the one from the top of the stack
    • addListener

      public void addListener(ChainingListener listener, int index)
      Parameters:
      listener - the chaining listener to add to the chain. If an instance of that listener is already present then we stack the new instance instead.
      index - the position in the chain where to insert the listener
      Since:
      10.5RC1
    • getNextListener

      public ChainingListener getNextListener(Class<? extends ChainingListener> listenerClass)
      Parameters:
      listenerClass - the listener for which we need to find the next listener in the chain
      Returns:
      the next listener in the chain
    • getListener

      public ChainingListener getListener(Class<? extends ChainingListener> listenerClass)
      Parameters:
      listenerClass - the listener class for which we want to find the listener instance
      Returns:
      the listener instance corresponding to the passed class. Note that the last instance of the stack is returned
    • indexOf

      public int indexOf(Class<? extends ChainingListener> listenerClass)
      Parameters:
      listenerClass - the listener class for which to find the position in the chain
      Returns:
      the position in the chain (first position is 0)
    • pushListener

      public void pushListener(Class<? extends ChainingListener> listenerClass)
      Create a new instance of the passed chaining listener if it's stackable (ie it implements the StackableChainingListener interface. This allows creating a clean state when some sub rendering has to be done with some new state.
      Parameters:
      listenerClass - the listener class for which to create a new instance (if stackable)
    • pushAllStackableListeners

      public void pushAllStackableListeners()
      Create new instances of all chaining listeners that are stackable (ie that implement the StackableChainingListener interface. This allows creating a clean state when some sub rendering has to be done with some new state.
    • popAllStackableListeners

      public void popAllStackableListeners()
      Remove all pushed stackable listeners to go back to the previous state (see pushAllStackableListeners().
    • popListener

      public void popListener(Class<? extends ChainingListener> listenerClass)
      Remove the last instance corresponding to the passed listener class if it's stackable, in order to go back to the previous state.
      Parameters:
      listenerClass - the class of the chaining listener to pop