List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration
public CompositeConfiguration()
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.sonar.server.database.EmbeddedDatabaseTest.java
@Override protected void setUp() throws Exception { windowsCleanup();//from w w w.ja va2 s . c o m if (testPort == null) { testPort = Integer.toString(findFreeServerPort()); } defaultProps = EmbeddedDatabase.getDefaultProperties(new CompositeConfiguration()); defaultProps.put("derby.drda.portNumber", testPort); // changing the defaut port driverUrl = "jdbc:derby://localhost:" + testPort + "/sonar;create=true;user=sonar;password=sonar"; }
From source file:org.sourceforge.net.javamail4ews.util.Util.java
public static Configuration getConfiguration(Session pSession) { try {/*w w w . j av a 2s. c o m*/ 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 *//*from w w w .ja va 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.AndesConfigurationManager.java
/** * initialize the configuration manager. this MUST be called at application startup. * (QpidServiceComponent bundle -> activate event) * * @throws AndesException/*from w w w.j a va 2s . c o m*/ */ public static void initialize(int portOffset) throws AndesException { String ROOT_CONFIG_FILE_PATH; // If system property is available set conf path to that value if (componentsPath != null) { ROOT_CONFIG_FILE_PATH = Paths.get(componentsPath).toString(); } else { ROOT_CONFIG_FILE_PATH = Paths.get(System.getProperty(CARBON_HOME), "repository", "conf").toString(); } String brokerConfigFilePath = ROOT_CONFIG_FILE_PATH + File.separator + ROOT_CONFIG_FILE_NAME; log.info("Main andes configuration located at : " + brokerConfigFilePath); try { compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.setDelimiterParsingDisabled(true); XMLConfiguration rootConfiguration = new XMLConfiguration(); rootConfiguration.setDelimiterParsingDisabled(true); rootConfiguration.setFileName(brokerConfigFilePath); rootConfiguration.setExpressionEngine(new XPathExpressionEngine()); rootConfiguration.load(); compositeConfiguration.addConfiguration(rootConfiguration); //Decrypt and maintain secure vault property values in a map for cross-reference. decryptConfigurationFromFile(brokerConfigFilePath); // Derive certain special properties that are not simply specified in the configuration files. addDerivedProperties(); // set carbonPortOffset coming from carbon AndesConfigurationManager.carbonPortOffset = portOffset; //set delivery timeout for a message int deliveryTimeoutForMessage = AndesConfigurationManager .readValue(AndesConfiguration.PERFORMANCE_TUNING_TOPIC_MESSAGE_DELIVERY_TIMEOUT); AndesContext.getInstance().setDeliveryTimeoutForMessage(deliveryTimeoutForMessage); } catch (ConfigurationException e) { String error = "Error occurred when trying to construct configurations from file at path : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (UnknownHostException e) { String error = "Error occurred when trying to derive the bind address for messaging from configurations."; log.error(error, e); throw new AndesException(error, e); } catch (FileNotFoundException e) { String error = "Error occurred when trying to read the configuration file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (JaxenException e) { String error = "Error occurred when trying to process cipher text in file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } catch (XMLStreamException e) { String error = "Error occurred when trying to process cipher text in file : " + brokerConfigFilePath; log.error(error, e); throw new AndesException(error, e); } }
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); }//from w w w. j a v a 2 s .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;/* w w w . j ava2s . co m*/ 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//w w w.ja v a 2 s .c o m * 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 ava 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; }