View Javadoc

1   package com.atlassian.johnson.event;
2   
3   import com.atlassian.event.api.EventListener;
4   import com.atlassian.johnson.Johnson;
5   
6   import javax.servlet.ServletContext;
7   
8   /**
9    * A simple listener which may be used with the Atlassian Events framework to listen for {@link AddEvent add} and
10   * {@link RemoveEvent remove} events on the bus, allowing simplified interaction with Johnson.
11   *
12   * @since 2.0
13   */
14  public class JohnsonEventListener
15  {
16      private final ServletContext servletContext;
17  
18      public JohnsonEventListener(ServletContext servletContext)
19      {
20          this.servletContext = servletContext;
21      }
22  
23      /**
24       * Adds the Johnson {@link Event} wrapped by the provided {@link AddEvent}  to the container.
25       * 
26       * @param e the add event
27       */
28      @EventListener
29      public void onAdd(AddEvent e)
30      {
31          Johnson.getEventContainer(servletContext).addEvent(e.getEvent());
32      }
33  
34      /**
35       * Attempts to remove the Johnson {@link Event} wrapped by the provided {@link RemoveEvent} from the container.
36       *
37       * @param e the remove event
38       */
39      @EventListener
40      public void onRemove(RemoveEvent e)
41      {
42          Johnson.getEventContainer(servletContext).removeEvent(e.getEvent());
43      }
44  }