View Javadoc

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