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