You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Thomas Joseph <op...@gmail.com> on 2013/05/03 04:54:14 UTC

Felix SCR - Single valued String array issue

Hi All,

I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0, and
declaring a OSGi property as:

@Property(label="Multivalued Property", value={"only-single-value"})
private static final String MV_PROPERTY= "multivalued.property";

And then try to retrieve the property value as:


@Activate
@Modified
protected void activate(*final ComponentContext context*) throws Exception {
   Object prop = context.getProperties().get(MV_PROPERTY);
}



But I observe that the value is retrieved as a String and not a String
array. The generated SCR xml itself is generated for a String and not a
String array.
 <property name="multivalued.property" value="only-single-value"/>

However, if I declare the property as below, I get the value as an array.

@Property(label="Multivalued Property", value={"only-single-value"*, ""*})
private static final String MV_PROPERTY= "multivalued.property";

I Googled around but could not find anything conclusive. Am I missing
something here? How can I get a String array without a workaround done
above.

-- 
Thanks,
/Thomas Joseph

Re: Felix SCR - Single valued String array issue

Posted by Carsten Ziegeler <cz...@apache.org>.
Great, thanks!
I've just committed a fix to the scr annotations, so if you use the
1.9.3-SNAPSHOT version from trunk (together with the latest scr plugin,
1.12.0), it should work

Carsten


2013/5/3 Thomas Joseph <op...@gmail.com>

