View Javadoc

1   /*
2    * Copyright 2004-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springmodules.validation.util.cel.valang;
18  
19  import org.springmodules.validation.util.cel.CelParseException;
20  import org.springmodules.validation.util.cel.ConditionExpressionParser;
21  import org.springmodules.validation.util.condition.Condition;
22  import org.springmodules.validation.util.condition.adapter.CommonsPredicateCondition;
23  import org.springmodules.validation.valang.parser.ParseException;
24  import org.springmodules.validation.valang.parser.SimpleValangBased;
25  
26  /**
27   * A {@link ConditionExpressionParser} implementation that knows how to parse valang boolean expressions.
28   *
29   * @author Uri Boness
30   */
31  public class ValangConditionExpressionParser extends SimpleValangBased implements ConditionExpressionParser {
32  
33      public Condition parse(String expression) throws CelParseException {
34          try {
35              return new CommonsPredicateCondition(createValangParser(expression).parseExpression());
36          } catch (ParseException pe) {
37              throw new CelParseException("Could not parse valang expression '" + expression + "'", pe);
38          }
39      }
40  
41  }