private boolean initConfig() { if (fileConfigs.isEmpty()) { try { for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) { FileConfiguration fileConfig = fileConfigBuilder.getConfiguration(); FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(0); fileConfig.setReloadingStrategy(reloadingStrategy); fileConfigs.add(fileConfig); } } catch (ConfigurationException ex) { if (!fileNotFound(ex)) { LOG.error("Config init failed {}", ex); } } } return !fileConfigs.isEmpty(); }
/** * The combined config = current user config + defaults for non-specified properties. * TODO: instead of re-reading user config every time, it would be better * to set up Commons Configuration listeners on the userfile. * @return even if reading user config fails, will return default config */ public CompositeConfiguration getConfig() { // try loading user config FileConfiguration userConfig = null; try { userConfig = BmConfig.forClass(BaseMap2D.class); } catch (ConfigurationException | IOException ex) { Exceptions.printStackTrace(ex); } CompositeConfiguration compositeConfig = new CompositeConfiguration(); // the order of adding configurations to combined configuration is important // whoever is added first "shadows" the same key in all subsequently added // configuraions. Thus, add the DEFAULTs at the very end if (userConfig != null) { compositeConfig.addConfiguration(userConfig); } compositeConfig.addConfiguration(defaultConfig); return compositeConfig; }
@Bean public FileConfiguration configuration() throws IOException, ConfigurationException { Path configFile = Paths.get("config"); if (!configFile.toFile().exists()) { Files.createFile(configFile); } PropertiesConfiguration config = new PropertiesConfiguration(); config.setFileName(configFile.toString()); config.setAutoSave(true); config.load(); return config; }
private void loadView(FileConfiguration fileConfig) { Iterator fileIter = fileConfig.getKeys(); while (fileIter.hasNext()) { String key = (String) fileIter.next(); setViewProperty(fileConfig, key, fileConfig.getProperty(key)); } }
private void setViewProperty(FileConfiguration fileConfig, String key, Object value) { if (!viewConfig.containsKey(key) || !viewConfig.getProperty(key).equals(value)) { LOG.debug("Setting property, key={} value={}", key, fileConfig.getProperty(key)); viewConfig.setProperty(key, fileConfig.getProperty(key)); } }
/** * Gets a new properties configuration that will re-load the properties from a file every time it is called. * * @return the properties configuration. * @throws ConfigurationException if the properties configuration couldn't be created. */ private PropertiesConfiguration getNewPropertiesConfiguration() throws ConfigurationException { // Create a new properties configuration. // We are using this instead of a database configuration for easier testing. PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesFile); // Create a reloading strategy that will always reload when asked. // There were some problems using the FileChangedReloadingStrategy where it wasn't detecting changed files and causing some methods in this // JUnit to fail. propertiesConfiguration.setReloadingStrategy(new ReloadingStrategy() { @Override public void setConfiguration(FileConfiguration configuration) { } @Override public void init() { } @Override public boolean reloadingRequired() { // Tell the caller that the properties should always be reloaded. return true; } @Override public void reloadingPerformed() { } }); return propertiesConfiguration; }
public static void save(Configuration configuration) throws ConfigurationException { FileConfiguration fileConfiguration = getWritableFileConfiguration(configuration); if (fileConfiguration == null) { throw new ConfigurationException("Cannot save configuration"); } else { fileConfiguration.save(); } }
public static FileConfiguration getWritableFileConfiguration(Configuration configuration) { if (configuration instanceof FileConfiguration) { return (FileConfiguration)configuration; } else if (configuration instanceof CompositeConfiguration) { CompositeConfiguration compositeConfiguration = (CompositeConfiguration)configuration; Configuration inMemoryConfigutation = compositeConfiguration.getInMemoryConfiguration(); return getWritableFileConfiguration(inMemoryConfigutation); } else { return null; } }
public void reload() { boolean mainConfigLoaded = false; for (ConfigView configView : configViews) { Configuration configurationForView; try { configurationForView = configurationProvider.getConfigurationForView(configView); if (configurationForView instanceof DataConfiguration) { DataConfiguration dc = (DataConfiguration) configurationForView; configurationForView = dc.getConfiguration(); } if (configurationForView instanceof FileConfiguration) { FileConfiguration fc = (FileConfiguration) configurationForView; if (configView instanceof InMainConfig) { if (!mainConfigLoaded) { fc.reload(); mainConfigLoaded = true; } } else { fc.reload(); } configView.loadConfiguration(fc); } } catch (ConfigurationException e1) { //TODO ?? e1.printStackTrace(); } } }
public Configuration flushUserConfigToDefault() { FileConfiguration userConfig = null; try { userConfig = BmConfig.forClass(BaseMap2D.class); userConfig.clear(); userConfig.save(); userConfig = BmConfig.forClass(BaseMap2D.class); } catch (ConfigurationException | IOException ex) { Exceptions.printStackTrace(ex); } defaultConfig = readDefaultConfig(); return userConfig; }
/** * Gets only the properties stored in user.dir in Netbeans App. * @return null if something went wrong during retrieving userconfig */ public FileConfiguration getUserConfig() { try { return BmConfig.forClass(BaseMap2D.class); } catch (ConfigurationException | IOException ex) { Exceptions.printStackTrace(ex); } return null; }
void store() throws ConfigurationException, IOException { updateConfigToUIState(); FileConfiguration userConfig = BmConfig.forClass(BaseMap2D.class); for (Iterator<String> i = config.getKeys(); i.hasNext();) { String key = i.next(); Object value = config.getProperty(key); userConfig.setProperty(key, value); } userConfig.save(); }
@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY) public Resolution update() { setupFormAndBean(); form.readFromRequest(context.getRequest()); if (form.validate()) { logger.debug("Applying settings to model"); try { FileConfiguration fileConfiguration = (FileConfiguration) configuration; Settings settings = new Settings(); form.writeToObject(settings); fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName); fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage); fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage); if(!settings.preloadGroovyPages || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) { fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES, settings.preloadGroovyPages); } if(!settings.preloadGroovyClasses || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) { fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES, settings.preloadGroovyClasses); } fileConfiguration.save(); logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath()); } catch (Exception e) { logger.error("Configuration not saved", e); SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved")); return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully")); return new RedirectResolution(this.getClass()); } else { return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } }
@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY) public Resolution update() { setupFormAndBean(); form.readFromRequest(context.getRequest()); if (form.validate()) { logger.debug("Applying settings to model"); try { FileConfiguration fileConfiguration = (FileConfiguration) configuration; Settings settings = new Settings(); form.writeToObject(settings); fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName); fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage); fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage); if (!settings.preloadGroovyPages || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) { fileConfiguration .setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES, settings.preloadGroovyPages); } if (!settings.preloadGroovyClasses || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) { fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES, settings.preloadGroovyClasses); } fileConfiguration.save(); logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath()); } catch (Exception e) { logger.error("Configuration not saved", e); SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved")); return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully")); return new RedirectResolution(this.getClass()); } else { return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp"); } }
public FileConfiguration getFileConfiguration(){ return this.config; }
public static void main(final String[] args) throws Exception { final FileConfiguration configuration = new PropertiesConfiguration(args[0]); new GraknSparkComputer(HadoopGraph.open(configuration)) .program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)) .submit().get(); }
public static void main(final String[] args) throws Exception { final FileConfiguration configuration = new PropertiesConfiguration(args[0]); new GiraphGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get(); }
public static void main(final String[] args) throws Exception { final FileConfiguration configuration = new PropertiesConfiguration(args[0]); new SparkGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get(); }
@Override public FileConfiguration getConfiguration() throws ConfigurationException { return new PropertiesConfiguration(url); }
public FileConfiguration getConfiguration() { return configuration; }
public static FileConfiguration forClass(Class<?> clazz) throws ConfigurationException, IOException { // return new XMLConfiguration(getConfigFile(clazz)); return new PropertiesConfiguration(getConfigFile(clazz)); }
@Inject public ApiKeysCommand(final Configuration config, final Flickr flickr) { this.config = (FileConfiguration) config; this.flickr = flickr; }
public ModuleRegistry(FileConfiguration configuration) { this.configuration = configuration; }
/** * @return configuration - {return content description} */ public static FileConfiguration getConfiguration() { return configuration; }
/** * @param configuration - {parameter description}. */ public static void setConfiguration(FileConfiguration configuration) { BaseContextUtils.configuration = configuration; }
protected FileConfiguration getConfigFile() { return basicProperties; }
public void setConfiguration(Configuration configuration) { m_configuration = (FileConfiguration)configuration; }
FileConfiguration getConfiguration() throws ConfigurationException;