Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • First we configure the DSCS so that it knows about the property. Define your property as a static string in:
    • org.sakaiproject.component.configuration.properties.api.ConfigurationProperties
  • It has to be a unique value. We recommend that you use the package name from the class where the property lives, and append the property name:
    • e.g.
      Code Block
      package org.sakaiproject.component.configuration.properties.api;
      
      	public interface ConfigurationProperties {
      
      		// Person's First Name
      		public static final String PERSON_FIRST_NAME = "org.sakaiproject.example.Person.FirstName";
      
      		// ...
      	}
      	
      
  • Now, modify the component-impl's components.xml file.
  • Find the following bean: "<bean id="org.sakaiproject.component.configuration.service.api.DynamicServerConfigurationService" and locate the "dynamicSakaiProperties" bean property. Then, add your configurable property to the map and assign it an initial value:
    • e.g.
      Code Block
      <property name="dynamicSakaiProperties">
      	<map>
      		<entry key="org.sakaiproject.example.Person.FirstName">
      			<value>Thomas</value>
      		</entry>
      	</map>
      </property>
      
  • The target class that wants to add a dynamically configurable property needs to implement "ConfigurationNotificationListener" and "ConfigurationProperties"
    • e.g.
      Code Block
      public class PersonImpl implements ConfigurationNotificationListener, ConfigurationProperties { ... }
      
  • The class needs to get the initial property value either at construction time or during a Spring init() method invocation.
  • Also, it needs to implement the ConfigurationNotificationListener API method "handleNotification"
    • e.g.
      Code Block
      
      package org.sakaiproject.example.Person;
      
      public class PersonImpl implements ConfigurationNotificationListener, ConfigurationProperties {
      
      	// ...
      
      	private String firstName;
      	private DynamicServerConfigurationService dynamicServerConfigurationService;
      	
      	// ...
      
      	// Spring DSCS injection
      	public void setDynamicServerConfigurationService(DynamicServerConfigurationService dynamicServerConfigurationService) {
      		this.dynamicServerConfigurationService = dynamicServerConfigurationService;
      	}
      
      	// Spring init method
      	public void init() {
      		
      		// Configuration Service
      		dynamicServerConfigurationService.addNotificationListener(this, PERSON_FIRST_NAME);
      		
      		try {
      			
      			firstName = dynamicServerConfigurationService.getDynamicString(PERSON_FIRST_NAME);
      			
      		} catch (ConfigurationObjectNotFound e) {
      			LOG.error("Was not able to find configuration property");
      		} catch (InvalidConfigurationKey e) {
      			LOG.error("Provided invalid configuration key");
      		}
      	}
      	
      	// Implementing ConfigurationNotificationListener API: handleNotification
      	public void handleNotification(String configurationItemKey) {
      		
      		try {
      
      			if(PERSON_FIRST_NAME.equals(configurationItemKey)) {
      				firstName = dynamicServerConfigurationService.getDynamicString(PERSON_FIRST_NAME);
      			}
      
      		} catch (ConfigurationObjectNotFound e) {
      			LOG.error("Was not able to find configuration property for key = " + configurationItemKey);
      		} catch (InvalidConfigurationKey e) {
      			LOG.error("Provided invalid configuration key = " + configurationItemKey);
      		}
      	}