> Sure!
>
> https://issues.apache.org/jira/browse/FELIX-4047
>
> Thanks,
> Thomas Joseph
>
>
> On Fri, May 3, 2013 at 5:32 PM, Carsten Ziegeler <cziegeler@apache.org
> >wrote:
>
> > Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
> > cardinality or the unbounded property you influence the generation of the
> > metatype information, but not the ds xml file.
> > Could you please create an issue for this?
> >
> > Thanks
> > Carsten
> >
> > 2013/5/3 Thomas Joseph <op...@gmail.com>
> >
> > > Thanks Carsten!
> > >
> > > I tried both the options (unbounded=PropertyUnbounded.ARRAY and
> > > cardinality=N)
> > > independently, but unfortunately it doesn't seem to work. The scr xml
> > still
> > > generates <property name="multivalued.property"
> > value="only-single-value"/>
> > >
> > > I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0,
> > and
> > > still it won't work. Can I have a code sample somewhere, so that I can
> > try
> > > it out?
> > >
> > >
> > > Thanks,
> > > Thomas Joseph
> > >
> > >
> > >
> > > On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <
> cziegeler@apache.org
> > > >wrote:
> > >
> > > > Hi,
> > > >
> > > > unfortunately, the java annotations do not distinguish between a
> single
> > > > value and an array, so it's impossible by looking at {"single value"}
> > if
> > > > this is should be a single value or an array. For the tooling
> > inspecting
> > > > the annotations "single value" looks exactly the same. Therefore the
> > SCR
> > > > plugin assumes a single value to be exactly this: a single value :)
> > > > If you just want to specify a single default value for a multi value
> > > > property, you can either use cardinality=N if you want to limit the
> > > number
> > > > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the
> latter
> > > > option.
> > > >
> > > > Carsten
> > > >
> > > >
> > > > 2013/5/3 Thomas Joseph <op...@gmail.com>
> > > >
> > > > > Hi All,
> > > > >
> > > > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0,
> > and
> > > > > declaring a OSGi property as:
> > > > >
> > > > > @Property(label="Multivalued Property",
> value={"only-single-value"})
> > > > > private static final String MV_PROPERTY= "multivalued.property";
> > > > >
> > > > > And then try to retrieve the property value as:
> > > > >
> > > > >
> > > > > @Activate
> > > > > @Modified
> > > > > protected void activate(*final ComponentContext context*) throws
> > > > Exception
> > > > > {
> > > > >    Object prop = context.getProperties().get(MV_PROPERTY);
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > But I observe that the value is retrieved as a String and not a
> > String
> > > > > array. The generated SCR xml itself is generated for a String and
> > not a
> > > > > String array.
> > > > >  <property name="multivalued.property" value="only-single-value"/>
> > > > >
> > > > > However, if I declare the property as below, I get the value as an
> > > array.
> > > > >
> > > > > @Property(label="Multivalued Property",
> value={"only-single-value"*,
> > > > ""*})
> > > > > private static final String MV_PROPERTY= "multivalued.property";
> > > > >
> > > > > I Googled around but could not find anything conclusive. Am I
> missing
> > > > > something here? How can I get a String array without a workaround
> > done
> > > > > above.
> > > > >
> > > > > --
> > > > > Thanks,
> > > > > /Thomas Joseph
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Carsten Ziegeler
> > > > cziegeler@apache.org
> > > >
> > >
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
> >
>
>
>
> --
> Thanks and Regards,
> /Thomas Joseph
>
> LinkedIn: http://www.linkedin.com/in/ethomasjoseph
> Twitter: http://twitter.com/ethomasjoseph
>
> ------------------------------------------------------------
> Promote Open Source - Promote Liberty of Ideas and Software.
> ------------------------------------------------------------
>



-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Felix SCR - Single valued String array issue

Posted by Neil Bartlett <nj...@gmail.com>.
Well, it's not an all-or-nothing proposal. You can use the bnd
annotations in just a single component, but continue using the Felix
SCR annotations everywhere else.

Anyway I understand your desire to keep things simple, I just wanted
to make you aware of the possibility.

Regards,
Neil


On Mon, May 6, 2013 at 6:13 AM, Thomas Joseph <op...@gmail.com> wrote:
> Thanks Neil.
>
> At this stage of project, it is difficult to think of using bnd
> annotations, but will definitely consider this in my next assignment.
>
>
>
> On Fri, May 3, 2013 at 6:19 PM, Neil Bartlett <nj...@gmail.com> wrote:
>
>> For what it's worth... I assume you're building with
>> maven-bundle-plugin, so you could use the bnd annotations as an
>> alternative:
>>
>> @Component(properties = {
>>     "singletonProp:String=val1", // this is the default type
>>     "singleElementListProp:List<String>=val1",
>>     "multiElementListProp:List<String>=val1|val2|val3"
>> })
>>
>> Regards
>> Neil
>>
>> On Fri, May 3, 2013 at 1:40 PM, Thomas Joseph <op...@gmail.com>
>> wrote:
>> > Sure!
>> >
>> > https://issues.apache.org/jira/browse/FELIX-4047
>> >
>> > Thanks,
>> > Thomas Joseph
>> >
>> >
>> > On Fri, May 3, 2013 at 5:32 PM, Carsten Ziegeler <cziegeler@apache.org
>> >wrote:
>> >
>> >> Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
>> >> cardinality or the unbounded property you influence the generation of
>> the
>> >> metatype information, but not the ds xml file.
>> >> Could you please create an issue for this?
>> >>
>> >> Thanks
>> >> Carsten
>> >>
>> >> 2013/5/3 Thomas Joseph <op...@gmail.com>
>> >>
>> >> > Thanks Carsten!
>> >> >
>> >> > I tried both the options (unbounded=PropertyUnbounded.ARRAY and
>> >> > cardinality=N)
>> >> > independently, but unfortunately it doesn't seem to work. The scr xml
>> >> still
>> >> > generates <property name="multivalued.property"
>> >> value="only-single-value"/>
>> >> >
>> >> > I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0,
>> >> and
>> >> > still it won't work. Can I have a code sample somewhere, so that I can
>> >> try
>> >> > it out?
>> >> >
>> >> >
>> >> > Thanks,
>> >> > Thomas Joseph
>> >> >
>> >> >
>> >> >
>> >> > On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <
>> cziegeler@apache.org
>> >> > >wrote:
>> >> >
>> >> > > Hi,
>> >> > >
>> >> > > unfortunately, the java annotations do not distinguish between a
>> single
>> >> > > value and an array, so it's impossible by looking at {"single
>> value"}
>> >> if
>> >> > > this is should be a single value or an array. For the tooling
>> >> inspecting
>> >> > > the annotations "single value" looks exactly the same. Therefore the
>> >> SCR
>> >> > > plugin assumes a single value to be exactly this: a single value :)
>> >> > > If you just want to specify a single default value for a multi value
>> >> > > property, you can either use cardinality=N if you want to limit the
>> >> > number
>> >> > > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the
>> latter
>> >> > > option.
>> >> > >
>> >> > > Carsten
>> >> > >
>> >> > >
>> >> > > 2013/5/3 Thomas Joseph <op...@gmail.com>
>> >> > >
>> >> > > > Hi All,
>> >> > > >
>> >> > > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin
>> 1.8.0,
>> >> and
>> >> > > > declaring a OSGi property as:
>> >> > > >
>> >> > > > @Property(label="Multivalued Property",
>> value={"only-single-value"})
>> >> > > > private static final String MV_PROPERTY= "multivalued.property";
>> >> > > >
>> >> > > > And then try to retrieve the property value as:
>> >> > > >
>> >> > > >
>> >> > > > @Activate
>> >> > > > @Modified
>> >> > > > protected void activate(*final ComponentContext context*) throws
>> >> > > Exception
>> >> > > > {
>> >> > > >    Object prop = context.getProperties().get(MV_PROPERTY);
>> >> > > > }
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > > But I observe that the value is retrieved as a String and not a
>> >> String
>> >> > > > array. The generated SCR xml itself is generated for a String and
>> >> not a
>> >> > > > String array.
>> >> > > >  <property name="multivalued.property" value="only-single-value"/>
>> >> > > >
>> >> > > > However, if I declare the property as below, I get the value as an
>> >> > array.
>> >> > > >
>> >> > > > @Property(label="Multivalued Property",
>> value={"only-single-value"*,
>> >> > > ""*})
>> >> > > > private static final String MV_PROPERTY= "multivalued.property";
>> >> > > >
>> >> > > > I Googled around but could not find anything conclusive. Am I
>> missing
>> >> > > > something here? How can I get a String array without a workaround
>> >> done
>> >> > > > above.
>> >> > > >
>> >> > > > --
>> >> > > > Thanks,
>> >> > > > /Thomas Joseph
>> >> > > >
>> >> > >
>> >> > >
>> >> > >
>> >> > > --
>> >> > > Carsten Ziegeler
>> >> > > cziegeler@apache.org
>> >> > >
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Carsten Ziegeler
>> >> cziegeler@apache.org
>> >>
>> >
>> >
>> >
>> > --
>> > Thanks and Regards,
>> > /Thomas Joseph
>> >
>> > LinkedIn: http://www.linkedin.com/in/ethomasjoseph
>> > Twitter: http://twitter.com/ethomasjoseph
>> >
>> > ------------------------------------------------------------
>> > Promote Open Source - Promote Liberty of Ideas and Software.
>> > ------------------------------------------------------------
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
>
> --
> Thanks and Regards,
> /Thomas Joseph
>
> LinkedIn: http://www.linkedin.com/in/ethomasjoseph
> Twitter: http://twitter.com/ethomasjoseph
>
> ------------------------------------------------------------
> Promote Open Source - Promote Liberty of Ideas and Software.
> ------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Felix SCR - Single valued String array issue

