Hi everyone, I'm pretty new to Jboss so I hope my questions isn't too stupid..

In the project Im currently in, I need to load classes stored in separate
.jar-files with the same name, sharing a common interface. To accomplish this in
Jboss I've made a simple session bean with an ordinary method containing the
logic. The problem is that I cannot cast my implementation to the common
interface in Jboss since they are loaded by different classloaders or instances
of the same classLoader. (i.e. UnifiedClassLoader). The best way would be to
"import myPackage.Shape" (Shape is the interface) and then using the default
Jboss classloader to:

Class impl = Class.forName("ShapeUser.Shapes." + name); //Loads the implementation
                                                        //with default ClassLoader
Shape _interface = (Shape)impl.newInstance(); // Casts impl to interface

But this doesn't work since my .jar file holding the implementation must be
loaded from an URL outside of the Jboss default namespace. If I define my own
instance of UnifiedClassLoader with a correct URL it loads the class fine, but
then cannot cast it to the interface since they are loaded by different
classloader instances. (In a stand-alone application this works just fine BTW
since they use the same CL-instance)

Using getMethod() and invoke(x,x) on the impl isn't an option BTW. My final
approach is to load both the interface and impl with the same classloader at
runtime, but then I don't have a clue if it's possible to cast "Class impl" to
"Class interface" at the corresponding line: (????????)

UnifiedClassLoader classLoader = new UnifiedClassLoader(myURL, repository);
Class impl = Class.forName("ShapeUser.Shapes." + name, true, classLoader);
Class interface = Class.forName("ShapeUser.Shape",true,classLoader);       
???????? Shape shp = (Shape)c.newInstance(); // HOW???

I guess the last issue isn't exactly Jboss-related but I hope you can oversee
that. I'd be really grateful for any suggestions on how I can accomplish the
main task of dynamic classloading and casting to a common interface in Jboss.

Regards Erik Lupander


-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to