Checkboxes Osgi property via run modes/ Setup checkboxes for osgi

If you want to create checkboxes for your OSGI properties then you can do it by having boolValue attribute assigned to Property annotation.

@Property(boolValue = false/true)
public static final String XYZ_PROPERTY = “xyz.property”;

private boolean xyz;

Retrieving these properties is also simple, you can simply do it like this

@Activate
public void activate(final Map<String, String> properties) {

this.xyz = PropertiesUtil.toBoolean(properties.get(XYZ_PROPERTY ), false);

}

But sometimes you will run into situations where you would need to override these values from OSGI config. If you remove the boolValue from property annotation then the property will be treated as String instead of Boolean.

Example: you want checkbox checked for this above property from OSGI and you somehow don’t want to do it via code because this might change for environments

In your run mode file, if you have the below property and boolValue within the property annotation in the code, you are sorted.

xyz.property=”{Boolean}true”

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s