That is the trick - but I don't think it is perfect. It should find
the META_INF/services that that classloader can see - but in Eclipse
3.4 they locked it down so you could not see across different
classloaders (except for specific packages that had been made visible)
- since the check was at the package level there was no way to allow
META-INF/services a get out of jail free card. So I think it will work
for a single classloader; but not all the parent classloaders.
Specifically I think the trick get's us into the "geotools"
classloader and then hopes for the best.
You will see that some of the factory FactoryRegistry.getClassLoaders
() method has some similar logic; I think this is what we are abusing
with the setContextClassLoader method.
Jody
On 17/09/2009, at 1:24 PM, Gabriel Roldan wrote:
hey, thanks for the insight.
So, before I mess-code, let me double check. What you're saying is
that I could just do:
ClassLoader orig = Thread.currentThread().getContextClassLoader();
try{
Thread.currentThread().setContextClassLoader(<Factory class to be
looked up>.class.getClassLoader());
... do lookup ...
}finally{
Thread.currentThread().setContextClassLoader(orig);
}
and that would be it, it will even find META-INF/services?
I guess "<Factory class to be looked up>" might actually be any
class in the same jar?
Cheers,
Gabriel
Jody Garnett wrote:
We have a trick in uDig where we look up a class; find its
classloader; switch the thread to that classloader; make the call
that uses factory spi; and then restore the thead its previous
classloader.
Jody
don't have much spare time to devote to 2.5.
As a bonus, if you can switch to 2.6 I'll be happy to figure out a
way
for you to impose a classloader to the spi.
--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users