Friedrik

You are correct -- the spec's coverage of component factories is rather 
sparse, and it won't help you in this case. The <service> element's 
servicefactory attribute might not help much either, since all it does is 
ensures that a unique instance is given to each bundle that request any of 
the component's provided services.

>I need to use an other object as implementation for the provided
>service, rather than an instance of the implementation mentioned
>in the component description. This is part of a legacy implementation,
>where the implementation of the interface provided is separated from
>the class doing the life cycle, as there are a bunch of these cases,
>and I would to solve it in a general manner.

This is my preferred approach when working with DS.  It's nasty to specify 
a POJO as the component's implementation class as it's too easy to create 
an unwanted dependency upon OSGi, especially when using the 
activate/deactivate methods.

I suggest implementing a Component class that is the component's 
implementation that implements all the provided services, and that simply 
forwards service API requests to POJO instances cached by the Component 
class.

Would this not work?

Simon




"Fredrik Alströmer" <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
10/21/2008 04:02 AM
Please respond to
OSGi Developer Mail List <[email protected]>


To
"OSGi Developer Mail List" <[email protected]>
cc

Subject
[osgi-dev] Re: Declarative Services factory components.






I just realized I should probably be dealing with the 'servicefactory'
attribute instead, I'm working on it right now, if anyone has any
input/ideas/concerns, please don't hesitate to voice them anyway. ;)

I'm still interested in how factory components should be used though,
if anyone has got any guidelines or good examples...

Thanks,
Fredrik.

On Tue, Oct 21, 2008 at 09:30, Fredrik Alströmer <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I'd like to have a component, with normal requires and provides, which
> are satisfied in the normal manner. However, when the component has
> been activated and a request for the service is made, I need to use an
> other object as implementation for the provided service, rather than
> an instance of the implementation mentioned in the component
> description. This is part of a legacy implementation, where the
> implementation of the interface provided is separated from the class
> doing the life cycle (this class incidentally creates the instance of
> the class providing the interface that I need, so I can't make a
> separate component which just depends on the life cycle component
> either). I also don't want to make a wrapper (or proxy..), as there
> are a bunch of these cases, and I would to solve it in a general
> manner.
>
> Can I use factory components for this? I tried to understand the
> compendium, but it appears to be very brief on this matter. If this
> cannot be done with factory components, could someone please explain
> how to use factory components? Who calls newInstance? (Does it have to
> be done explicitly?)
>
> I hope my question was halfway comprehensible, it felt pretty
> confusing to me... :)
>
> Thanks,
> Fredrik.
>

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to