0

I am using BND annotations to assist with creating a configuration managed by OSGI cm.

Here is my simple config

@Meta.AD(required = false, type = Type.Boolean, deflt = "false")
boolean enabled();

I have used the BND configuration annotation library quite a few times, but this is the first time that I would like to use a boolean type.

I have read through this

And it talks about an integer or other alternative number based handling of booleans for convenience. The thing is the deflt method always returns a string value, if my type was an integer I would do "2" (these are parsed). But booleans don't seem to be parsed in the configurable BND code up to this assignment point.

if (resultType == boolean.class || resultType == Boolean.class) {
            if ( actualType == boolean.class || actualType ==   Boolean.class)
                return o;

            if (Number.class.isAssignableFrom(actualType)) {
                double b = ((Number) o).doubleValue();
                if (b == 0)
                    return false;
                else
                    return true;
            }
            return true;

I would like to further know why this returns true when the deflt value is never even parsed. I expected this to more closely follow the spec and return false, since cm would try to do Boolean.parseFrom, so anything not "true" equal ignore case is false.

All of this isn't a complete failure because if I change the value through cm it works correctly after setting to true, and then false again, but obviously that was just an effort at wondering if it would ever work.

Simply I would like to know if anyone knows how to set a BOOLEAN default value using BND's configuration annotations.

Thanks

cAllen
  • 13
  • 4
  • I can't see anything obviously wrong with this. I usually don't bother adding the `type=...` attribute to the annotation, because the type is already clearly defined by the return-type of the method. Could you try removing this attribute? – Neil Bartlett Feb 24 '13 at 12:07
  • I have tried it without this attribute without any change it the out come. – cAllen Feb 24 '13 at 19:15
  • This might be a bug, please report this on https://github.com/bndtools/bnd – Peter Kriens Feb 25 '13 at 07:28
  • Thank you Peter, it is issue 316. Thank you – cAllen Feb 25 '13 at 12:22

0 Answers0