Adding Properties to the Bundle/ OSGI CQ Service
String / TextField
@Property(value = "GET")
 static final String STRING_VAL = "string.textfield";
String Array / Multifield
@Property ( unbounded=PropertyUnbounded.ARRAY, value={"*"},label="Template paths",description="eg: /apps/devtools/templates/page-home" )
 private static final String MUTIFIELD_EX = "multifield.test";
Boolean Field
@Property(boolValue={false}, label="Boolean values", description="Booealn test")
 private static final String BOOLEN_TEST = "boolean_test";
Dropdown
@Property( options={
    @PropertyOption(name="blue", value="color-blue"),
    @PropertyOption(name="green", value="color-green"), 
    @PropertyOption(name="red", value="color-red"), 
    @PropertyOption(name="yellow", value="color-yellow"), 
 private static final String SELECTION_TEST = "dropdown.test";
Reading Properties of Bundle/ OSGI CQ Service
1) You to get the ConfigurationAdmin  reference
@Reference
    ConfigurationAdmin configAdmin; 
2) Get Bundle Configuratinn
            Configuration config = configAdmin.getConfiguration(this.getClass().getCanonicalName());
3) Get properties of conguration
     Dictionary<?, ?> configProperties = config.getProperties();
4) Red Properties
Reading String/TextField
          String texfiledValue =  (String) configProperties.get( STRING_VAL );
Reading the Dropdown
        String dropdownTest  =  (String) configProperties.get( SELECTION_TEST );
Reading Boolean
          Boolean booealnTest = ( Boolean ) configProperties.get( BOOLEN_TEST );
Reading Array/Multifield
           String[] multifieldVlaues  =  (String[]) configProperties.get( MUTIFIELD_EX );
      for( String value : multifieldVlaues ){
   out.println( value ); 
  }
 
No comments :
Post a Comment