Posted by Thomas Joseph <op...@gmail.com>.
Thanks Neil.

At this stage of project, it is difficult to think of using bnd
annotations, but will definitely consider this in my next assignment.



On Fri, May 3, 2013 at 6:19 PM, Neil Bartlett <nj...@gmail.com> wrote:

> For what it's worth... I assume you're building with
> maven-bundle-plugin, so you could use the bnd annotations as an
> alternative:
>
> @Component(properties = {
>     "singletonProp:String=val1", // this is the default type
>     "singleElementListProp:List<String>=val1",
>     "multiElementListProp:List<String>=val1|val2|val3"
> })
>
> Regards
> Neil
>
> On Fri, May 3, 2013 at 1:40 PM, Thomas Joseph <op...@gmail.com>
> wrote:
> > Sure!
> >
> > https://issues.apache.org/jira/browse/FELIX-4047
> >
> > Thanks,
> > Thomas Joseph
> >
> >
> > On Fri, May 3, 2013 at 5:32 PM, Carsten Ziegeler <cziegeler@apache.org
> >wrote:
> >
> >> Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
> >> cardinality or the unbounded property you influence the generation of
> the
> >> metatype information, but not the ds xml file.
> >> Could you please create an issue for this?
> >>
> >> Thanks
> >> Carsten
> >>
> >> 2013/5/3 Thomas Joseph <op...@gmail.com>
> >>
> >> > Thanks Carsten!
> >> >
> >> > I tried both the options (unbounded=PropertyUnbounded.ARRAY and
> >> > cardinality=N)
> >> > independently, but unfortunately it doesn't seem to work. The scr xml
> >> still
> >> > generates <property name="multivalued.property"
> >> value="only-single-value"/>
> >> >
> >> > I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0,
> >> and
> >> > still it won't work. Can I have a code sample somewhere, so that I can
> >> try
> >> > it out?
> >> >
> >> >
> >> > Thanks,
> >> > Thomas Joseph
> >> >
> >> >
> >> >
> >> > On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <
> cziegeler@apache.org
> >> > >wrote:
> >> >
> >> > > Hi,
> >> > >
> >> > > unfortunately, the java annotations do not distinguish between a
> single
> >> > > value and an array, so it's impossible by looking at {"single
> value"}
> >> if
> >> > > this is should be a single value or an array. For the tooling
> >> inspecting
> >> > > the annotations "single value" looks exactly the same. Therefore the
> >> SCR
> >> > > plugin assumes a single value to be exactly this: a single value :)
> >> > > If you just want to specify a single default value for a multi value
> >> > > property, you can either use cardinality=N if you want to limit the
> >> > number
> >> > > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the
> latter
> >> > > option.
> >> > >
> >> > > Carsten
> >> > >
> >> > >
> >> > > 2013/5/3 Thomas Joseph <op...@gmail.com>
> >> > >
> >> > > > Hi All,
> >> > > >
> >> > > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin
> 1.8.0,
> >> and
> >> > > > declaring a OSGi property as:
> >> > > >
> >> > > > @Property(label="Multivalued Property",
> value={"only-single-value"})
> >> > > > private static final String MV_PROPERTY= "multivalued.property";
> >> > > >
> >> > > > And then try to retrieve the property value as:
> >> > > >
> >> > > >
> >> > > > @Activate
> >> > > > @Modified
> >> > > > protected void activate(*final ComponentContext context*) throws
> >> > > Exception
> >> > > > {
> >> > > >    Object prop = context.getProperties().get(MV_PROPERTY);
> >> > > > }
> >> > > >
> >> > > >
> >> > > >
> >> > > > But I observe that the value is retrieved as a String and not a
> >> String
> >> > > > array. The generated SCR xml itself is generated for a String and
> >> not a
> >> > > > String array.
> >> > > >  <property name="multivalued.property" value="only-single-value"/>
> >> > > >
> >> > > > However, if I declare the property as below, I get the value as an
> >> > array.
> >> > > >
> >> > > > @Property(label="Multivalued Property",
> value={"only-single-value"*,
> >> > > ""*})
> >> > > > private static final String MV_PROPERTY= "multivalued.property";
> >> > > >
> >> > > > I Googled around but could not find anything conclusive. Am I
> missing
> >> > > > something here? How can I get a String array without a workaround
> >> done
> >> > > > above.
> >> > > >
> >> > > > --
> >> > > > Thanks,
> >> > > > /Thomas Joseph
> >> > > >
> >> > >
> >> > >
> >> > >
> >> > > --
> >> > > Carsten Ziegeler
> >> > > cziegeler@apache.org
> >> > >
> >> >
> >>
> >>
> >>
> >> --
> >> Carsten Ziegeler
> >> cziegeler@apache.org
> >>
> >
> >
> >
> > --
> > Thanks and Regards,
> > /Thomas Joseph
> >
> > LinkedIn: http://www.linkedin.com/in/ethomasjoseph
> > Twitter: http://twitter.com/ethomasjoseph
> >
> > ------------------------------------------------------------
> > Promote Open Source - Promote Liberty of Ideas and Software.
> > ------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Thanks and Regards,
/Thomas Joseph

