I am developing an application using OSGi (Equinox platform), and one of the bundles needs to parse XML files. So far I implemented this with SAX (javax.xml.parsers.SAXParserFactory) and I would like to retrieve the SAXParserFactory from the platform.

Hi, I'm not confident with OSGi but why not to use the XML stack bundled with the JRE?
–
ATorrasJul 21 '09 at 14:42

Hi, yes it is, but the OSGi classloader mechanism differs - and hence calling the SAXParserFactory.newInstance() may yield problems, since the JAXP loader mechanism expects to find the parser in the current's thread classloader and that may not necessarily be the case.
–
Manuel BernhardtJul 22 '09 at 7:39

If you want to write code that deals with the lifecycle layer of the OSGi platform, I would suggest to track the reference, rather than looking it up directly.
There are many approaches for this; I have written about one I call ServiceMediator here.

I would suggest also to look at "OSGI Dynamic Services" or "Spring DM" both have similar means for declaring/resolving dependencies of a bundle declaratively. And with these mechanisms the code above would simplify considerably.
–
Petr GladkikhJan 29 '10 at 5:07

The code above is not really complicated and can easily be machine generated (the Latch can be take from different places if required for the Runtime Environment). I don't doubt that DS (I assume that you refer to Declarative Services) is an alternative, however, you may as well end up with some pretty complex configuration files sometimes. Anyway, it's always good to have alternatives to pick from :)
–
DieterJan 29 '10 at 16:37

You can use Apache Xerces for Sax parsing. A suitable bundle is available from the Eclipse Orbit project. I don't know that the Xerces bundle registers a SAXParserFactory service but you can add a dependency on the bundle and use the Sax parser directly.