You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Per-Erik Svensson <pe...@gmail.com> on 2011/02/12 16:37:11 UTC

XMLParserActivator

Hi all,

I was wondering how to use the XMLParserActivator. I cant seem to find any
information about how it works. First of all, we bundle felix into our own
application and supply some "base/core" bundles to the framework (starting
together with the framework). One such base bundle would be an xml parser
factory so that our bundles can get a hold of an xml parser (factory).

   1. So, is the XMLParserActivator supplied by the felix framework somehow?
   I cant see it when listing all currently registered services (and my guess
   is that it isnt a service at all).
   2. If the answer to the above is no, how do I supply/set up one for my
   other bundles to use? Ultimately, I would like to use the java vm xml stack.
   3. Once it is set up, how is it supposed to be used? It doesn't look like
   a service so when I ask the service registry, what interface should I be
   asking for?

In short: bundleContext.getServiceReferences("What to type here?", "any
required filters?");

The only thing I get when searching the web is either about Equinox or
JavaDoc for the XMLParserActivator.

Regards,
Per-Erik Svensson

Re: XMLParserActivator

Posted by Per-Erik Svensson <pe...@gmail.com>.
On Sat, Feb 12, 2011 at 9:01 PM, Simon Chemouil <sc...@gmail.com> wrote:

> On Sat, Feb 12, 2011 at 4:37 PM, Per-Erik Svensson
> <pe...@gmail.com> wrote:
> >
> > Hi all,
> >
> > I was wondering how to use the XMLParserActivator. I cant seem to find
> any
> > information about how it works. First of all, we bundle felix into our
> own
> > application and supply some "base/core" bundles to the framework
> (starting
> > together with the framework). One such base bundle would be an xml parser
> > factory so that our bundles can get a hold of an xml parser (factory).
>
> If you have a bundle that provides a parser factory, you should use
> the Service Loader mechanism (
> http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html
> ) and the XMLParserActivator might find it and use it. But if it's
> *your* implementation it would be better if you registered your own
> factory as an OSGi service directly.
>
>
I don't have a bundle that provides a parser factory. Not everything in our
environment is bundleized (yet). We have an application that embeds felix.
(Long term goal is of course to make everything bundles and put them inside
felix but for now we have to much old code for that to work.) The actual
bundles that we do have need xml parsing facilities and I'm not sure how to
supply this from our application, through felix (OSGi), to our bundles.


> >   1. So, is the XMLParserActivator supplied by the felix framework
> somehow?
> >   I cant see it when listing all currently registered services (and my
> guess
> >   is that it isnt a service at all).
>
>
> The XMLParserActivator is in fact a part of the OSGi spec, and its
> package is supplied in the OSGi compendium 4.2 so it's the same for
> all frameworks. Its goal is to scan for bundles (or JRE) providing
> SAX/DOM factories (hopefully, StAX soon as well!) using the Java
> ServiceLoader mechanism and export those factories as OSGi services.
> The Javadoc for this class says pretty much everything:
> http://www.osgi.org/javadoc/r4v42/org/osgi/util/xml/XMLParserActivator.html
>
>
>
Our application need to act as a framework here since we just fire up felix
with a List of bundle activators. One of those activators need to be the
XMLParserActivator (or so I thought). So, I added the XMLParserActivator to
the list, in hope
that it would start supplying xml factories as osgi services. It didn't so I
had a look at the JavaDoc and it seems that I need to set it up properly (it
only scans the META-INF dir to know what classes to load). Now, since I have
no META-INF directory for the bundle that starts XMLParserActivator (since
the start is our application, not a bundle), I'm not sure how to proceed.
But I'm getting the feeling that I'm completely misunderstanding something
here so I should probably test a few things first. :)