LinkedIn: http://www.linkedin.com/in/ethomasjoseph
Twitter: http://twitter.com/ethomasjoseph

------------------------------------------------------------
Promote Open Source - Promote Liberty of Ideas and Software.
------------------------------------------------------------

Re: Felix SCR - Single valued String array issue

Posted by Neil Bartlett <nj...@gmail.com>.
For what it's worth... I assume you're building with
maven-bundle-plugin, so you could use the bnd annotations as an
alternative:

@Component(properties = {
    "singletonProp:String=val1", // this is the default type
    "singleElementListProp:List<String>=val1",
    "multiElementListProp:List<String>=val1|val2|val3"
})

Regards
Neil

On Fri, May 3, 2013 at 1:40 PM, Thomas Joseph <op...@gmail.com> wrote:
> Sure!
>
> https://issues.apache.org/jira/browse/FELIX-4047
>
> Thanks,
> Thomas Joseph
>
>
> On Fri, May 3, 2013 at 5:32 PM, Carsten Ziegeler <cz...@apache.org>wrote:
>
>> Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
>> cardinality or the unbounded property you influence the generation of the
>> metatype information, but not the ds xml file.
>> Could you please create an issue for this?
>>
>> Thanks
>> Carsten
>>
>> 2013/5/3 Thomas Joseph <op...@gmail.com>
>>
>> > Thanks Carsten!
>> >
>> > I tried both the options (unbounded=PropertyUnbounded.ARRAY and
>> > cardinality=N)
>> > independently, but unfortunately it doesn't seem to work. The scr xml
>> still
>> > generates <property name="multivalued.property"
>> value="only-single-value"/>
>> >
>> > I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0,
>> and
>> > still it won't work. Can I have a code sample somewhere, so that I can
>> try
>> > it out?
>> >
>> >
>> > Thanks,
>> > Thomas Joseph
>> >
>> >
>> >
>> > On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <cziegeler@apache.org
>> > >wrote:
>> >
>> > > Hi,
>> > >
>> > > unfortunately, the java annotations do not distinguish between a single
>> > > value and an array, so it's impossible by looking at {"single value"}
>> if
>> > > this is should be a single value or an array. For the tooling
>> inspecting
>> > > the annotations "single value" looks exactly the same. Therefore the
>> SCR
>> > > plugin assumes a single value to be exactly this: a single value :)
>> > > If you just want to specify a single default value for a multi value
>> > > property, you can either use cardinality=N if you want to limit the
>> > number
>> > > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the latter
>> > > option.
>> > >
>> > > Carsten
>> > >
>> > >
>> > > 2013/5/3 Thomas Joseph <op...@gmail.com>
>> > >
>> > > > Hi All,
>> > > >
>> > > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0,
>> and
>> > > > declaring a OSGi property as:
>> > > >
>> > > > @Property(label="Multivalued Property", value={"only-single-value"})
>> > > > private static final String MV_PROPERTY= "multivalued.property";
>> > > >
>> > > > And then try to retrieve the property value as:
>> > > >
>> > > >
>> > > > @Activate
>> > > > @Modified
>> > > > protected void activate(*final ComponentContext context*) throws
>> > > Exception
>> > > > {
>> > > >    Object prop = context.getProperties().get(MV_PROPERTY);
>> > > > }
>> > > >
>> > > >
>> > > >
>> > > > But I observe that the value is retrieved as a String and not a
>> String
>> > > > array. The generated SCR xml itself is generated for a String and
>> not a
>> > > > String array.
>> > > >  <property name="multivalued.property" value="only-single-value"/>
>> > > >
>> > > > However, if I declare the property as below, I get the value as an
>> > array.
>> > > >
>> > > > @Property(label="Multivalued Property", value={"only-single-value"*,
>> > > ""*})
>> > > > private static final String MV_PROPERTY= "multivalued.property";
>> > > >
>> > > > I Googled around but could not find anything conclusive. Am I missing
>> > > > something here? How can I get a String array without a workaround
>> done
>> > > > above.
>> > > >
>> > > > --
>> > > > Thanks,
>> > > > /Thomas Joseph
>> > > >
>> > >
>> > >
>> > >
>> > > --
>> > > Carsten Ziegeler
>> > > cziegeler@apache.org
>> > >
>> >
>>
>>
>>
>> --
>> Carsten Ziegeler
>> cziegeler@apache.org
>>
>
>
>
> --
> Thanks and Regards,
> /Thomas Joseph
>
> LinkedIn: http://www.linkedin.com/in/ethomasjoseph
> Twitter: http://twitter.com/ethomasjoseph
>
> ------------------------------------------------------------
> Promote Open Source - Promote Liberty of Ideas and Software.
> ------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Felix SCR - Single valued String array issue

