From: Oti <oh...@ya...> - 2002-08-18 08:23:27
|
[ Orengo, Michel ] > Here is more details: > I have something like: <snipped> > Because "Client" defines a method "getPK", I believe jython tries to > get a > property "PK" on a instance of "Client" where I would like to get the > inner > class "PK", as I do with "WebUser" > I was wondering if there is a trick to direct jython not to use > javabean > properties. Hello Michel, you can use reflection to get at the Client.PK class: package CH.obj.Libraries.Utility; public abstract class Entity { protected Entity.PK _entityPK = null; public PK getPrimaryKey() { return null; } public static abstract class PK { } } package CH.obj.Test; import CH.obj.Libraries.Utility.Entity; public class Client extends Entity { protected Client() {} public static class PK extends Entity.PK { public long _clientId; public PK( long clientId ) { _clientId = clientId; } } public Client.PK getPK() { return null; } } package CH.obj.Test; import CH.obj.Libraries.Utility.Entity; public class WebUser extends Entity { protected WebUser() {} public static class PK extends Entity.PK { public long _userId; public PK( long userId ) { _userId = userId; } } } Jython 2.1 on java1.3.0 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> from CH.obj.Test import WebUser >>> from CH.obj.Test import Client >>> WebUser.PK <jclass CH.obj.Test.WebUser.PK at 8000886> >>> classes = Client.getClasses() >>> for c in classes: ... print c ... CH.obj.Test.Client.PK CH.obj.Libraries.Utility.Entity.PK >>> classes[0] <jclass CH.obj.Test.Client.PK at 7100506> >>> Best wishes, Oti. __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com |
From: Orengo, M. <Michel.Orengo@AIG.com> - 2002-08-16 14:12:39
|
Oti, Here is more details: I have something like: public abstract class Entity { protected Entity.PK _entityPK = null; public PK getPrimaryKey () {...} public static abstract class PK implements java.io.Serializable {...} public class Client extends com.aig.ebrs.tc.entity.Entity protected Client () {} public static class PK extends Entity.PK { public long clientId; public PK ( long clientId ) { this.clientId = clientId; } [...] } [...] public Client.PK getPK () { return (Client.PK) getPrimaryKey (); } public class WebUser extends com.aig.ebrs.tc.entity.Entity protected WebUser () {} public static class PK extends Entity.PK { public long userId; public PK ( long userId ) { this.userId = userId; } [...] } So if I import these above classes and I do: >>> WebUser.PK <jclass com.aig.ebrs.tc.entity.WebUser.PK at 2920795> >>> Client.PK Traceback (innermost last): File "<console>", line 1, in ? AttributeError: instance attr: PK Because "Client" defines a method "getPK", I believe jython tries to get a property "PK" on a instance of "Client" where I would like to get the inner class "PK", as I do with "WebUser" I was wondering if there is a trick to direct jython not to use javabean properties. Hope the above is clear. Thanks for your help. Michel -----Original Message----- From: Oti [mailto:oh...@ya...] Sent: Saturday, August 10, 2002 6:47 AM To: Orengo, Michel; 'jyt...@li...' Subject: Re: [Jython-dev] Issue with Javabean properties [ Orengo, Michel ] > I use Jython to test some Java code we are developing. One class "A" > defines a inner class called "PK", but has also a method called > "getPK". When Jython tries to access A.PK it returns an exception > because it tries to > get an attribute PK for an instance of A (the property generated > automatically using the JavaBean Introspector) > Is there a way to have Jython getting the inner class instead? Hello Michel, from your explanation it is not completely clear (at least to me) how your classes relate and what you are trying to do in jython. Could you give a short example ? Oti. __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com |
From: Orengo, M. <Michel.Orengo@AIG.com> - 2002-08-19 21:12:14
|
Thanks. It worked! -----Original Message----- From: Oti [mailto:oh...@ya...] Sent: Sunday, August 18, 2002 4:23 AM To: Orengo, Michel; 'jyt...@li...' Subject: RE: [Jython-dev] Issue with Javabean properties [ Orengo, Michel ] > Here is more details: > I have something like: <snipped> > Because "Client" defines a method "getPK", I believe jython tries to > get a property "PK" on a instance of "Client" where I would like to > get the inner > class "PK", as I do with "WebUser" > I was wondering if there is a trick to direct jython not to use > javabean > properties. Hello Michel, you can use reflection to get at the Client.PK class: package CH.obj.Libraries.Utility; public abstract class Entity { protected Entity.PK _entityPK = null; public PK getPrimaryKey() { return null; } public static abstract class PK { } } package CH.obj.Test; import CH.obj.Libraries.Utility.Entity; public class Client extends Entity { protected Client() {} public static class PK extends Entity.PK { public long _clientId; public PK( long clientId ) { _clientId = clientId; } } public Client.PK getPK() { return null; } } package CH.obj.Test; import CH.obj.Libraries.Utility.Entity; public class WebUser extends Entity { protected WebUser() {} public static class PK extends Entity.PK { public long _userId; public PK( long userId ) { _userId = userId; } } } Jython 2.1 on java1.3.0 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> from CH.obj.Test import WebUser >>> from CH.obj.Test import Client >>> WebUser.PK <jclass CH.obj.Test.WebUser.PK at 8000886> >>> classes = Client.getClasses() >>> for c in classes: ... print c ... CH.obj.Test.Client.PK CH.obj.Libraries.Utility.Entity.PK >>> classes[0] <jclass CH.obj.Test.Client.PK at 7100506> >>> Best wishes, Oti. __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com |