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.registry;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.expression.ExpressionEvaluator;
11  import org.mule.api.lifecycle.Disposable;
12  import org.mule.api.registry.PreInitProcessor;
13  
14  /** 
15   * Registers ExpressionEvaluators with the {@link org.mule.expression.DefaultExpressionManager} so that they will
16   * be resolved at run-time.
17   * {@link org.mule.api.expression.ExpressionEvaluator} objects are used to execute property expressions (usually on the
18   * current message) at run-time to extract a dynamic value.
19   */
20  public class ExpressionEvaluatorProcessor implements PreInitProcessor, Disposable
21  {
22      private MuleContext context;
23  
24      public ExpressionEvaluatorProcessor(MuleContext context)
25      {
26          this.context = context;
27      }
28  
29      public Object process(Object object)
30      {
31          if(object instanceof ExpressionEvaluator)
32          {
33              context.getExpressionManager().registerEvaluator((ExpressionEvaluator)object);
34          }
35          return object;
36      }
37  
38      /**
39       * A lifecycle method where implementor should free up any resources. If an
40       * exception is thrown it should just be logged and processing should continue.
41       * This method should not throw Runtime exceptions.
42       */
43      public void dispose()
44      {
45          context.getExpressionManager().clearEvaluators();
46      }
47  }