Posted by Thomas Joseph <op...@gmail.com>.
Sure!

https://issues.apache.org/jira/browse/FELIX-4047

Thanks,
Thomas Joseph


On Fri, May 3, 2013 at 5:32 PM, Carsten Ziegeler <cz...@apache.org>wrote:

> Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
> cardinality or the unbounded property you influence the generation of the
> metatype information, but not the ds xml file.
> Could you please create an issue for this?
>
> Thanks
> Carsten
>
> 2013/5/3 Thomas Joseph <op...@gmail.com>
>
> > Thanks Carsten!
> >
> > I tried both the options (unbounded=PropertyUnbounded.ARRAY and
> > cardinality=N)
> > independently, but unfortunately it doesn't seem to work. The scr xml
> still
> > generates <property name="multivalued.property"
> value="only-single-value"/>
> >
> > I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0,
> and
> > still it won't work. Can I have a code sample somewhere, so that I can
> try
> > it out?
> >
> >
> > Thanks,
> > Thomas Joseph
> >
> >
> >
> > On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <cziegeler@apache.org
> > >wrote:
> >
> > > Hi,
> > >
> > > unfortunately, the java annotations do not distinguish between a single
> > > value and an array, so it's impossible by looking at {"single value"}
> if
> > > this is should be a single value or an array. For the tooling
> inspecting
> > > the annotations "single value" looks exactly the same. Therefore the
> SCR
> > > plugin assumes a single value to be exactly this: a single value :)
> > > If you just want to specify a single default value for a multi value
> > > property, you can either use cardinality=N if you want to limit the
> > number
> > > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the latter
> > > option.
> > >
> > > Carsten
> > >
> > >
> > > 2013/5/3 Thomas Joseph <op...@gmail.com>
> > >
> > > > Hi All,
> > > >
> > > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0,
> and
> > > > declaring a OSGi property as:
> > > >
> > > > @Property(label="Multivalued Property", value={"only-single-value"})
> > > > private static final String MV_PROPERTY= "multivalued.property";
> > > >
> > > > And then try to retrieve the property value as:
> > > >
> > > >
> > > > @Activate
> > > > @Modified
> > > > protected void activate(*final ComponentContext context*) throws
> > > Exception
> > > > {
> > > >    Object prop = context.getProperties().get(MV_PROPERTY);
> > > > }
> > > >
> > > >
> > > >
> > > > But I observe that the value is retrieved as a String and not a
> String
> > > > array. The generated SCR xml itself is generated for a String and
> not a
> > > > String array.
> > > >  <property name="multivalued.property" value="only-single-value"/>
> > > >
> > > > However, if I declare the property as below, I get the value as an
> > array.
> > > >
> > > > @Property(label="Multivalued Property", value={"only-single-value"*,
> > > ""*})
> > > > private static final String MV_PROPERTY= "multivalued.property";
> > > >
> > > > I Googled around but could not find anything conclusive. Am I missing
> > > > something here? How can I get a String array without a workaround
> done
> > > > above.
> > > >
> > > > --
> > > > Thanks,
> > > > /Thomas Joseph
> > > >
> > >
> > >
> > >
> > > --
> > > Carsten Ziegeler
> > > cziegeler@apache.org
> > >
> >
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>



