2

I have a configuration file (an XML) which I load using XMLConfiguration.

I need to make sure that this XMLConfiguration instance is updated ( every 30 seconds ).

For that matter I have the following code:

 XMLConfiguration configuration = new XMLConfiguration(configFile);
 configuration.setAutoSave(true);

 FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
 strategy.setRefreshDelay(getRefreshDelay());
 configuration.setReloadingStrategy(strategy);

It works great, but the thing is I want to log any changes in this XML file.

Is there a way of doing it?

Noam
  • 3,049
  • 10
  • 34
  • 52
  • Please improve the question... Are you asking how to log, or are you asking how to check if there were changes in XML data? And how do you want to do the logging, text file or what? – hyde Nov 05 '12 at 15:59
  • Thanks for the reply - As for your questions: I want to log the changes to a log file. The changes I want to log are the changes in the xml file. I think I have an answer - I will post it here in a few seconds if it's correct – Noam Nov 05 '12 at 16:02

1 Answers1

2

I got it!

All I need to do is this:

        ConfigurationListener listener = new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if ( !event.isBeforeUpdate() ){
                System.out.println(event.getPropertyName() + " " + event.getPropertyValue());
            }
        }
    };
    configuration.addConfigurationListener(listener);

It works!

Noam
  • 3,049
  • 10
  • 34
  • 52