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