commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henrib <hen...@apache.org>
Subject Re: [jexl] custom expressions / registering functions
Date Wed, 26 May 2010 11:44:34 GMT

Hi,
JEXL should be appropriate feature-wise; adding EL capabilities to a
framework is one of its intents.

JEXL 2.0 allows to invoke any method on an object accessible through the
evaluation context.
It also allows to register functions in namespaces achieved by mapping the
namespace name to an instance or a class - if all methods are static.

<code>
            public static MyMath {
                public double cos(double x) {
                    return Math.cos(x);
                }
            }
            Map<String, Object> funcs = new HashMap<String, Object>();
            funcs.put("math", new MyMath());
            JexlEngine jexl = new JexlEngine();
            jexl.setFunctions(funcs);

            JexlContext jc = new MapContext();
            jc.set("pi", Math.PI);

            e = JEXL.createExpression("math:cos(pi)");
            o = e.evaluate(jc);
            assertEquals(Double.valueOf(-1),o);
</code>

Useful links on the topic:
http://commons.apache.org/jexl/index.html
http://commons.apache.org/jexl/reference/syntax.html  (method calls,
functions)
http://commons.apache.org/jexl/apidocs/index.html

Follow-up if things aren't clear enough;
Regards
Henrib

-- 
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-custom-expressions-registering-functions-tp2228958p2231466.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message