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);
}
}
|