Ahem ....
   having spent the last two days doing purely Java stuff my fingers got ahead of me:
What I _meant_ to write was ...
class PyFoo(FooBean):
    _i = 0
    def setFoo(self, i):
        self._i = i
    def getFoo(self):
        return self._i
Is it just me, or is the hardest part of Jython keeping the two languages straight ..... ???
-----Original Message-----
From: jython-users-admin@lists.sourceforge.net [mailto:jython-users-admin@lists.sourceforge.net]On Behalf Of Alan Littleford
Sent: Tuesday, July 02, 2002 2:30 PM
To: Phil Surette; 'Nick Collier'; jython-users@lists.sourceforge.net
Subject: RE: [Jython-users] reflection / property question

   I have found the easiest way to make Jython classes 'look' like Java classes is to have them inherit
a Java interface describing what you would expect to see in Java. So if you have
interface FooBean {
    public void setFoo(int i);
   public int getFoo();
class PyFoo(FooBean):
    _i = 0
    def setFoo(i):
        self._i = i
    def getFoo()
        return self._i
then if you have a reference to a PyFoo() in java you can treat it just as you would expect from within Java
  -----Original Message-----
From: jython-users-admin@lists.sourceforge.net [mailto:jython-users-admin@lists.sourceforge.net]On Behalf Of Phil Surette
Sent: Tuesday, July 02, 2002 11:46 AM
To: 'Nick Collier'; jython-users@lists.sourceforge.net
Subject: RE: [Jython-users] reflection / property question

I was poking around with this sort of stuff a while ago
so I could write ant tasks in jython.

As far as I can tell, there is no easy way to make
a jython class look like a java bean. In general, jython
is great at making java classes look like python classes,
but jython classes don't look like java classes.

If someone knows a trick for doing this (other than
jythonc), I'd love to know it.

Maybe some
unholy combination of java.lang.reflect.Proxy and
java.util.BeanInfo be used to proxy through
to a jython class and adapt it to meet the javabeans
spec? Except that a Proxy must implement
some predefined interfaces...

-----Original Message-----
From: Nick Collier [mailto:nick.collier@verizon.net]
Sent: Wednesday, June 26, 2002 12:11 PM
To: jython-users@lists.sourceforge.net
Subject: [Jython-users] reflection / property question


Some background. I'm working with the repast simulation framework for
creating agent based simulations. Typically you write your model in
java, "load" it into repast and off it goes. Repast identifies and
displays a models starting parameters by calling getInitParam on the
model which returns a list of property names. (These are standard bean
like properties where the presence of a get / set accesor method
identifies a property. So, getVal and/or setVal "defines" the val
property.) Repast takes this list of property names uses reflection to
go find the appropriate methods in the model. So a property name of
"val" makes repast look for a getVal and a setVal.

What I'd like to be able to do is to write the models in jython.
Everything seems to work fine as far as subclassing the repast base
models with my jython code. However, although repast does call the
appropriate method and receive the list of property names, it can't find
the get/set accessor methods in my jython model. Short of compiling the
jython into java and using the "@sig" comments, is there any way to get
this kind of bean property reflection working on the jython side.



Nick Collier
Social Science Research Computing
University of Chicago

This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
Jython-users mailing list