View Javadoc

1   /*
2    * $Id: TestMuleEventBean.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  
19  /**
20   * <code>TestMuleEventBean</code> is a MuleEventBean for testing with the
21   * MuleEventMulticaster.
22   */
23  
24  public class TestMuleEventBean implements MuleEventListener
25  {
26      private final Log logger = LogFactory.getLog(this.getClass());
27      private EventCallback eventCallback;
28  
29      public void onApplicationEvent(ApplicationEvent event)
30      {
31          MuleApplicationEvent e = (MuleApplicationEvent)event;
32  
33          logger.debug("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  }