Hi,

Am Freitag, den 19.11.2010, 12:33 +0100 schrieb Martin Ždila: 
> On Fri, Nov 19, 2010 at 12:22 PM, Neil Bartlett <[email protected]>
> wrote:
>         Why do you feel that DS disobeys the ServiceFactory contract?
>         
> 
> 
> In the component.xml I have:
> 
> 
> <implementation class="MyFactory"/>
> <service><provide interface="MyService"/></service>
> 
> 
> The class:
> 
> 
> public class MyFactory implements ServiceFactory {
>     public Object getService(Bundle bundle, ServiceRegistration
> registration) {
>         // .... returns object that implements MyService
>     }
> }
> 
> 
> This throws ClassCastException somewhere in the Apache Felix code. Or
> is it a bug in Apache Felix?

Yes of course ;-)

Point is that DS implements the ServiceFactory object on behalf of the
component if the component is delayed or marked as a service factory. In
the end DS always creates an instance of said implementation class which
must implement the provided interface(s).

This is not violating the ServiceFactory contract but along the vision
of DS relieves the burdon of using OSGi API from the component.

In your case, the problem is that you have some configuration which must
instantiate some more-or-less random class. I agree with Neil, that it
would probably best if you forget about DS and....

  * Implement a ManagedServiceFactory listeing for the configurations
  * Instantiate (and destory) your service instances yourself 
  * Register/unregister the services instances along the way

I don't think you need to use Service Tracker, though.

The clients of your class can still be implemented as DS components
referring to the dynamically created and registered services. Its just
provisioning of the services that is not handled by DS.

HTH
Regards
Felix

>  
> -- 
> Ing. Martin Ždila 
> CTO
> 
> M-Way Solutions Slovakia s.r.o.
> Letná 27, 040 01 Košice
> Slovakia
> 
> tel:+421-908-363-848
> mailto:[email protected]
> http://www.mwaysolutions.com
> 
> _______________________________________________
> 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