> >   3. Once it is set up, how is it supposed to be used? It doesn't look
> like
> >   a service so when I ask the service registry, what interface should I
> be
> >   asking for?
> >
> > In short: bundleContext.getServiceReferences("What to type here?", "any
> > required filters?");
>
> You don't use this directly activator. It's a bridge provided by OSGi
> util to give you those XML parser factories as OSGi services.
>

Yes, but when I tell my
bundleContext.getServiceReference(DocumentBuilderFactory.class.getName()), I
get null in return. So either the XMLParserActivator isn't doing it's job
or, more likely, I haven't set it up correctly.


>
> You can get the services it exports by their name:
>
> bundleContext.getServiceReference(DocumentBuilderFactory.class.getName());
> or
> bundleContext.getServiceReference(XMLParserActivator.DOMFACTORYNAME);
>
> and
>
> bundleContext.getServiceReference(SAXParserFactory.class.getName());
> or
> bundleContext.getServiceReference(XMLParserActivator.SAXFACTORYNAME);
>
> If you can avoid referencing the XMLParserActivator class it would be
> nicer (e.g, first lines are better). The only real usage is if you
> want to get the name of the implementation you're using (DOMCLASSFILE
> or SAXCLASSFILE)
>
>
> (Common sense, as usual, is that you should probably consume services
> using a framework above the basic OSGi API, like DS, iPOJO, Peaberry
> or Blueprint).
>
>
Sure, it just felt easier to show the use case as
bndContext.getServiceRef... than spitting DS xml your way. And I still
needed the name of the service (which I get now should be the
DocumentBF/SAXPF interface names).


>
> > The only thing I get when searching the web is either about Equinox or
> > JavaDoc for the XMLParserActivator.
>
> The JavaDoc is pretty much all you need once you get why it's there :).
>
>
Heh, guess I don't get why it's there then! :)

But I'll try some new things out based on what you've said so far. Thanks
alot for the help - much appreciated!


>
> HTH,
>
> Simon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
Regards,
Per-Erik Svensson

Re: XMLParserActivator

Posted by Simon Chemouil <sc...@gmail.com>.
On Sat, Feb 12, 2011 at 4:37 PM, Per-Erik Svensson
<pe...@gmail.com> wrote:
>
> Hi all,
>
> I was wondering how to use the XMLParserActivator. I cant seem to find any
> information about how it works. First of all, we bundle felix into our own
> application and supply some "base/core" bundles to the framework (starting
> together with the framework). One such base bundle would be an xml parser
> factory so that our bundles can get a hold of an xml parser (factory).

If you have a bundle that provides a parser factory, you should use
the Service Loader mechanism (
http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html
) and the XMLParserActivator might find it and use it. But if it's
*your* implementation it would be better if you registered your own
factory as an OSGi service directly.


>   1. So, is the XMLParserActivator supplied by the felix framework somehow?
>   I cant see it when listing all currently registered services (and my guess
>   is that it isnt a service at all).


The XMLParserActivator is in fact a part of the OSGi spec, and its
package is supplied in the OSGi compendium 4.2 so it's the same for
all frameworks. Its goal is to scan for bundles (or JRE) providing
SAX/DOM factories (hopefully, StAX soon as well!) using the Java
ServiceLoader mechanism and export those factories as OSGi services.
The Javadoc for this class says pretty much everything:
http://www.osgi.org/javadoc/r4v42/org/osgi/util/xml/XMLParserActivator.html


>   3. Once it is set up, how is it supposed to be used? It doesn't look like
>   a service so when I ask the service registry, what interface should I be
>   asking for?
>
> In short: bundleContext.getServiceReferences("What to type here?", "any
> required filters?");

You don't use this directly activator. It's a bridge provided by OSGi
util to give you those XML parser factories as OSGi services.

You can get the services it exports by their name:

bundleContext.getServiceReference(DocumentBuilderFactory.class.getName());
or
bundleContext.getServiceReference(XMLParserActivator.DOMFACTORYNAME);

and

bundleContext.getServiceReference(SAXParserFactory.class.getName());
or
bundleContext.getServiceReference(XMLParserActivator.SAXFACTORYNAME);

If you can avoid referencing the XMLParserActivator class it would be
nicer (e.g, first lines are better). The only real usage is if you
want to get the name of the implementation you're using (DOMCLASSFILE
or SAXCLASSFILE)


(Common sense, as usual, is that you should probably consume services
using a framework above the basic OSGi API, like DS, iPOJO, Peaberry
or Blueprint).


> The only thing I get when searching the web is either about Equinox or
> JavaDoc for the XMLParserActivator.

The JavaDoc is pretty much all you need once you get why it's there :).


HTH,

Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org