[osgi-dev] Factory for registering services in Declarative Service

Neil Bartlett njbartlett at gmail.com
Fri Nov 19 05:04:47 EST 2010

Creating objects of different classes based on configuration data is not supported by Declarative Services. The DS runtime always instantiates the class named in the "implementation" element.

You will need to drop down to the ServiceTracker API to achieve what you are trying to do.


Sent from my BlackBerry

On 19 Nov 2010, at 09:04, Martin Ždila <m.zdila at gmail.com> wrote:

> Hello
> We are using Managed Service Factory in Declarative Services to create one component for every configuration. This works perfectly if the component we want to register is exactly of the class specified in the <implementation class="..."/>.
> But sometimes we need a factory to create the component of different implementation type. For example we want to register componend that is of the java.security.cert.Certificate subtype according to the configuration properties like:
> - certificate type (eg. X509) (this defines the real type)
> - certificate (in PEM format)
> - security provider name
> There may be multiple certificates registered - every with the different properties. We can't do <implementation class="java.security.cert.Certificate"/> because this class can't configure itself from the properties. Also the real implementation can be sun.security.x509.X509CertImpl or different class according to the "certificate type" configuration property.
> We checked the usage of Component Factory (factory="...") and Service Factory (servicefactory="...") but none seems to solve our problem. One solution is to use delegator design pattern, but it is too cumbersome. Is there some transparent way to achieve our needs using Declarative Services so that consumer component will only use <reference interface="java.security.cert.Certificate" bind="setCertificate" target="..."/> ?
> Thanks in advance
> Best regards
> -- 
> Ing. Martin Ždila 
> tel:+421-908-363-848
> mailto:martin at zdila.sk
> http://www.zdila.sk/
> _______________________________________________
> OSGi Developer Mail List
> osgi-dev at mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.osgi.org/pipermail/osgi-dev/attachments/20101119/98bdba3f/attachment.html

More information about the osgi-dev mailing list