You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by oh...@yahoo.com.INVALID on 2020/05/03 15:35:35 UTC

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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Can JEXL expression invoke call my own method (and if so how)?

Posted by henrib <he...@apache.org>.
Hi;
I know nothing about Syncope (besides skimming the nice doc) but I suspect
you can not add your own JEXL namespace easily. For JEXL to be able to call
a method, it 'only' needs to be a public method of an accessible public
class. In your case, derived attributes being expression on 'plain schema
type', I suspect the incoming_attribute is not an instance of your class.
One possibility is to instantiate your own 'functor' class with JEXLs 'new'
operator; assuming your public class fqcn is 'my.syncopex.functor' with a
public constructor accepting a string as argument (your incoming attribute)
and a 'derive' method (that will compute the derived value), you may be able
to use an expression like:
{code}
new('my.syncopex.functor', incoming_attribute).derive()
{code}
Let us know how it goes.
Cheers



--
Sent from: http://apache-commons.680414.n4.nabble.com/Commons-User-f735979.html

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


RE: Can JEXL expression invoke call my own method (and if so how)?

Posted by "Greenberg, Gary" <gg...@visa.com.INVALID>.
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: ggreenbe@visa.com
M: 650-269-7902



-----Original Message-----
From: ohaya@yahoo.com.INVALID <oh...@yahoo.com.INVALID> 
Sent: Sunday, May 3, 2020 8:36 AM
To: user@commons.apache.org
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org