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.config.spring;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.context.notification.ServerNotificationListener;
11  import org.springframework.beans.BeansException;
12  import org.springframework.beans.factory.config.BeanPostProcessor;
13  
14  /**
15   * Responsible for passing in the MuleContext instance for all objects in the
16   * registry that want it. For an object to get an instance of the MuleContext it must
17   * implement MuleContextAware.
18   * 
19   * @see org.mule.api.context.MuleContextAware
20   * @see org.mule.api.MuleContext
21   */
22  public class NotificationListenersPostProcessor implements BeanPostProcessor
23  {
24  
25      private final MuleContext muleContext;
26  
27      public NotificationListenersPostProcessor(MuleContext muleContext)
28      {
29          this.muleContext = muleContext;
30      }
31  
32      public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
33      {
34          if (bean instanceof ServerNotificationListener)
35          {
36              if (!muleContext.getNotificationManager().isListenerRegistered((ServerNotificationListener) bean))
37              {
38                  muleContext.getNotificationManager().addListener((ServerNotificationListener) bean);
39              }
40          }
41          return bean;
42      }
43  
44      public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
45      {
46          return bean;
47      }
48  
49  }