01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 expressionString)
35: throws ParserException {
36: return doParseSettableExpression(expressionString);
37: }
38:
39: public SettableExpression doParseSettableExpression(
40: String expressionString) throws ParserException {
41: try {
42: return new OgnlExpression(Ognl
43: .parseExpression(expressionString));
44: } catch (OgnlException e) {
45: throw new ParserException(expressionString, e);
46: }
47: }
48:
49: /**
50: * Add a property access strategy for the given class.
51: * @param clazz the class that contains properties needing access
52: * @param propertyAccessor the property access strategy
53: */
54: public void addPropertyAccessor(Class clazz,
55: PropertyAccessor propertyAccessor) {
56: OgnlRuntime.setPropertyAccessor(clazz, propertyAccessor);
57: }
58: }
|