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