This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Visibility across classloaders?
Posted by Wayne Stidolph on July 04, 2000 at 10:30 PM
I am wondering about good design approaches to "exporting" an interface from one classloader into another, all in the same JVM. Suppose I want to have a Class "A_impl" which implements interface "A" and a class B that uses an A_impl object found in a JNDI namespace. The ideal code in B is something like: A myA = (A)context.lookup("theObj"); Is there a way tomake this work if A and A_impl are defined by user Classloader "ACL" and B is defined by user Classloader BCL, and there is no parent-child relationship between ACL and BCL? The problem is that the code in B uses BCL, so using "A" fails. Adding A.class to be loaded by BCL as well as ACL doesn't work; gets an invalid class cast exception (I think the object "theObj" hold the reference backs to its defining classloader and the cast is to an A defined under BCL, so they don't match, right?) Is there a way to mark BCL as an "initiating" Classloader to get access to the ACL "A" interface - and to do this for *only* the "A" interface, not to any other information? Clearly a parent can be inserted above ACL and BCL to share "A" but this has a lot of other drawbacks for what I'm trying to do. Any other ideas on creating sibling partial-exposure relationships between Classloaders? Wayne
Replies:
|