|
From: Bill W. <wp...@gm...> - 2005-12-08 16:16:13
|
Good morning, I'm using Jython 2.2a1 to do some client-side testing of a J2EE application on a somewhat more obscure J2EE application server. In Jython, I am able to obtain an object from JNDI and call methods on it in Jython, very nicely, thank you very much. However, when I try to turn that Jython code into some server-side Java code, I'm running into a problem. In Jython, I can look at the class (using "<object name>.__class__"), as well as getting method and variable information about the class (using "dir(<object name>.__class__)"), but the actual Java class that is listed is an 'Impl' class. In order to use this object in Java, I need to know what interface to cast it to. The application server is not well documented in this area, and I'm having trouble finding out what the Java interface is.=20 Is there any way in Jython to obtain the interface(s) that class implements? Or should I use the Java reflection classes to get it? TIA, - Bill -- Bill Woodward wp...@sa... http://www.saifa.net "I have more trouble with D. L. Moody than with any other man I ever met." -- D. L. Moody s/D. L. Moody/Bill Woodward/g |
|
From: Victor A. <an...@bo...> - 2005-12-08 16:42:50
|
On Thu, Dec 08, 2005 at 10:15:59AM -0600, Bill Woodward wrote:
> Good morning,
>
> I'm using Jython 2.2a1 to do some client-side testing of a J2EE
> application on a somewhat more obscure J2EE application server. In
> Jython, I am able to obtain an object from JNDI and call methods on it
> in Jython, very nicely, thank you very much. However, when I try to
> turn that Jython code into some server-side Java code, I'm running
> into a problem. In Jython, I can look at the class (using "<object
> name>.__class__"), as well as getting method and variable information
> about the class (using "dir(<object name>.__class__)"), but the actual
> Java class that is listed is an 'Impl' class.
>
> In order to use this object in Java, I need to know what interface to
> cast it to. The application server is not well documented in this
> area, and I'm having trouble finding out what the Java interface is.
> Is there any way in Jython to obtain the interface(s) that class
> implements? Or should I use the Java reflection classes to get it?
>
I am not sure about the possibilities to use jython for that task, but I
would do this with reflection classes...
--
Victor Anyakin () ascii ribbon campaign
/\ - against html mail
|
|
From: Bill W. <wp...@gm...> - 2005-12-08 16:44:32
|
---------- Forwarded message ---------- From: Helio R. Zwi <hz...@co...> Date: Dec 8, 2005 10:38 AM Subject: Re: [Jython-users] Getting Java interface information from a Java class in Jython To: Bill Woodward <wp...@gm...> Use <object name>.__class__.__bases__ (or <any_class_name>.__bases__) It is the list of superclasses for the given class. If the given class is a Java class (no multiple inheritance allowed), one of the elements is the actual superclass (always __bases__[0], as far as I can tell), and the remaining (if any), the superinterfaces. You can use it "recursively", e.g.: >>> java.lang.StringBuffer.__bases__[0] <jclass java.lang.AbstractStringBuilder at 25822411> >>> java.lang.StringBuffer.__bases__[0].__bases__[0] <jclass java.lang.Object at 13059400> >>> java.lang.StringBuffer.__bases__[1] <jclass java.io.Serializable at 25392329> >>> java.lang.StringBuffer.__bases__[2] <jclass java.lang.CharSequence at 5791657> >>> Helio Bill Woodward wrote: >Good morning, > >I'm using Jython 2.2a1 to do some client-side testing of a J2EE >application on a somewhat more obscure J2EE application server. In >Jython, I am able to obtain an object from JNDI and call methods on it >in Jython, very nicely, thank you very much. However, when I try to >turn that Jython code into some server-side Java code, I'm running >into a problem. In Jython, I can look at the class (using "<object >name>.__class__"), as well as getting method and variable information >about the class (using "dir(<object name>.__class__)"), but the actual >Java class that is listed is an 'Impl' class. > >In order to use this object in Java, I need to know what interface to >cast it to. The application server is not well documented in this >area, and I'm having trouble finding out what the Java interface is. >Is there any way in Jython to obtain the interface(s) that class >implements? Or should I use the Java reflection classes to get it? > >TIA, >- Bill > >-- >Bill Woodward wp...@sa... http://www.saifa.net > >"I have more trouble with D. L. Moody than with any other man I ever >met." -- D. L. Moody > s/D. L. Moody/Bill Woodward/g > > >------------------------------------------------------- >This SF.net email is sponsored by: Splunk Inc. Do you grep through log fil= es >for problems? Stop! Download the new AJAX search engine that makes >searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! >http://ads.osdn.com/?ad_idv37&alloc_id=16865&op=3Dclick >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users > > > -- Bill Woodward wp...@sa... http://www.saifa.net "I have more trouble with D. L. Moody than with any other man I ever met." -- D. L. Moody s/D. L. Moody/Bill Woodward/g |
|
From: Bill W. <wp...@gm...> - 2005-12-08 16:47:00
|
On 12/8/05, Bill Woodward <wp...@gm...> wrote: > > In order to use this object in Java, I need to know what interface to > cast it to. The application server is not well documented in this > area, and I'm having trouble finding out what the Java interface is. > Is there any way in Jython to obtain the interface(s) that class > implements? Or should I use the Java reflection classes to get it? > Wow! Thanks everyone for the quick help. I was able to find the interface via the reflection API. Helio's pythonic solution looks good, too, although I haven't tried it out. Thanks again, - Bill -- Bill Woodward wp...@sa... http://www.saifa.net "I have more trouble with D. L. Moody than with any other man I ever met." -- D. L. Moody s/D. L. Moody/Bill Woodward/g |
|
From: Jeff E. <jem...@fr...> - 2005-12-08 17:19:27
|
If I have a reference to a java object, I often issue these sorts of commands. They are a cross between Python and Java reflection and a bit quicker to type than the raw reflection API. dir(obj.class) dir(obj.class.superclass) obj.class.interfaces dir(obj.class.interfaces[1]) obj.class.declaredMethods obj.class.someMethod.argslist obj.class.interfaces[1].anotherMethod.argslist[0].data Bill Woodward wrote: > Good morning, > > I'm using Jython 2.2a1 to do some client-side testing of a J2EE > application on a somewhat more obscure J2EE application server. In > Jython, I am able to obtain an object from JNDI and call methods on it > in Jython, very nicely, thank you very much. However, when I try to > turn that Jython code into some server-side Java code, I'm running > into a problem. In Jython, I can look at the class (using "<object > name>.__class__"), as well as getting method and variable information > about the class (using "dir(<object name>.__class__)"), but the actual > Java class that is listed is an 'Impl' class. > > In order to use this object in Java, I need to know what interface to > cast it to. The application server is not well documented in this > area, and I'm having trouble finding out what the Java interface is. > Is there any way in Jython to obtain the interface(s) that class > implements? Or should I use the Java reflection classes to get it? > > TIA, > - Bill > > -- > Bill Woodward wp...@sa... http://www.saifa.net > > "I have more trouble with D. L. Moody than with any other man I ever > met." -- D. L. Moody > s/D. L. Moody/Bill Woodward/g > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_idv37&alloc_id865&op=click > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |