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.test.integration.spring.events;
8   
9   import org.mule.module.spring.events.MuleApplicationEvent;
10  import org.mule.module.spring.events.MuleEventListener;
11  import org.mule.tck.functional.EventCallback;
12  import org.mule.util.StringMessageUtils;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.springframework.context.ApplicationEvent;
17  
18  /**
19   * <code>TestMuleEventBean</code> is a MuleEventBean for testing with the
20   * MuleEventMulticaster.
21   */
22  
23  public class TestMuleEventBean implements MuleEventListener
24  {
25      private static final Log logger = LogFactory.getLog(TestMuleEventBean.class);
26  
27      private EventCallback eventCallback;
28  
29      public void onApplicationEvent(ApplicationEvent event)
30      {
31          MuleApplicationEvent e = (MuleApplicationEvent)event;
32  
33          logger.debug(StringMessageUtils.getBoilerPlate("Received message on " + e.getEndpoint()));
34  
35          if (eventCallback != null)
36          {
37              try
38              {
39                  eventCallback.eventReceived(e.getMuleEventContext(), event);
40              }
41              catch (Exception e1)
42              {
43                  throw new RuntimeException("Callback failed: " + e1.getMessage(), e1);
44              }
45          }
46      }
47  
48      public EventCallback getEventCallback()
49      {
50          return eventCallback;
51      }
52  
53      public void setEventCallback(EventCallback eventCallback)
54      {
55          this.eventCallback = eventCallback;
56      }
57  
58  }