Jeff and I have been discussing this off-list; I figured I'd send the
discussion back to the list.
-- John
----- Forwarded message from John Goerzen <jgo...@co...> -----
X-Addr-Extension: sent-mail
To: Jeff Emanuel <je...@ad...>
Subject: Re: [Jython-users] tojava() failing
From: John Goerzen <jgo...@co...>
OK. I did:
System.out.println(this.getClass().getClassLoader().getClass().getName());
System.out.println(newobj.getClass().getClassLoader().getClass().getName());
Resulting in:
com.lutris.classloader.MultiClassLoader
org.python.core.BytecodeLoader1
MultiClassLoader is a subclass of java.lang.ClassLoader adding in
functionality such as loading classes from URLs, ZIPs, etc. (This is
an Enhydra servlet).
Interestingly, this is JDK 2 but it's using Jython's JDK 1
BytecodeLoader.
Let me show you exactly what I'm trying to do:
In Java: (before adding the printlns and other debug stuff)
PythonInterpreter interp = new PythonInterpreter();
interp.exec("mod = __import__('" + brob + "')");
interp.exec("cl = mod." + brob + "()");
Object newobj = interp.get("cl", Object.class);
return (ListBO) newobj;
In this case, 'brob' is ListBOFoo, and it's loading this Python code:
from quovix.business.util import *
class ListBOFoo(ListBO):
def getDescription(self):
desc = ListBO.getDescription(self) # Superclass call
return "Foo_" + desc
Very simple stuff. I have it working with jythonc but I'm trying to
eliminate jythonc from the picture so it can be loaded 100%
dynamically.
Thanks for your assistance!
-- John
Jeff Emanuel <je...@ad...> writes:
> The java class Class has a method to return its ClassLoader.
> You can do something like this:
>
> System.out.println(this.getClass().getClassLoader());
> System.out.println(newobj.getClass().getClassLoader());
>
> If they are different, the classes are in effect not equal.
> I'm not sure why that would be or how to work around it. I've
> done things as you are trying and it worked. If we know
> what the classloaders are, perhaps we can discover why they
> are different, or what action to take.
>
> You can also try newobj.getClass().isAssignableFrom(this.getClass())
>
> That is likely to be false since you know you can't do the cast.
>
>
>
> John Goerzen wrote:
>
> > Jeff Emanuel <je...@ad...> writes:
> >
>
> >>It is likely that your ListBO class was loaded by two different class
> >>loaders. Try printing out the classloaders for your Java this instance
> >>and your newobj. Even if the classes are the same, if they were loaded
> >>by different loaders, then they really aren't equal.
> >>
> > OK this is unfamiliar territory for me. I don't know what a class
>
> > loader is or how to print it. If the loaders are different, how would
> > I go about resolving the problem? One is the regular static stuff
> > loaded as usual with classes generated by javac; the other, Python.
> > Ideas?
> > Thanks!
>
> > -- John
>
> >
>
>
>
--
John Goerzen <jgo...@co...> GPG: 0x8A1D9A1F www.complete.org
----- End forwarded message -----
|