View Javadoc

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