Serge Huber created FELIX-4296:
----------------------------------

             Summary: Cannot deactivate service interface detection in DS 
annotations
                 Key: FELIX-4296
                 URL: https://issues.apache.org/jira/browse/FELIX-4296
             Project: Felix
          Issue Type: Bug
          Components: SCR Annotations
    Affects Versions: scr ds annotations 1.2.4
            Reporter: Serge Huber


I am trying to use DS annotations to declare an extender, and I have the 
following annotation and class definition : 

@Component(service={})
public class ExtenderBundleListener implements SynchronousBundleListener {

According to the DS annotation specification this is value, as is illustrated 
from the javadoc :

        /**
         * The types under which to register this Component as a service.
         *
         * <p>
         * If no service should be registered, the empty value
         * <code>&#x7B;&#x7D;</code> must be specified.
         *
         * <p>
         * If not specified, the service types for this Component are all the
         * <i>directly</i> implemented interfaces of the class being annotated.
         *
         * @see "The service element of a Component Description."
         */
        Class< ? >[] service() default {};

Unfortunately this doesn't work, as it seems that the annotation parser 
transforms the {} value into "null" so the following code in the DS annotation 
processor doesn't work as expected : 

        final List<String> listedInterfaces = new ArrayList<String>();
        if (cad.getValue("service") != null) {
            final String[] interfaces = (String[]) cad.getValue("service");
            for (final String t : interfaces) {
                listedInterfaces.add(t);
            }
        } else {
            // scan directly implemented interfaces
            this.searchInterfaces(listedInterfaces, 
scannedClass.getScannedClass());
        }

This is a bit problematic to solve because we would need to differentiate 
between the null and empty case, but it seems that this is somehow not 
supported by the annotations parser ?

For the moment I worked around the problem by using the following annotation, 
but it's rather ugly since it still generates a service that is not needed :

@Component(service={ExtenderBundleListener.class}, immediate = true) // ideally 
we would like to not specify any service but it's seems that due to a bug in 
the DS annotation processor this is not possible so we use the immediate 
setting instead
public class ExtenderBundleListener implements SynchronousBundleListener {




--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to