-- 
Thanks and Regards,
/Thomas Joseph

LinkedIn: http://www.linkedin.com/in/ethomasjoseph
Twitter: http://twitter.com/ethomasjoseph

------------------------------------------------------------
Promote Open Source - Promote Liberty of Ideas and Software.
------------------------------------------------------------

Re: Felix SCR - Single valued String array issue

Posted by Carsten Ziegeler <cz...@apache.org>.
Ah, yes - you're right; I think you've hit a bug in the SCR plugin. With
cardinality or the unbounded property you influence the generation of the
metatype information, but not the ds xml file.
Could you please create an issue for this?

Thanks
Carsten

2013/5/3 Thomas Joseph <op...@gmail.com>

> Thanks Carsten!
>
> I tried both the options (unbounded=PropertyUnbounded.ARRAY and
> cardinality=N)
> independently, but unfortunately it doesn't seem to work. The scr xml still
> generates <property name="multivalued.property" value="only-single-value"/>
>
> I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0, and
> still it won't work. Can I have a code sample somewhere, so that I can try
> it out?
>
>
> Thanks,
> Thomas Joseph
>
>
>
> On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <cziegeler@apache.org
> >wrote:
>
> > Hi,
> >
> > unfortunately, the java annotations do not distinguish between a single
> > value and an array, so it's impossible by looking at {"single value"} if
> > this is should be a single value or an array. For the tooling inspecting
> > the annotations "single value" looks exactly the same. Therefore the SCR
> > plugin assumes a single value to be exactly this: a single value :)
> > If you just want to specify a single default value for a multi value
> > property, you can either use cardinality=N if you want to limit the
> number
> > of values, or unbounded=PropertyUnbounded.ARRAY. We usually the latter
> > option.
> >
> > Carsten
> >
> >
> > 2013/5/3 Thomas Joseph <op...@gmail.com>
> >
> > > Hi All,
> > >
> > > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0, and
> > > declaring a OSGi property as:
> > >
> > > @Property(label="Multivalued Property", value={"only-single-value"})
> > > private static final String MV_PROPERTY= "multivalued.property";
> > >
> > > And then try to retrieve the property value as:
> > >
> > >
> > > @Activate
> > > @Modified
> > > protected void activate(*final ComponentContext context*) throws
> > Exception
> > > {
> > >    Object prop = context.getProperties().get(MV_PROPERTY);
> > > }
> > >
> > >
> > >
> > > But I observe that the value is retrieved as a String and not a String
> > > array. The generated SCR xml itself is generated for a String and not a
> > > String array.
> > >  <property name="multivalued.property" value="only-single-value"/>
> > >
> > > However, if I declare the property as below, I get the value as an
> array.
> > >
> > > @Property(label="Multivalued Property", value={"only-single-value"*,
> > ""*})
> > > private static final String MV_PROPERTY= "multivalued.property";
> > >
> > > I Googled around but could not find anything conclusive. Am I missing
> > > something here? How can I get a String array without a workaround done
> > > above.
> > >
> > > --
> > > Thanks,
> > > /Thomas Joseph
> > >
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
> >
>



