[
https://issues.apache.org/jira/browse/FELIX-2563?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12904191#action_12904191
]
Felix Meschberger commented on FELIX-2563:
------------------------------------------
> What you say makes sense though it makes the example I provided impossible to
> implement with DS
Yes. And yes, DS requires component classes to have a default constructor.
Implementing the activate method (you don't have to modifiy the descriptor if
you use the default name "activate") you can get the using bundle from the
ComponentContext.
> service factory causes cast error
> ---------------------------------
>
> Key: FELIX-2563
> URL: https://issues.apache.org/jira/browse/FELIX-2563
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-1.6.0
> Reporter: Christopher Brind
> Priority: Minor
> Attachments: dsbug.jar
>
>
> Given this component XML:
> <?xml version="1.0" encoding="UTF-8"?>
> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
> name="dsbug.LongFactory">
> <implementation class="dsbug.LongFactory"/>
>
> <service servicefactory="true">
> <provide interface="java.lang.Long" />
> </service>
> </scr:component>
> And given this component class:
> package dsbug;
> import org.osgi.framework.Bundle;
> import org.osgi.framework.ServiceFactory;
> import org.osgi.framework.ServiceRegistration;
> public class LongFactory implements ServiceFactory {
> public Object getService(Bundle bundle, ServiceRegistration
> registration) {
> return new Long(bundle.getBundleId());
> }
> public void ungetService(Bundle bundle, ServiceRegistration
> registration,
> Object service) {
> }
>
> }
> Causes this error when referencing the service factory (resulting in
> unsatisfied dependencies):
> org.apache.felix.log.LogException: org.osgi.framework.ServiceException:
> Service cannot be cast: java.lang.Long
> However, when using this Activator *instead* of DS, all is well:
> package dsbug;
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> public class Activator implements BundleActivator {
> public void start(BundleContext context) throws Exception {
> context.registerService(Long.class.getName(), new
> LongFactory(), null);
> }
> public void stop(BundleContext context) throws Exception {
> }
> }
> Workaround (with DS) is to create a simple component with an
> activate(BundleContext ctx) method and manually register the service.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.