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.expression.ExpressionEvaluator;
11  import org.mule.api.expression.ExpressionManager;
12  
13  import org.springframework.beans.BeansException;
14  import org.springframework.beans.factory.config.BeanPostProcessor;
15  
16  /**
17   * Registers custom declarative expression evaluators configured via Spring config.
18   *
19   * @see ExpressionEvaluator
20   */
21  public class ExpressionEvaluatorPostProcessor implements BeanPostProcessor
22  {
23      private MuleContext muleContext;
24  
25      public ExpressionEvaluatorPostProcessor(MuleContext muleContext)
26      {
27          this.muleContext = muleContext;
28      }
29  
30      public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
31      {
32          if (muleContext == null)
33          {
34              return bean;
35          }
36  
37          if (bean instanceof ExpressionEvaluator)
38          {
39              ExpressionEvaluator ee = (ExpressionEvaluator) bean;
40  
41              final ExpressionManager expressionManager = muleContext.getExpressionManager();
42              if (!expressionManager.isEvaluatorRegistered(ee.getName()))
43              {
44                  expressionManager.registerEvaluator(ee);
45              }
46          }
47          return bean;
48      }
49  
50      public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
51      {
52          return bean;
53      }
54  
55  }