You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Adrian Herscu <ad...@gmail.com> on 2010/05/23 15:39:04 UTC

[jexl] custom expressions / registering functions

Hi all,

I am looking for an expression language to using in a testing framework 
that I am designing.

The requirement is that the users of the framework are allowed to define 
their own functions. I could not find it possible to add a function to a 
JEXL context. Is there any other mechanism?

Please help,
Adrian.


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


Re: [jexl] custom expressions / registering functions

Posted by Paul Libbrecht <pa...@activemath.org>.
Le 25-mai-10 à 06:40, Adrian Herscu a écrit :
> On 24/05/2010 22:52, Paul Libbrecht wrote:
>> Jexl containers allow you to add objects.
>
> Can you, please, send a link for more info?
>
>> At least jelly does.

Jelly is at... commons-jelly:
	http://commons.apache.org/jelly/
some other projects use jexl, especially newer version of it,  
including scxml.

paul


Re: [jexl] custom expressions / registering functions

Posted by Adrian Herscu <ad...@gmail.com>.

On 24/05/2010 22:52, Paul Libbrecht wrote:
> Jexl containers allow you to add objects.

Can you, please, send a link for more info?

> At least jelly does.
>
> And invoking methods on these functions sounds like an easy thing.
>
> paul
>
>
> Le 23-mai-10 à 15:39, Adrian Herscu a écrit :
>
>> Hi all,
>>
>> I am looking for an expression language to using in a testing
>> framework that I am designing.
>>
>> The requirement is that the users of the framework are allowed to
>> define their own functions. I could not find it possible to add a
>> function to a JEXL context. Is there any other mechanism?
>>
>> Please help,
>> Adrian.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>


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


Re: [jexl] custom expressions / registering functions

Posted by Adrian Crum <ad...@yahoo.com>.
You could also take a look at JUEL.

-Adrian

--- On Mon, 5/24/10, Paul Libbrecht <pa...@activemath.org> wrote:

> From: Paul Libbrecht <pa...@activemath.org>
> Subject: Re: [jexl] custom expressions / registering functions
> To: "Commons Users List" <us...@commons.apache.org>
> Date: Monday, May 24, 2010, 12:52 PM
> Jexl containers allow you to add
> objects.
> At least jelly does.
> 
> And invoking methods on these functions sounds like an easy
> thing.
> 
> paul
> 
> 
> Le 23-mai-10 à 15:39, Adrian Herscu a écrit :
> 
> > Hi all,
> > 
> > I am looking for an expression language to using in a
> testing framework that I am designing.
> > 
> > The requirement is that the users of the framework are
> allowed to define their own functions. I could not find it
> possible to add a function to a JEXL context. Is there any
> other mechanism?
> > 
> > Please help,
> > Adrian.
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> > 
> 
> 


      

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


Re: [jexl] custom expressions / registering functions

Posted by Paul Libbrecht <pa...@activemath.org>.
Jexl containers allow you to add objects.
At least jelly does.

And invoking methods on these functions sounds like an easy thing.

paul


Le 23-mai-10 à 15:39, Adrian Herscu a écrit :

> Hi all,
>
> I am looking for an expression language to using in a testing  
> framework that I am designing.
>
> The requirement is that the users of the framework are allowed to  
> define their own functions. I could not find it possible to add a  
> function to a JEXL context. Is there any other mechanism?
>
> Please help,
> Adrian.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


Re: [jexl] custom expressions / registering functions

Posted by Jörg Schaible <jo...@gmx.de>.
Adrian Herscu wrote:

> Hi all,
> 
> I am looking for an expression language to using in a testing framework
> that I am designing.
> 
> The requirement is that the users of the framework are allowed to define
> their own functions. I could not find it possible to add a function to a
> JEXL context. Is there any other mechanism?

Why don't you simply use the JavaScript engine (JSR 223)? It comes out of 
the box with Java 6 (including Rhino) and for earlier JDKs you can use 
Apache BSF (http://jakarta.apache.org/bsf/) that implements also JSR 223 and 
provides therefore a smooth upgrade path. With the embedded JavaScript of 
Rhino you can access easily also all Java stuff.

- Jörg


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


Re: [jexl] custom expressions / registering functions

Posted by henrib <he...@apache.org>.
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