Class ListenerChain
java.lang.Object
org.xwiki.rendering.listener.chaining.ListenerChain
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ChainingListener listener) voidaddListener(ChainingListener listener, int index) getListener(Class<? extends ChainingListener> listenerClass) getNextListener(Class<? extends ChainingListener> listenerClass) intindexOf(Class<? extends ChainingListener> listenerClass) voidRemove all pushed stackable listeners to go back to the previous state (seepushAllStackableListeners().voidpopListener(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.voidCreate new instances of all chaining listeners that are stackable (ie that implement theStackableChainingListenerinterface.voidpushListener(Class<? extends ChainingListener> listenerClass) Create a new instance of the passed chaining listener if it's stackable (ie it implements theStackableChainingListenerinterface.voidremoveListener(Class<? extends ChainingListener> listenerClass)
-
Constructor Details
-
ListenerChain
public ListenerChain()
-
-
Method Details
-
addListener
- 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
- 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
- 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
- Parameters:
listenerClass- the listener for which we need to find the next listener in the chain- Returns:
- the next listener in the chain
-
getListener
- 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
- 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
Create a new instance of the passed chaining listener if it's stackable (ie it implements theStackableChainingListenerinterface. 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 theStackableChainingListenerinterface. 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 (seepushAllStackableListeners(). -
popListener
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
-