View Javadoc

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