Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little suggestion about user-defined functions #1

Closed
GoogleCodeExporter opened this issue May 1, 2015 · 4 comments
Closed

A little suggestion about user-defined functions #1

GoogleCodeExporter opened this issue May 1, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Thank u for the great job on Ik-e and it is easy to use in our projects!

But when using I found a problem that the user-defined functions ik-e 
supported were construted when system starts. So we cann't use the spring-
managed beans and it's hard to inject other beans(like httprequest ...) 
into the functions. That means the  user-defined functions ik-e supported 
are more like Toolkit beans than business beans.

To resolve this problem, I use a ugly way: add a static attribute into 
ExpressionEvaluator ,add synchronized block in evaluate method and inject 
it to function object everytime it is to be invoked. 

So my suggestion is if you can change the function's init and invoking 
method, let function object more extensible so user can manage it by 
ourself? 

After all, thanks again for your great job, it's helpful!

Best wishes

Original issue reported on code.google.com by chenb...@gmail.com on 5 May 2009 at 3:41

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author


很高兴,有大牛能给IK-E提出建议。我的E文水平只够看,不够
写哈,所以就用中文给你回复吧,
呵呵!
实际上在IK-E中有两种方法解决您提到的问题:
一种是用org.wltea.expression.function.FunctionLoader这个类中的方法

public static void addFunction(String functionName, Object instance, Method 
method)

在运行时传入对象的实例、java方法实例以及映射的函数名称�
��添加自定义函数(ps:很不好意
思,文档做的不够细,漏了这个API的说明呵呵)

第二种方法,通过ThreadLocal的线程本地变量,可以将您自己声
明的类实例(包括任意的外部参
数)传入到自定义的Function中(在执行表达式前声明一个Thread
Local,将参数传入,并在表达
式中的自定义方法执行时,从ThreadLocal中取出即可)。我自己
目前在做的一个项目中就采用了
这种方式,可以很容易的使用Map对象传入想要的参数。

最后,很感谢你的使用!:)

Original comment by linliang...@gmail.com on 11 May 2009 at 3:40

@GoogleCodeExporter
Copy link
Author

Original comment by linliang...@gmail.com on 24 Jul 2009 at 6:26

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Original comment by linliang...@gmail.com on 4 Dec 2009 at 2:00

  • Changed state: Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant