dynamic variable:
比如说我想用variable "varA". The word "varA" retrieved from database, how
can I use this word to get the variable value? 我现在想的是建一个lookup.
dynamic functions:
比如说我想trim一个variable. The word ".trim()" retrieved from
database, "" will be replaced by real variable and ".trim()" will be
excuted, how can I do that?
Thanks
g*****g 发帖数: 34805
2
Java Reflection
be
【在 B*****g 的大作中提到】 : dynamic variable: : 比如说我想用variable "varA". The word "varA" retrieved from database, how : can I use this word to get the variable value? 我现在想的是建一个lookup. : dynamic functions: : 比如说我想trim一个variable. The word ".trim()" retrieved from : database, "" will be replaced by real variable and ".trim()" will be : excuted, how can I do that? : Thanks
A**o 发帖数: 1550
3
How about the scripting ability added since JDK 6? It might work here, too.
But i have no experience on it.
c*****t 发帖数: 1879
4
It is nothing more than an equivalent of BSF framework.
.
【在 A**o 的大作中提到】 : How about the scripting ability added since JDK 6? It might work here, too. : But i have no experience on it.
s******e 发帖数: 493
5
How can you do it in java reflection?
I am not sure if you can do it in a pure java way with java 1.6 scripting
engine either.
For either way, it will be interesting to see a working example.
c*****t 发帖数: 1879
6
LZ is not concrete enough. So there won't be concrete example either :P
【在 s******e 的大作中提到】 : How can you do it in java reflection? : I am not sure if you can do it in a pure java way with java 1.6 scripting : engine either. : For either way, it will be interesting to see a working example.
s******e 发帖数: 493
7
not concrete enough?
I believe that even the poster title is good enough for you to come with a
sample.
The dynamic variable and dynamic functions are common features in emacscript
based language such as .js and .as but it is extemely hard to any strong
typed object oriented language. personally i do not see any way you can do
it in java reflection. even with jsr223,
you might still have a trouble to do it.
g*****g 发帖数: 34805
8
Think of Spring IoC declared in XML.
You declare a class name, a method name, and you can invoke the method.
Something like
Class> c = Class.forName(yourClassName);
Object o = c.newInstance();
Method method = c.getDeclaredMethod(yourMethod);
method.invoke(o);
You probably want to have a constructor passing in a String parameter,
something we've seen in spring IoC too.
I believe OP's problem can be resolved in a similar way, although he
may need to format his string in DB with more type details
【在 s******e 的大作中提到】 : not concrete enough? : I believe that even the poster title is good enough for you to come with a : sample. : The dynamic variable and dynamic functions are common features in emacscript : based language such as .js and .as but it is extemely hard to any strong : typed object oriented language. personally i do not see any way you can do : it in java reflection. even with jsr223, : you might still have a trouble to do it.
s******e 发帖数: 493
9
You misunderstood what dynamic variable and dynamic functions mean. they are
not someting that preexist at the compiling time.
both js ans as allow you to define a new memeber of class on the fly.
.for example, adding a new variable/function to a class at run time.
g*****g 发帖数: 34805
10
How you want to coin the names is not that important. The OP wants
to call some function by parsing a string from DB. And Spring IoC
is a perfect example for that. If you want to add new variable/function,
look at AspectJ.
are
【在 s******e 的大作中提到】 : You misunderstood what dynamic variable and dynamic functions mean. they are : not someting that preexist at the compiling time. : both js ans as allow you to define a new memeber of class on the fly. : .for example, adding a new variable/function to a class at run time.
I would go with an embedded scripting language too.
Groovy or jruby are both good choices here, as they closely
resemble java syntax.
【在 c*****t 的大作中提到】 : It is nothing more than an equivalent of BSF framework. : : .
F****n 发帖数: 3271
12
Mozilla Rhino Javascript. You can hack into it quite deep.
【在 m******t 的大作中提到】 : : I would go with an embedded scripting language too. : Groovy or jruby are both good choices here, as they closely : resemble java syntax.
c*****t 发帖数: 1879
13
BeanShell is actually even better :P Zero learning curves.
【在 m******t 的大作中提到】 : : I would go with an embedded scripting language too. : Groovy or jruby are both good choices here, as they closely : resemble java syntax.
c*****t 发帖数: 1879
14
Well, he wasn't specific enough in what he was trying to do. When he
mentions "dynamic variable", it makes me wonder why and where he would
use it.
emacscript
【在 s******e 的大作中提到】 : not concrete enough? : I believe that even the poster title is good enough for you to come with a : sample. : The dynamic variable and dynamic functions are common features in emacscript : based language such as .js and .as but it is extemely hard to any strong : typed object oriented language. personally i do not see any way you can do : it in java reflection. even with jsr223, : you might still have a trouble to do it.
s******e 发帖数: 493
15
Even many terms are vague in cs.
But these two are not vague at all when we talk about language. actually
they are one of the criteria to distinguish a type strong langauge and a
dynamic language.
aspectj by nature is just another layer of compilation. actually no aop has
ever brought dynamic variable and dynamic functions to the table.
dynamic variable and fuctions are very useful when you do not know what and
how many things you want your object to carry at compilation time.
m***i 发帖数: 2480
16
It should be something like eval() in python. did a little search, https://
eval.dev.java.net/ might be helpful.
be
【在 B*****g 的大作中提到】 : dynamic variable: : 比如说我想用variable "varA". The word "varA" retrieved from database, how : can I use this word to get the variable value? 我现在想的是建一个lookup. : dynamic functions: : 比如说我想trim一个variable. The word ".trim()" retrieved from : database, "" will be replaced by real variable and ".trim()" will be : excuted, how can I do that? : Thanks
m******t 发帖数: 2416
17
Very true. I used to use a lot of beanshell, even
embedding it in a web app as an admin console.
The active development on it seems to have stopped though.
【在 c*****t 的大作中提到】 : BeanShell is actually even better :P Zero learning curves.
m******t 发帖数: 2416
18
There is this design approach to implement validation
logic in javascript, and run it once on client side, then again
on server side with rhino. Very interesting idea, I thought.
【在 F****n 的大作中提到】 : Mozilla Rhino Javascript. You can hack into it quite deep.
c*****t 发帖数: 1879
19
Why do you need "active" development anyways? It has already fullfilled
its purposes.
【在 m******t 的大作中提到】 : : There is this design approach to implement validation : logic in javascript, and run it once on client side, then again : on server side with rhino. Very interesting idea, I thought.
m******t 发帖数: 2416
20
I personally don't have problems with that. I'm just saying that
it might be a concern for some projects, especially when the latest
version released is nominally a beta.
【在 c*****t 的大作中提到】 : Why do you need "active" development anyways? It has already fullfilled : its purposes.
f + l is just an example.
Real world can be complicate.
Like first remove special characters from f and l, then trim them, then get
first 20 characters, then trim again, then uppercase.
More complicate example may involve if/else
You must first know what the expression language is. If you don't know, then
there's no solution.
get
【在 B*****g 的大作中提到】 : f + l is just an example. : Real world can be complicate. : Like first remove special characters from f and l, then trim them, then get : first 20 characters, then trim again, then uppercase. : More complicate example may involve if/else
s******e 发帖数: 493
32
if so, even dynamic functions are not enough. Dynamic functions are not real
dynamic, you still need to code them in your code base.
what you need is either using db or xml file or any format file to act as a
configuration file, treating your first name as operand one, and last name
as operand two (if you are sure that you will only have two operands, and
they will be stored in columns that you know ahead. Otherwise if even the
operands are unknown at compilation time, it will be way too compli
s******e 发帖数: 493
33
just have thought, you may be able to take advantage of jdk 1.6 with mozilla
rhino(the only built-in Jscript implemntation support in hotspot)
for example you have a formula (op1 * 13 - op2)/13 *op2, you store in
formula in db or xml, because java new script engine allows you to define
your js function in java, you can just simply replace op1 and op2 at run
time, and send the defined function to js engine. this way you just take
advantage of exsiting js engine parser and interpreter. You do not
B*****g 发帖数: 34098
34
this one I decide. I want to do it in java
then
【在 F****n 的大作中提到】 : You must first know what the expression language is. If you don't know, then : there's no solution. : : get
B*****g 发帖数: 34098
35
Solution storing data in columns (no matter is physical or logical) has been
turned down by my manager.
Solution use pl/sql as script language for all operations is also turned
down.
That is why I ask here.
My manager asked " why can not you do it in java?"
I am new to java, his is pre^10-new
real
a
name
used
【在 s******e 的大作中提到】 : if so, even dynamic functions are not enough. Dynamic functions are not real : dynamic, you still need to code them in your code base. : what you need is either using db or xml file or any format file to act as a : configuration file, treating your first name as operand one, and last name : as operand two (if you are sure that you will only have two operands, and : they will be stored in columns that you know ahead. Otherwise if even the : operands are unknown at compilation time, it will be way too compli
c*****t 发帖数: 1879
36
你没这方面的知识。没戏。
【在 B*****g 的大作中提到】 : this one I decide. I want to do it in java : : then
【在 B*****g 的大作中提到】 : Solution storing data in columns (no matter is physical or logical) has been : turned down by my manager. : Solution use pl/sql as script language for all operations is also turned : down. : That is why I ask here. : My manager asked " why can not you do it in java?" : I am new to java, his is pre^10-new : : real : a
Use script with customized context. People do that kind of things all the
time. You can either use Rhino (then the expression is officially javascript
, not java), or use BeanShell.