Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.CompositeConfiguration


public abstract class AbstractConfiguration {
    protected CompositeConfiguration conf;

    protected AbstractConfiguration() {
        conf = new CompositeConfiguration();
    }
View Full Code Here


    @Override
    public void validateConfiguration() throws ConfigurationException
    {
        // Valid Configuration either has xml links to new files
        _finalConfig = new CompositeConfiguration(getConfig());
        List subFiles = getConfig().getList("xml[@fileName]");
        for (Object subFile : subFiles)
        {
            _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
        }
View Full Code Here

    @Override
    public void validateConfiguration() throws ConfigurationException
    {
        // Valid Configuration either has xml links to new files
        _finalConfig = new CompositeConfiguration(getConfig());
        List subFiles = getConfig().getList("xml[@fileName]");
        for (Object subFile : subFiles)
        {
            _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
        }
View Full Code Here

        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(getConfig().subset("exchanges"));
            String exchName = (String) i.next();
            _exchanges.put(exchName, new ExchangeConfiguration(exchName, mungedConf));
        }
    }
View Full Code Here

        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)
View Full Code Here

    public QueueConfiguration(String name, VirtualHostConfiguration virtualHostConfiguration) throws ConfigurationException
    {
        _vHostConfig = virtualHostConfiguration;
        _name = name;

        CompositeConfiguration mungedConf = new CompositeConfiguration();
        mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + name));
        mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues"));

        setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf);
    }
View Full Code Here

    @Override
    public void validateConfiguration() throws ConfigurationException
    {
        // Valid Configuration either has xml links to new files
        _finalConfig = new CompositeConfiguration(getConfig());
        List subFiles = getConfig().getList("xml[@fileName]");
        for (Object subFile : subFiles)
        {
            _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
        }
View Full Code Here

   * @return a Guice module configured with setting support.
   * @throws ConfigurationException on configuration error
   */
  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));
View Full Code Here

    public FileServer() {
        org.apache.log4j.PropertyConfigurator.configure("config/logging.properties");

        try {
            config = new CompositeConfiguration();
            config.addConfiguration(new SystemConfiguration());
            config.addConfiguration(new PropertiesConfiguration("config/server.properties"));

            final String data = config.getString("fileserver.data");
            final String services = config.getString("fileserver.services");
View Full Code Here

                    config.addProperty(entry.getKey(), entry.getValue());
                }
            }
            basicConfiguration.addConfiguration(config);

            CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
            compositeConfiguration.addConfiguration(new SystemConfiguration());
            compositeConfiguration.addConfiguration(basicConfiguration);
            configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration , _broker);
        }
        else
        {
            if (!new File(configurationFile).exists())
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.CompositeConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.