01: /* ApacheELFactory.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Aug 30 11:12:14 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zkmax.xel.el21;
20:
21: import javax.el.ELContext;
22:
23: import org.zkoss.xel.Expression;
24: import org.zkoss.xel.ExpressionFactory;
25: import org.zkoss.xel.XelContext;
26: import org.zkoss.xel.XelException;
27:
28: /**
29: * An implementation based on org.apache.el.ExpressionFactoryImpl.
30: *
31: * @author tomyeh
32: * @since 3.0.0
33: */
34: public class ApacheELFactory implements ExpressionFactory {
35: private final javax.el.ExpressionFactory _expf;
36:
37: public ApacheELFactory() {
38: _expf = newExpressionFactory();
39: }
40:
41: //ExpressionFactory//
42: public boolean isSupported(int feature) {
43: return feature == FEATURE_FUNCTION;
44: }
45:
46: public Expression parseExpression(XelContext xelc,
47: String expression, Class expectedType) throws XelException {
48: return new ELXelExpression(_expf.createValueExpression(
49: new XelELContext(xelc), expression, expectedType));
50: }
51:
52: public Object evaluate(XelContext xelc, String expression,
53: Class expectedType) throws XelException {
54: final ELContext ctx = new XelELContext(xelc);
55: return _expf.createValueExpression(ctx, expression,
56: expectedType).getValue(ctx);
57: }
58:
59: /** Returns the EL expression factory.
60: * <p>Default: Use org.apache.el.ExpressionFactoryImpl.
61: * <p>You might override it to use a different implementation.
62: */
63: protected javax.el.ExpressionFactory newExpressionFactory() {
64: return new org.apache.el.ExpressionFactoryImpl();
65: }
66: }
|