RE: Help needed to Intercept and overide getter and setter method calls
"White, John K" <JohnWhite-1VmriVQ4F2F8UrSeD/[email protected]>
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <2B5685BB89170947A53B9EDD0CA6276CEA4A2E@sdomsg00.corp.fairisaac.com> |
there's also the map access syntax:
map = new java.util.HashMap();
map{"key"} = "value";
but that's not as simple as "map.key = value;".
j.
> -----Original Message-----
> From: Shankar Unni [mailto:[email protected]]
> Sent: Tuesday, November 04, 2003 9:28 PM
> To: beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Subject: RE: [Beanshell-dev] Help needed to Intercept and
> overide getter and setter method calls
>
>
> > property.put("value1", new Integer(2));
> > property.put("value2", new Integer(3));
> > property.put("value2", new Integer(0));
>
> > 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
>
> Not directly, no. I, too, had the same idea for our
> integration with BeanShell (my product has objects that keep
> attributes in a simple hashmap, exactly like this).
>
> There is a way to do this without BeanShell code changes, but
> it's a bit
> painful: you use reflection to examine the list of keys in
> your map, and create a wrapper class on the fly with
> something like BCEL (Byte Code Engineering Library), like a
> proxy class, that you wrap your object with before passing to
> BeanShell. This wrapper would have getValue1(), etc., methods.
>
> But it would be nice if there was a simple hook or hooks in
> the field resolution code that could get invoked when a field
> resolution failed using the current mechanisms. Exactly like
> the "invoke()" mechanism already available for method resolution..
>
> (Actually, there would need to be two hooks along the lines of:
>
> Object getField(..., String fieldName);
> void setField(..., String fieldName, Object value);
>
> And the appropriate one would be invoked depending on whether
> an lvalue or an rvalue was required).
>
> What do you think, Pat?
>
>
>
>
> -------------------------------------------------------
> 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/
> _______________________________________________
> Beanshell-developers mailing list
> Beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-developers
>
-------------------------------------------------------
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/