Help needed to Intercept and overide getter and setter method calls
"Jp Vinjamoori" <[email protected]>
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi All,
I have a weird requirement and pretty new to bean shell (I have been playing
with it for couple of days)
I am having the following code.
------------------------------------------------------
import java.util.Properties;
import bsh.EvalError;
import bsh.Interpreter;
public class PropertyTest {
public static void main(String[] args) throws EvalError {
Properties property = new Properties();
property.put("value1", new Integer(2));
property.put("value2", new Integer(3));
property.put("value2", new Integer(0));
Interpreter i = new Interpreter(); // Construct an interpreter
i.set("property", property);
i.eval("property.value3 = property.value2 * property.value1;");
// I want to intercept the calls to Properties getter and setter
values and call the Property.get("value1") etc
// Can I do it? If yes, please tell me.
//The following line should print 6
System.out.println("The value3:" + property.get("value3"));
}
}
------------------------------------------------------
Basically, what I want is to intercept the getter and setter called by bean
shell and translate it to properties.get("value1") or
properties.get("value2") or properties.set("value3", value)
Is it possible? How would I go about it.
One option I figured out is to create commands for set and get and use it to
set and get values. But the expression would have to change it to some thing
like
set(property, get(property, "value2") * get(property, "value1"));
But my requirement is to let the user define it as in code above
["property.value3 = property.value2 * property.value1;"]. Please help.
Thanks in advance,
_Jp
_________________________________________________________________
Concerned that messages may bounce because your Hotmail account is over
limit? Get Hotmail Extra Storage! http://join.msn.com/?PAGE=features/es
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/