Example usage for org.apache.commons.configuration ConfigurationUtils toString

List of usage examples for org.apache.commons.configuration ConfigurationUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationUtils toString.

Prototype

public static String toString(Configuration configuration) 

Source Link

Document

Get a string representation of the key/value mappings of a configuration.

Usage

From source file:org.apache.james.protocols.lib.ProtocolHandlerChainImpl.java

public void init() throws Exception {
    List<org.apache.commons.configuration.HierarchicalConfiguration> children = handlerchainConfig
            .configurationsAt("handler");

    // check if the coreHandlersPackage was specified in the config, if
    // not add the default
    if (handlerchainConfig.getString("[@coreHandlersPackage]") == null)
        handlerchainConfig.addProperty("[@coreHandlersPackage]", coreHandlersPackage);

    String coreHandlersPackage = handlerchainConfig.getString("[@coreHandlersPackage]");

    if (handlerchainConfig.getString("[@jmxHandlersPackage]") == null)
        handlerchainConfig.addProperty("[@jmxHandlersPackage]", jmxHandlersPackage);

    String jmxHandlersPackage = handlerchainConfig.getString("[@jmxHandlersPackage]");

    HandlersPackage handlersPackage = (HandlersPackage) loader.load(coreHandlersPackage,
            addHandler(coreHandlersPackage));
    registerHandlersPackage(handlersPackage, null, children);

    if (handlerchainConfig.getBoolean("[@enableJmx]", true)) {
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        builder.addProperty("jmxName", jmxName);
        HandlersPackage jmxPackage = (HandlersPackage) loader.load(jmxHandlersPackage,
                addHandler(jmxHandlersPackage));

        registerHandlersPackage(jmxPackage, builder, children);
    }//from   ww w.j  a va  2  s  . co m

    for (HierarchicalConfiguration hConf : children) {
        String className = hConf.getString("[@class]", null);
        if (className != null) {
            handlers.add(loader.load(className, hConf));
        } else {
            throw new ConfigurationException(
                    "Missing @class attribute in configuration: " + ConfigurationUtils.toString(hConf));
        }
    }
    wireExtensibleHandlers();

}

From source file:org.apache.s4.example.fluent.counter.Module.java

private void loadProperties(Binder binder) {

    try {/*from   w  w  w  .  j  av a2  s.c o m*/
        InputStream is = this.getClass().getResourceAsStream("/s4-counter-example.properties");
        config = new PropertiesConfiguration();
        config.load(is);

        System.out.println(ConfigurationUtils.toString(config));
        // TODO - validate properties.

        /* Make all properties injectable. Do we need this? */
        Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
    } catch (ConfigurationException e) {
        binder.addError(e);
        e.printStackTrace();
    }
}

From source file:org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShimServiceLoader.java

/**
 * Return a reference to the shim service.  This method may return a cached shim service
 * unless {@code forceReload} is true.  Calls to this method need not be externally
 * synchonized./*  ww w . ja  va 2  s  .c  o  m*/
 *
 * @param forceReload if false, this method may use its internal service cache; if true,
 *                    this method must ignore cache, and it must invoke {@link ServiceLoader#reload()}
 *                    before selecting a new service to return
 * @return the shim service
 */
private static KryoShimService load(final boolean forceReload) {
    // if the service is loaded and doesn't need reloading, simply return in
    if (null != cachedShimService && !forceReload)
        return cachedShimService;

    // if a service is already loaded, close it
    if (null != cachedShimService)
        cachedShimService.close();

    // if the configuration is null, try and load the configuration from System.properties
    if (null == configuration)
        configuration = SystemUtil.getSystemPropertiesConfiguration("tinkerpop", true);

    // get all of the shim services
    final ArrayList<KryoShimService> services = new ArrayList<>();
    final ServiceLoader<KryoShimService> serviceLoader = ServiceLoader.load(KryoShimService.class);
    synchronized (KryoShimServiceLoader.class) {
        if (forceReload)
            serviceLoader.reload();
        for (final KryoShimService kss : serviceLoader) {
            services.add(kss);
        }
    }
    // if a shim service class is specified in the configuration, use it -- else, priority-based
    if (configuration.containsKey(KRYO_SHIM_SERVICE)) {
        for (final KryoShimService kss : services) {
            if (kss.getClass().getCanonicalName().equals(configuration.getString(KRYO_SHIM_SERVICE))) {
                log.info("Set KryoShimService to {} because of configuration {}={}",
                        kss.getClass().getSimpleName(), KRYO_SHIM_SERVICE,
                        configuration.getString(KRYO_SHIM_SERVICE));
                cachedShimService = kss;
                break;
            }
        }
    } else {
        Collections.sort(services, KryoShimServiceComparator.INSTANCE);
        for (final KryoShimService kss : services) {
            log.debug("Found KryoShimService: {} (priority {})", kss.getClass().getCanonicalName(),
                    kss.getPriority());
        }
        if (0 != services.size()) {
            cachedShimService = services.get(services.size() - 1);
            log.info("Set KryoShimService to {} because its priority value ({}) is the best available",
                    cachedShimService.getClass().getSimpleName(), cachedShimService.getPriority());
        }
    }

    // no shim service was available
    if (null == cachedShimService)
        throw new IllegalStateException("Unable to load KryoShimService");

    // once the shim service is defined, configure it
    log.info(
            "Configuring KryoShimService {} with the following configuration:\n#######START########\n{}\n########END#########",
            cachedShimService.getClass().getCanonicalName(), ConfigurationUtils.toString(configuration));
    cachedShimService.applyConfiguration(configuration);
    return cachedShimService;
}

From source file:org.eurocarbdb.dataaccess.Eurocarb.java

static void initConfig() {
    //if ( config == null )
    config = new CompositeConfiguration();

    try {/*  w  ww.j  a v  a 2 s .  c  om*/
        // log.info("adding configuration: " + EUROCARB_OVERRIDES_CONF );
        // config.addConfiguration( 
        //     new PropertiesConfiguration( EUROCARB_OVERRIDES_CONF ) );
        // log.info( "configured properties for core-api: \n" 
        //     + ConfigurationUtils.toString( config ) );

        log.info("adding core-api configuration: " + EUROCARB_CONF);
        config.addConfiguration(new PropertiesConfiguration(EUROCARB_CONF));
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }

    if (log.isInfoEnabled()) {
        log.info(CR + repeat('=', 20) + " configured eurocarb core-api properties " + repeat('=', 20) + CR
                + ConfigurationUtils.toString(config) + CR + repeat('=', 80));
    }

}

From source file:org.eurocarbdb.servlet.init.EurocarbApplicationContextHandler.java

/**
*   Loads the main application properties file, given by {@link ECDB_APP_PROPERTIES_FILE}.
*   Note that core-api properties take precedence over application properties;
*   ideally there shouldn't be any property name collisions in the first place.
*//*from  w w  w . ja va  2 s  . co m*/
protected void initConfig() {
    //  need to call getConfiguration before adding our config so 
    //  that core-api config gets initialised and logged first. 
    CompositeConfiguration config = Eurocarb.getConfiguration();

    log.info("adding eurocarbdb application configuration: " + ECDB_APP_PROPERTIES_FILE);
    try {
        config.addConfiguration(new PropertiesConfiguration(ECDB_APP_PROPERTIES_FILE));
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }

    if (log.isInfoEnabled()) {
        log.info("Configured eurocarb-application properties:\n" + CR + ConfigurationUtils.toString(config));
    }
}