-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Felix SCR - Single valued String array issue

Posted by Thomas Joseph <op...@gmail.com>.
Thanks Carsten!

I tried both the options (unbounded=PropertyUnbounded.ARRAY and cardinality=N)
independently, but unfortunately it doesn't seem to work. The scr xml still
generates <property name="multivalued.property" value="only-single-value"/>

I even upgraded to SCR annotations v1.9.2 and Maven SCR plugin 1.12.0, and
still it won't work. Can I have a code sample somewhere, so that I can try
it out?


Thanks,
Thomas Joseph



On Fri, May 3, 2013 at 11:44 AM, Carsten Ziegeler <cz...@apache.org>wrote:

> Hi,
>
> unfortunately, the java annotations do not distinguish between a single
> value and an array, so it's impossible by looking at {"single value"} if
> this is should be a single value or an array. For the tooling inspecting
> the annotations "single value" looks exactly the same. Therefore the SCR
> plugin assumes a single value to be exactly this: a single value :)
> If you just want to specify a single default value for a multi value
> property, you can either use cardinality=N if you want to limit the number
> of values, or unbounded=PropertyUnbounded.ARRAY. We usually the latter
> option.
>
> Carsten
>
>
> 2013/5/3 Thomas Joseph <op...@gmail.com>
>
> > Hi All,
> >
> > I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0, and
> > declaring a OSGi property as:
> >
> > @Property(label="Multivalued Property", value={"only-single-value"})
> > private static final String MV_PROPERTY= "multivalued.property";
> >
> > And then try to retrieve the property value as:
> >
> >
> > @Activate
> > @Modified
> > protected void activate(*final ComponentContext context*) throws
> Exception
> > {
> >    Object prop = context.getProperties().get(MV_PROPERTY);
> > }
> >
> >
> >
> > But I observe that the value is retrieved as a String and not a String
> > array. The generated SCR xml itself is generated for a String and not a
> > String array.
> >  <property name="multivalued.property" value="only-single-value"/>
> >
> > However, if I declare the property as below, I get the value as an array.
> >
> > @Property(label="Multivalued Property", value={"only-single-value"*,
> ""*})
> > private static final String MV_PROPERTY= "multivalued.property";
> >
> > I Googled around but could not find anything conclusive. Am I missing
> > something here? How can I get a String array without a workaround done
> > above.
> >
> > --
> > Thanks,
> > /Thomas Joseph
> >
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>

