List of usage examples for org.apache.commons.configuration CompositeConfiguration addConfiguration
public void addConfiguration(Configuration config)
From source file:org.sonar.ant.Launcher.java
private Configuration getInitialConfiguration(ProjectDefinition project) { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(project.getProperties())); return configuration; }
From source file:org.sonar.batch.MavenProjectBuilder.java
Configuration getStartupConfiguration(MavenProject pom) { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(pom.getModel().getProperties())); return configuration; }
From source file:org.sonar.maven.SonarMojo.java
private Configuration getInitialConfiguration() { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(project.getModel().getProperties())); return configuration; }
From source file:org.sourceforge.net.javamail4ews.util.Util.java
public static Configuration getConfiguration(Session pSession) { try {//from ww w . j ava 2s.c om PropertiesConfiguration prop = new PropertiesConfiguration(); for (Object aKey : pSession.getProperties().keySet()) { Object aValue = pSession.getProperties().get(aKey); prop.addProperty(aKey.toString(), aValue); } CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(prop); URL lURL = Thread.currentThread().getContextClassLoader() .getResource("javamail-ews-bridge.default.properties"); config.addConfiguration(new PropertiesConfiguration(lURL)); return config; } catch (ConfigurationException e) { throw new RuntimeException(e.getMessage(), e); } }
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 *///w w w . j av a 2 s .c o m 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.plugins.ConfigurationPluginTest.java
@Override public void setUp() throws Exception { // Test does not directly use the AppRegistry but the configured broker // is required for the correct ConfigurationPlugin processing super.setUp(); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.addProperty("base.element[@property]", "property"); xmlconfig.addProperty("base.element.name", "name"); // We make these strings as that is how they will be read from the file. xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG)); xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG)); xmlconfig.addProperty("base.element.boolean", String.valueOf(true)); xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE)); for (int i = 0; i < LIST_SIZE; i++) { xmlconfig.addProperty("base.element.list", i); }/* w ww .jav a 2s . c o m*/ //Use a composite configuration as this is what our broker code uses. CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(xmlconfig); _plugin = new ConfigPlugin(); try { _plugin.setConfiguration("base.element", composite.subset("base.element")); } catch (ConfigurationException e) { e.printStackTrace(); fail(e.toString()); } }
From source file:org.wso2.andes.configuration.qpid.QueueConfiguration.java
public QueueConfiguration(String name, VirtualHostConfiguration virtualHostConfiguration) throws ConfigurationException { _vHostConfig = virtualHostConfiguration; _name = name;/*from ww w.j a va 2 s. c om*/ CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + name)); mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues")); setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf); }
From source file:org.wso2.andes.configuration.qpid.QueueConfigurationTest.java
private VirtualHostConfiguration overrideConfiguration(String property, int value) throws ConfigurationException { PropertiesConfiguration queueConfig = new PropertiesConfiguration(); queueConfig.setProperty("queues.queue.test." + property, value); CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(_fullHostConf.getConfig()); config.addConfiguration(queueConfig); return new VirtualHostConfiguration("test", config); }
From source file:org.wso2.andes.configuration.qpid.VirtualHostConfiguration.java
/** * Apply the given configuration to this VirtualHostConfiguration * * @param config/* ww w . j av a 2 s.c om*/ * the config to apply * @throws ConfigurationException * if a problem occurs with configuration */ public void setConfiguration(Configuration config) throws ConfigurationException { setConfiguration("virtualhosts.virtualhost", config); Iterator i = getListValue("queues.queue.name").iterator(); while (i.hasNext()) { String queueName = (String) i.next(); _queues.put(queueName, new QueueConfiguration(queueName, this)); } i = getListValue("exchanges.exchange.name").iterator(); int count = 0; while (i.hasNext()) { CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(config.subset("exchanges.exchange(" + count++ + ")")); mungedConf.addConfiguration(_configuration.subset("exchanges")); String exchName = (String) i.next(); _exchanges.put(exchName, new ExchangeConfiguration(exchName, mungedConf)); } }
From source file:org.wso2.andes.configuration.qpid.VirtualHostConfiguration.java
public ConfigurationPlugin getQueueConfiguration(AMQQueue queue) { VirtualHostConfiguration hostConfig = queue.getVirtualHost().getConfiguration(); // First check if we have a named queue configuration (the easy case) if (Arrays.asList(hostConfig.getQueueNames()).contains(queue.getName())) { return null; }//w w w .j a v a 2s . c o m // We don't have an explicit queue config we must find out what we need. ArrayList<Binding> bindings = new ArrayList<Binding>(queue.getBindings()); List<AMQShortString> exchangeClasses = new ArrayList<AMQShortString>(bindings.size()); //Remove default exchange for (int index = 0; index < bindings.size(); index++) { // Ignore the DEFAULT Exchange binding if (bindings.get(index).getExchange().getNameShortString() .equals(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)) { bindings.remove(index); } else { exchangeClasses.add(bindings.get(index).getExchange().getType().getName()); if (exchangeClasses.size() > 1) { // If we have more than 1 class of exchange then we can only use the global // queue configuration. // and this will be returned from the default getQueueConfiguration return null; } } } // If we are just bound the the default exchange then use the default. if (bindings.isEmpty()) { return null; } // If we are bound to only one type of exchange then we are going // to have to resolve the configuration for that exchange. String exchangeName = bindings.get(0).getExchange().getType().getName().toString(); // Lookup a Configuration handler for this Exchange. // Build the expected class name. <Exchangename>sConfiguration // i.e. TopicConfiguration or HeadersConfiguration String exchangeClass = "org.wso2.andes.configuration.qpid." + exchangeName.substring(0, 1).toUpperCase() + exchangeName.substring(1) + "Configuration"; ExchangeConfigurationPlugin exchangeConfiguration = (ExchangeConfigurationPlugin) queue.getVirtualHost() .getConfiguration().getConfiguration(exchangeClass); // now need to perform the queue-topic-topics-queues magic. // So make a new ConfigurationObject that will hold all the configuration for this queue. ConfigurationPlugin queueConfig = new QueueConfiguration.QueueConfig(); // Initialise the queue with any Global values we may have PropertiesConfiguration newQueueConfig = new PropertiesConfiguration(); newQueueConfig.setProperty("name", queue.getName()); try { //Set the queue name CompositeConfiguration mungedConf = new CompositeConfiguration(); //Set the queue name mungedConf.addConfiguration(newQueueConfig); //Set the global queue configuration mungedConf.addConfiguration(getConfig().subset("queues")); // Set configuration queueConfig.setConfiguration("virtualhosts.virtualhost.queues", mungedConf); } catch (ConfigurationException e) { // This will not occur as queues only require a name. _logger.error("QueueConfiguration requirements have changed.", e); } // Merge any configuration the Exchange wishes to apply if (exchangeConfiguration != null) { queueConfig.addConfiguration(exchangeConfiguration.getConfiguration(queue)); } //Finally merge in any specific queue configuration we have. if (_queues.containsKey(queue.getName())) { queueConfig.addConfiguration(_queues.get(queue.getName())); } return queueConfig; }