Re: [Simpleweb-Support] ClassLoader and prepare() problems
Brought to you by:
niallg
From: Niall G. <gal...@ya...> - 2007-04-30 20:56:27
|
Hi, Seems to me that you must be giving either the MapperEngine or LoaderEngine a class path entry outside the class path of the object you are trying to cast. The registry delegates to a parent class loader, like so: ClassLoader parent = Registry.class.getClassLoader(); Thus if this parent delegates to the system classloader and the class you are using is in the classpath then you will not have the class cast exception. One thing to note is that if you dont provide a file or URL to the loader engine constructor it will use the Context.getBasePath(), perhaps this is where your issue is? Download the demo package, it should contain working code of the situation you describe. Niall ----- Original Message ---- From: Will Benton <wi...@cs...> To: sim...@li... Sent: Thursday, April 26, 2007 8:24:04 PM Subject: [Simpleweb-Support] ClassLoader and prepare() problems Hi all, I'm having some trouble with prepare() methods and ClassLoaders in an extremely minimal application. This application is a basic MVC database frontend with no static content. I'm using Simple 3.1.3 under Java 5 (with the Apple/Sun VM for now). I want to be able to store a reference to a controller object in each of my Service classes. If I declare the prepare() method to take the class of the controller object as a parameter, it will never be invoked. If, on the other hand, I declare the prepare method to take an Object and then cast, I'll get a ClassCastException. As far as I can tell, both of these happen because the Service is using a URLClassLoader that never delegates to the System class loader -- so the Class object for my controller class in the URLClassLoader is not equal to the one in the System class loader (which was in effect when I created the object that I passed to the prepare() method). I've scanned the source, but can't figure out how to get the behavior I want without changing simple.http.load.Registry, which seems like a bad plan. As a result, it seems to me that I must be going about this whole enterprise improperly. I'd greatly appreciate it if someone could either 1. provide some example code that passes objects created in a context using the system classloader to a Simple service, or 2. explain how to set up a LoaderEngine so that the Services it creates will have classloaders that will delegate to the system classloader. If I'm missing something even more fundamental, I'd be glad to hear that as well, of course. Thanks for reading this! best, wb ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Simpleweb-Support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simpleweb-support __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |