Yes, you can use your own classes and custom method.
You do need to specify you class in namespaces declaration, like this:

Map< String, Object> ns = new HashMap< >();
ns.put("foo", new Foo());
ns,put("bar", new Bar());
JexlEngine engine = (new JexlBuilder()).namespaces(ns).create();

Now in your expressions you can use something like "foo:extractField1(incoming)"
Good luck.

Gary Greenberg
Staff Software Engineer
Data Product Development, BI-A
E: [email protected]
M: 650-269-7902



-----Original Message-----
From: [email protected] <[email protected]> 
Sent: Sunday, May 3, 2020 8:36 AM
To: [email protected]
Subject: Can JEXL expression invoke call my own method (and if so how)?

Hi,

I am new here, and we are using another Apache "product" (Syncope) that 
supports JEXL.  We have a need to have a JEXL expression that calls our own 
method, and I was wondering (a) does JEXL support that capability, and (b) if 
so, how do we accomplish that?

Some background:  Syncope supports using JEXL to provide what they call 
"derived attributes", i.e., where we can have a JEXL expression to construct an 
dynamically-constructed attribute from other attributes. 

However in our case, we have some custom Java methods (e.g., "extractField1()") 
to extract some information from an attribute, so we want to have a derived 
attribute that is constructed by a JEXPL expression, something like

my_derived_attribute = incoming_attribute.extractField1()

Is that something that JEXL supports?

And, if so, what do we have to do to make that extractField1() method available 
to JEXL?  Do we just put that method (actually we have several different 
methods) and make the class that the methods are in on the classpath?  

Thanks!!

Jim

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to