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


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.

Reply via email to