List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration
public SystemConfiguration()
From source file:org.sonar.server.configuration.ConfigurationFactory.java
public Configuration getConfiguration(ServletContextEvent sce) { CoreConfiguration configuration = new CoreConfiguration(); configuration.addConfiguration(getConfigurationFromPropertiesFile()); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(getDirectoriesConfiguration(sce)); return configuration; }
From source file:org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration.java
protected void configureArchaius(ConfigurableEnvironmentConfiguration envConfig) { if (initialized.compareAndSet(false, true)) { String appName = this.env.getProperty("spring.application.name"); if (appName == null) { appName = "application"; log.warn("No spring.application.name found, defaulting to 'application'"); }/*from w w w. ja v a 2 s .c o m*/ System.setProperty(DeploymentContext.ContextKey.appId.getKey(), appName); ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); // support to add other Configurations (Jdbc, DynamoDb, Zookeeper, jclouds, // etc...) if (externalConfigurations != null) { for (AbstractConfiguration externalConfig : externalConfigurations) { config.addConfiguration(externalConfig); } } config.addConfiguration(envConfig, ConfigurableEnvironmentConfiguration.class.getSimpleName()); // below come from ConfigurationManager.createDefaultConfigInstance() DynamicURLConfiguration defaultURLConfig = new DynamicURLConfiguration(); try { config.addConfiguration(defaultURLConfig, URL_CONFIG_NAME); } catch (Throwable ex) { log.error("Cannot create config from " + defaultURLConfig, ex); } // TODO: sys/env above urls? if (!Boolean.getBoolean(DISABLE_DEFAULT_SYS_CONFIG)) { SystemConfiguration sysConfig = new SystemConfiguration(); config.addConfiguration(sysConfig, SYS_CONFIG_NAME); } if (!Boolean.getBoolean(DISABLE_DEFAULT_ENV_CONFIG)) { EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(); config.addConfiguration(environmentConfiguration, ENV_CONFIG_NAME); } ConcurrentCompositeConfiguration appOverrideConfig = new ConcurrentCompositeConfiguration(); config.addConfiguration(appOverrideConfig, APPLICATION_PROPERTIES); config.setContainerConfigurationIndex(config.getIndexOfConfiguration(appOverrideConfig)); addArchaiusConfiguration(config); } else { // TODO: reinstall ConfigurationManager log.warn("Netflix ConfigurationManager has already been installed, unable to re-install"); } }
From source file:org.waveprotocol.wave.util.settings.SettingsBinder.java
/** * Bind configuration parameters into Guice Module. * * @return a Guice module configured with setting support. * @throws ConfigurationException on configuration error *///from www .j ava2 s . c om public static Module bindSettings(String propertiesFileKey, Class<?>... settingsArg) throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); String propertyFile = config.getString(propertiesFileKey); if (propertyFile != null) { config.addConfiguration(new PropertiesConfiguration(propertyFile)); } List<Field> fields = new ArrayList<Field>(); for (Class<?> settings : settingsArg) { fields.addAll(Arrays.asList(settings.getDeclaredFields())); } // Reflect on settings class and absorb settings final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>(); for (Field field : fields) { if (!field.isAnnotationPresent(Setting.class)) { continue; } // Validate target type SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType()); if (typeHelper == null || !typeHelper.check(field.getGenericType())) { throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types"); } Setting setting = field.getAnnotation(Setting.class); settings.put(setting, field); } // Now validate them List<String> missingProperties = new ArrayList<String>(); for (Setting setting : settings.keySet()) { if (setting.defaultValue().isEmpty()) { if (!config.containsKey(setting.name())) { missingProperties.add(setting.name()); } } } if (missingProperties.size() > 0) { StringBuilder error = new StringBuilder(); error.append("The following required properties are missing from the server configuration: "); error.append(Joiner.on(", ").join(missingProperties)); throw new ConfigurationException(error.toString()); } // bundle everything up in an injectable guice module return new AbstractModule() { @Override protected void configure() { // We must iterate the settings a third time when binding. // Note: do not collapse these loops as that will damage // early error detection. The runtime is still O(n) in setting count. for (Map.Entry<Setting, Field> entry : settings.entrySet()) { Class<?> type = entry.getValue().getType(); Setting setting = entry.getKey(); if (int.class.equals(type)) { Integer defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Integer.parseInt(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getInteger(setting.name(), defaultValue)); } else if (boolean.class.equals(type)) { Boolean defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Boolean.parseBoolean(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getBoolean(setting.name(), defaultValue)); } else if (String.class.equals(type)) { bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getString(setting.name(), setting.defaultValue())); } else { String[] value = config.getStringArray(setting.name()); if (value.length == 0 && !setting.defaultValue().isEmpty()) { value = setting.defaultValue().split(","); } bind(new TypeLiteral<List<String>>() { }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value)); } } } }; }
From source file:org.wso2.andes.configuration.qpid.ServerConfiguration.java
public static org.apache.commons.configuration.Configuration flatConfig(File file) throws ConfigurationException { // We have to override the interpolate methods so that // interpolation takes place accross the entirety of the // composite configuration. Without doing this each // configuration object only interpolates variables defined // inside itself. final MyConfiguration conf = new MyConfiguration(); conf.addConfiguration(new SystemConfiguration() { protected String interpolate(String o) { return conf.interpolate(o); }/*from w w w .ja v a2 s . co m*/ }); conf.addConfiguration(new XMLConfiguration(file) { protected String interpolate(String o) { return conf.interpolate(o); } }); return conf; }
From source file:org.wso2.andes.server.configuration.ServerConfiguration.java
public final static Configuration flatConfig(File file) throws ConfigurationException { // We have to override the interpolate methods so that // interpolation takes place accross the entirety of the // composite configuration. Without doing this each // configuration object only interpolates variables defined // inside itself. final MyConfiguration conf = new MyConfiguration(); conf.addConfiguration(new SystemConfiguration() { protected String interpolate(String o) { return conf.interpolate(o); }//w w w . java 2 s.co m }); conf.addConfiguration(new XMLConfiguration(file) { protected String interpolate(String o) { return conf.interpolate(o); } }); return conf; }
From source file:ro.nextreports.server.web.ApplicationLoaderListener.java
private void config() { LOG.info("NextReports Server " + ReleaseInfo.getVersion() + " starting ... "); CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try {/*w ww . j ava 2s. c o m*/ config.addConfiguration(new PropertiesConfiguration(getClass().getResource("/nextserver.properties"))); } catch (ConfigurationException e) { // TODO e.printStackTrace(); } File defaultNextServerHomeFolder = new File(System.getProperty("user.home"), ".nextserver"); String defaultNextServerHome = defaultNextServerHomeFolder.getPath(); String nextServerHome = config.getString("nextserver.home", defaultNextServerHome); LOG.info("nextserver.home = " + nextServerHome); String demo = System.getProperty("DEMO"); LOG.info("DEMO=" + demo); boolean installWithDemo = Boolean.valueOf(demo); File nextServerHomeFolder = new File(nextServerHome); if (!nextServerHomeFolder.exists()) { try { if (installWithDemo) { deployDemoData(nextServerHome); } else { if (LOG.isDebugEnabled()) { LOG.debug("Create nextserver home folder: '" + nextServerHomeFolder + "'"); } FileUtils.forceMkdir(nextServerHomeFolder); } } catch (IOException e) { // TODO e.printStackTrace(); } } System.setProperty("nextserver.home", nextServerHome); // File defaultJaspersHomeFolder = new File(nextServerHome, "jaspers"); // String defaultJaspersHome = defaultJaspersHomeFolder.getPath(); // String jaspersHome = config.getString("jaspers.home", defaultJaspersHome); // System.setProperty("jaspers.home", jaspersHome); // if (LOG.isDebugEnabled()) { // LOG.debug("jaspers.home = " + jaspersHome); // } // indexing.file ClassPathResource classPathResource = new ClassPathResource("indexing.xml"); String indexingFile = null; try { indexingFile = classPathResource.getFile().getAbsolutePath(); } catch (IOException e) { // TODO e.printStackTrace(); } System.setProperty("indexing.file", indexingFile); if (LOG.isDebugEnabled()) { LOG.debug("indexing.file = " + indexingFile); } // String baseUrl = config.getString("nextserver.baseUrl"); // String reportsUrl = config.getString("reports.url"); // if (LOG.isDebugEnabled()) { // LOG.debug("nextserver.baseUrl = " + baseUrl); // LOG.debug("reports.url = " + reportsUrl); // } }
From source file:tw.com.mt.DocAPIDemo.java
/** * Default constructor.//from w ww . j a v a 2s .c o m */ public DocAPIDemo() { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try { config.addConfiguration(new PropertiesConfiguration(propertyFile)); this.projObjKey = config.getInt("projObjKey"); this.parentObjKey = config.getInt("parentObjKey"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tw.com.mt.ObsAPIDemo.java
/** * Default constructor./*w w w . j a v a2 s .c om*/ */ public ObsAPIDemo() { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try { config.addConfiguration(new PropertiesConfiguration(propertyFile)); this.parentObjKey = config.getInt("parentObjKey"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tw.com.mt.TaskAPIDemo.java
/** * Default constructor./* ww w. j a v a 2 s.c om*/ */ public TaskAPIDemo() { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try { config.addConfiguration(new PropertiesConfiguration(propertyFile)); this.projObjKey = config.getInt("projObjKey"); this.parentObjKey = config.getInt("parentObjKey"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:tw.com.mt.TopicAPIDemo.java
/** * Default constructor.// w w w .j a v a2 s . com */ public TopicAPIDemo() { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); try { config.addConfiguration(new PropertiesConfiguration(propertyFile)); this.projObjKey = config.getInt("projObjKey"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }