Here is an email, sent to me off-list, that has other solutions.

I confirmed that the first solution works but I didn't try the second since that creates a custom JAXB bundle that wouldn't work in the Felix Commons.

Thanks again for everyone's help on this.

Tim


zze-SEYVOZ Stephane RD-MAPS-GRE wrote:

Hi there, I've actually been working on XFire integration in Felix for a project at my university, and had an interest for it in the context of my internship at France Telecom R&D.

Here is what I would answer to the problem as it was described (quote below)

There are 2 different solutions (the first one I drop like this if you don't want to know the details, the second one I haven't used by contains the explanation of the problem) :

1) write this method call :
"Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());" in your application bundle (not the one containing JAXB) just before the method call of your application that calls internally JAXB.

This will force the current thread to use the classloader of your application bundle, that (I hope) contains an implementation of a factory or parser that JAXB wants to use. In fact, each bundle being run in a different classloader as you know, JAXB tries to find a parser or factory it hasn't got (this allows you to design the one you want) whereas you surely have an implementation of it in your application bundle. In the case it doesn't find it (through a config file or searching in the current class loader with something like a Class.forName), it falls back on the implementation of the people who wrote the API, for instance as it falls back on com.sun … it's Sun (well yes you knew it ^^)). And in your case it can't even find Sun's one too. The command I gave you may resolve the problem as all the loaded classes of both bundles will then be in the same classloader (whereas it's not the same with the normal behavior of bundles in Felix : one separated Thread per bundle).

When you're not in Felix, there's surely no problem because the class specified by the config file or that is in the JVM can be easily found as it's loaded in the unique classloader running your application.

2) To resolve the same problem, you can export the implementation class of the factory or parser you use in your application bundle A, and import it in JAXB B. But be aware of the package dependendencies of this class, as you also will have to export and import them, for them to be accessible. I haven't tried this thing but it could work, just try not to make the serpent bite its own tail.

Seyvoz Stephane

PS : I don't know how to be quoted on the forum/mailing list in order to make everyone see the solution, as my master of internship directly passed me the mails below. Feel free to do what you want with this mail :)


Reply via email to