1   /*
2    * $Id: OrderManagerBean.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.MuleSubscriptionEventListener;
15  
16  import org.springframework.context.ApplicationEvent;
17  
18  /**
19   * <code>OrderManagerBean</code> receives Order beans from Mule and dispatches
20   * processed results back through Mule via the applicationContext
21   */
22  public class OrderManagerBean extends TestMuleEventBean
23      implements OrderManager, MuleSubscriptionEventListener
24  {
25      private String[] subscriptions;
26  
27      public void onApplicationEvent(ApplicationEvent event)
28      {
29          super.onApplicationEvent(event);
30          // Get the order
31          Order order = (Order)event.getSource();
32          String result = processOrder(order);
33  
34          // Cast the event to a Mule event, we'll use this to get the AppContext
35          MuleApplicationEvent muleEvent = (MuleApplicationEvent)event;
36  
37          // Create a new DefaultMuleEvent. This will be sent to the replyTo
38          // address
39          MuleApplicationEvent returnEvent = null;
40  
41          returnEvent = new MuleApplicationEvent(result, "jms://processed.queue");
42  
43          // Call publish on the application context, Mule will do the rest
44          muleEvent.getApplicationContext().publishEvent(returnEvent);
45      }
46  
47      public String processOrder(Order order)
48      {
49          // Do some processing...
50          return "Order '" + order.getOrder() + "' Processed";
51      }
52  
53      public String[] getSubscriptions()
54      {
55          return subscriptions;
56      }
57  
58      public void setSubscriptions(String[] subscriptions)
59      {
60          this.subscriptions = subscriptions;
61      }
62  
63  }