From: Samuele P. <ped...@bl...> - 2004-01-14 13:23:34
|
At 10:26 14.01.2004 +0100, Nicola de Candussio wrote: >It is possible to provide a workaround by introducing a jython class that >redirects __getattr__ to the __findattr__ of the java base class .. the >code at the end explains it better. >You maybe wondering what is all this exercise about ... we want to provide >to our internal user a framework to develop algorithms in java AND jython >with a common programming style, these algorithms will be eventually used >in jython. As part of this framework we provide a base class that >implements the template pattern and insure the certain operations (like >parameter checking ) are performed before the actual computation is run. >The signature of such algorithms is provided by a an HashMap where the >keys are the name of the parameters: these are the properties we would >like to give access to by redefing the __findattr__ method. > >But my real question at this moment is the following: >if you had to develop a java framework for the sake of the jython users >which features would you consider stable enough to rely on ?? I repeat, there is no real designed support for subclassing in/from Jython PyObject java subclasses at the moment. e is a naked proxy, which is something one should really never see on Jython side. When there will be such a support e.g. Property.__findattr__ will not be exposed. >########################################################## >// JAVA BASE class >import org.python.core.PyObject; > >public class Property extends PyObject { > PyObject property = null; > > public PyObject __findattr__(String key) { > return property; > } > > public final void __setattr__(String key, PyObject value) { > property = value; > } >} > ># JYTHON BASE class, inherits from Property >class JProperty(Property): > def __init__(self): > Property.__init__(self) > # > def __getattr__(self, name): > return Property.__findattr__(self, name) > # > def __setattr__(self, name, value): > return Property.__setattr__(self, name, value) > > ># jyhton sub class inherits from JProperty >class Example(JProperty): > # > def __init__(self): > JProperty.__init__(self) > # fine, I can set it ! > self.whatever = 3 > # fine !! > print self.whatever > > >e = Example() > ># fine I read it .. >print e.whatever > >########################################################## > > > >Samuele Pedroni wrote: > >>At 10:20 13.01.2004 -0600, Jeff Emanuel wrote: >> >>>If you change your Java class not to extend PyObject, >>>then your examples work. >> >>well in that case you get a mixin implementing __setattr__, >>but I don't see why it should work. >> >>>-----Original Message----- >>>From: Nicola de Candussio [mailto:nde...@rs...] >>>Sent: Tuesday, January 13, 2004 8:00 AM >>>To: Samuele Pedroni >>>Cc: jyt...@li... >>>Subject: Re: [Jython-users] Emulating Jython object attribute access >>>with a Java class >>> >>> >>>So I guess it is not recommended to provide Jython object attribute >>>access with a Java in the way suggested by the FAQ (maybe it should be >>>mentioned in the FAQ). >>>Is there any better way to do it? >>>More generally which kind of jython functionalities a java class can >>>safely implement ? >>>I think of all the methods that are mentioned in several books and >>>e-mails (__finditem__ etc& etc&) >>>Is there any official commitment about them ? >>> >>>Thanks in advance >>> >>>Nicola >>> >>> >>>Samuele Pedroni wrote: >>> >>> > At 13:52 13.01.2004 +0100, Nicola de Candussio wrote: >>> > >>> >> Hi all, >>> >> >>> >> I followed the instructions mentioned in the 5.2 point of the Jython >>> >> faq (Emulating Jython object attribute access with a Java class) and >>> >> redefined the __findattr__ method. >>> >> It worked just fine until .... I inherited the java class in a jython >>> >> one which gave me an unexpected result: the properties defined in the >>> >> java class are still accessible BUT only from outside the inherited >>> >> the jython class i.e. I cannot get the value of the attribute of the >>> >> base class within the inherited jython class ... nor by using the >>> >> notation self.property of by referring directly to the base class... >>> >> I include the code of the two classes >>> > >>> > >>> > there is no real designed support for subclassing PyObject subclasses. >>> > >>> > >>> > ------------------------------------------------------- >>> > This SF.net email is sponsored by: Perforce Software. >>> > Perforce is the Fast Software Configuration Management System offering >>> > advanced branching capabilities and atomic changes on 50+ platforms. >>> > Free Eval! http://www.perforce.com/perforce/loadprog.html >>> > _______________________________________________ >>> > Jython-users mailing list >>> > Jyt...@li... >>> > https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> >>> >>> >>> >>>------------------------------------------------------- >>>This SF.net email is sponsored by: Perforce Software. >>>Perforce is the Fast Software Configuration Management System offering >>>advanced branching capabilities and atomic changes on 50+ platforms. >>>Free Eval! http://www.perforce.com/perforce/loadprog.html >>>_______________________________________________ >>>Jython-users mailing list >>>Jyt...@li... >>>https://lists.sourceforge.net/lists/listinfo/jython-users >>> >>> >>>------------------------------------------------------- >>>This SF.net email is sponsored by: Perforce Software. >>>Perforce is the Fast Software Configuration Management System offering >>>advanced branching capabilities and atomic changes on 50+ platforms. >>>Free Eval! http://www.perforce.com/perforce/loadprog.html >>>_______________________________________________ >>>Jython-users mailing list >>>Jyt...@li... >>>https://lists.sourceforge.net/lists/listinfo/jython-users >> >> >> >> >>------------------------------------------------------- >>This SF.net email is sponsored by: Perforce Software. >>Perforce is the Fast Software Configuration Management System offering >>advanced branching capabilities and atomic changes on 50+ platforms. >>Free Eval! http://www.perforce.com/perforce/loadprog.html >>_______________________________________________ >>Jython-users mailing list >>Jyt...@li... >>https://lists.sourceforge.net/lists/listinfo/jython-users > > |