KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > expression > support > OgnlExpressionParser


1 /*
2  * Copyright 2002-2006 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 package org.springframework.binding.expression.support;
17
18 import ognl.Ognl;
19 import ognl.OgnlException;
20 import ognl.OgnlRuntime;
21 import ognl.PropertyAccessor;
22
23 import org.springframework.binding.expression.Expression;
24 import org.springframework.binding.expression.ParserException;
25 import org.springframework.binding.expression.SettableExpression;
26
27 /**
28  * An expression parser that parses Ognl expressions.
29  *
30  * @author Keith Donald
31  */

32 public class OgnlExpressionParser extends AbstractExpressionParser {
33
34     protected Expression doParseExpression(String JavaDoc expressionString) throws ParserException {
35         return parseSettableExpression(expressionString);
36     }
37
38     public SettableExpression parseSettableExpression(String JavaDoc expressionString) throws ParserException {
39         try {
40             return new OgnlExpression(Ognl.parseExpression(expressionString));
41         }
42         catch (OgnlException e) {
43             throw new ParserException(expressionString, e);
44         }
45     }
46
47     /**
48      * Add a property access strategy for the given class.
49      * @param clazz the class that contains properties needing access
50      * @param propertyAccessor the property access strategy.
51      */

52     public void addPropertyAccessor(Class JavaDoc clazz, PropertyAccessor propertyAccessor) {
53         OgnlRuntime.setPropertyAccessor(clazz, propertyAccessor);
54     }
55 }
Popular Tags