View Javadoc

1   package com.atlassian.event.legacy;
2   
3   import com.atlassian.event.Event;
4   import com.atlassian.event.EventListener;
5   import org.springframework.context.ApplicationContext;
6   import org.springframework.context.ApplicationContextAware;
7   
8   import static com.google.common.base.Preconditions.checkNotNull;
9   
10  /**
11   * <p>An event listener for all Spring {@link org.springframework.context.ApplicationEvent application events} so that they get published to the actual
12   * Spring context.<p>
13   * <p>Simply register this against your Spring context to handle event the same 'old' way</p>
14   *
15   * @since 2.0.0
16   */
17  public class SpringContextEventPublisher implements ApplicationContextAware, EventListener {
18      private ApplicationContext applicationContext;
19  
20      public void handleEvent(Event event) {
21          checkNotNull(applicationContext).publishEvent(event);
22      }
23  
24      public Class[] getHandledEventClasses() {
25          return new Class[]{Event.class};
26      }
27  
28      public void setApplicationContext(ApplicationContext applicationContext) {
29          this.applicationContext = checkNotNull(applicationContext);
30      }
31  
32      @Override
33      public String toString() {
34          return "SpringContextEventPublisher{applicationContext=" + applicationContext + '}';
35      }
36  }