You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Christopher Brind (JIRA)" <ji...@apache.org> on 2010/08/30 13:12:53 UTC

[jira] Updated: (FELIX-2563) service

     [ https://issues.apache.org/jira/browse/FELIX-2563?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christopher Brind updated FELIX-2563:
-------------------------------------

    Attachment: dsbug.jar

dsbug.jar contains deloyable bundle (that contains the bug) and source.

> service
> -------
>
>                 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.