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