View Javadoc

1   /*
2    * $Id: TestApplicationEventBean.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.spring.events;
12  
13  import org.mule.tck.functional.EventCallback;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  import org.springframework.context.ApplicationEvent;
18  import org.springframework.context.ApplicationListener;
19  
20  /**
21   * <code>TestApplicationEventBean</code> is a bean for testing Spring
22   * ApplicationListeners with the MuleEventMulticaster
23   */
24  
25  public class TestApplicationEventBean implements ApplicationListener
26  {
27      private final Log logger = LogFactory.getLog(this.getClass());
28      private EventCallback eventCallback;
29  
30      public void onApplicationEvent(ApplicationEvent event)
31      {
32          logger.debug("Received Spring event: " + event.getClass().getName());
33  
34          if (eventCallback != null)
35          {
36              try
37              {
38                  eventCallback.eventReceived(null, event);
39              }
40              catch (Exception e1)
41              {
42                  throw new RuntimeException("Callback failed: " + e1.getMessage(), e1);
43              }
44          }
45      }
46  
47      public EventCallback getEventCallback()
48      {
49          return eventCallback;
50      }
51  
52      public void setEventCallback(EventCallback eventCallback)
53      {
54          this.eventCallback = eventCallback;
55      }
56  
57  }