View Javadoc

1   /*
2    * $Id: FilterConverter.java 20321 2010-11-24 15:21:24Z dfeist $
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.config.converters;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.api.expression.PropertyConverter;
14  import org.mule.api.routing.filter.Filter;
15  import org.mule.expression.ExpressionConfig;
16  import org.mule.routing.filters.ExpressionFilter;
17  
18  /**
19   * Converts an Expression sting into a Filter object. The string must define an expression that results in a
20   * boolean value.
21   */
22  public class FilterConverter implements PropertyConverter
23  {
24      public Object convert(String property, MuleContext context)
25      {
26          if (null != property)
27          {
28              ExpressionConfig config = new ExpressionConfig();
29              config.parse(property);
30              ExpressionFilter filter = new ExpressionFilter(config.getExpression(), config.getEvaluator(), config.getCustomEvaluator());
31              filter.setMuleContext(context);
32              return filter;
33          }
34          else
35          {
36              return null;
37          }
38  
39      }
40  
41      public Class getType()
42      {
43          return Filter.class;
44      }
45  }