Re: Felix SCR - Single valued String array issue

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

unfortunately, the java annotations do not distinguish between a single
value and an array, so it's impossible by looking at {"single value"} if
this is should be a single value or an array. For the tooling inspecting
the annotations "single value" looks exactly the same. Therefore the SCR
plugin assumes a single value to be exactly this: a single value :)
If you just want to specify a single default value for a multi value
property, you can either use cardinality=N if you want to limit the number
of values, or unbounded=PropertyUnbounded.ARRAY. We usually the latter
option.

Carsten


2013/5/3 Thomas Joseph <op...@gmail.com>

> Hi All,
>
> I am using Felix SCR annotations v1.7.0 and Maven SCR plugin 1.8.0, and
> declaring a OSGi property as:
>
> @Property(label="Multivalued Property", value={"only-single-value"})
> private static final String MV_PROPERTY= "multivalued.property";
>
> And then try to retrieve the property value as:
>
>
> @Activate
> @Modified
> protected void activate(*final ComponentContext context*) throws Exception
> {
>    Object prop = context.getProperties().get(MV_PROPERTY);
> }
>
>
>
> But I observe that the value is retrieved as a String and not a String
> array. The generated SCR xml itself is generated for a String and not a
> String array.
>  <property name="multivalued.property" value="only-single-value"/>
>
> However, if I declare the property as below, I get the value as an array.
>
> @Property(label="Multivalued Property", value={"only-single-value"*, ""*})
> private static final String MV_PROPERTY= "multivalued.property";
>
> I Googled around but could not find anything conclusive. Am I missing
> something here? How can I get a String array without a workaround done
> above.
>
> --
> Thanks,
> /Thomas Joseph
>



-- 
Carsten Ziegeler
cziegeler@apache.org