org.xwiki.rendering.listener.chaining
Class ListenerChain

java.lang.Object
  extended by 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$

Constructor Summary
ListenerChain()
           
 
Method Summary
 void addListener(ChainingListener listener)
           
 ChainingListener getListener(Class<? extends ChainingListener> listenerClass)
           
 ChainingListener getNextListener(Class<? extends ChainingListener> listenerClass)
           
 int indexOf(Class<? extends ChainingListener> listenerClass)
           
 void popAllStackableListeners()
          Remove all pushed stackable listeners to go back to the previous state (see pushAllStackableListeners().
 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.
 void pushAllStackableListeners()
          Create new instances of all chaining listeners that are stackable (ie that implement the StackableChainingListener interface.
 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.
 void removeListener(Class<? extends ChainingListener> listenerClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListenerChain

public ListenerChain()
Method Detail

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

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


Copyright © 2004-2013 XWiki. All Rights Reserved.