Example usage for org.apache.commons.configuration FileConfiguration getReloadingStrategy

List of usage examples for org.apache.commons.configuration FileConfiguration getReloadingStrategy

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration getReloadingStrategy.

Prototype

ReloadingStrategy getReloadingStrategy();

Source Link

Document

Return the reloading strategy.

Usage

From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java

private boolean mustReloadDefinitionFiles(CmsRepository associatedRepository) {

    //Check reload flag with default value set to false
    if (isCmsInProductionMode()) {
        if (definitionFileConfigurations != null
                && CollectionUtils.isNotEmpty(definitionFileConfigurations.get(associatedRepository.getId()))) {
            return false;
        } else {//from   w w w.  j ava 2s  . c  o m
            return true;
        }
    }
    //Debug mode
    else if (configuration != null) {

        final boolean reloadDefinitionFiles = configuration
                .getBoolean(CmsConstants.RELOAD_CONTENT_DEFINITION_FILE, false);

        //Reloading has been disabled but no definition files have ever been loaded
        //It may be the first time
        if (!reloadDefinitionFiles && (definitionFileConfigurations == null
                || !definitionFileConfigurations.containsKey(associatedRepository.getId()))) {
            return true;
        }

        if (reloadDefinitionFiles && definitionFileConfigurations != null) {

            List<FileConfiguration> repositoryFileConfigurations = definitionFileConfigurations
                    .get(associatedRepository.getId());

            if (repositoryFileConfigurations == null) {
                return true;
            }

            //Check if any file has been added or removed
            //Get files that exist in definition directory
            File[] definitionSchemaFiles = retrieveXmlSchemaFiles(associatedRepository, false);

            //At least one definition was added or removed
            if (repositoryFileConfigurations.size() != definitionSchemaFiles.length) {
                return true;
            }

            //Reload flag is set to true. Check that file is changed
            boolean atLeastOneFileChanged = false;
            for (FileConfiguration fileConf : repositoryFileConfigurations) {
                if (fileConf.getReloadingStrategy().reloadingRequired()) {
                    fileConf.getReloadingStrategy().reloadingPerformed();
                    logger.info("Definition file {} has been modified and will be reloaded for repository {}",
                            fileConf.getFileName(), associatedRepository.getId());
                    atLeastOneFileChanged = true;
                    break;
                }
            }

            return atLeastOneFileChanged;

        }

    }

    return false;
}