Example usage for org.apache.commons.configuration Configuration isEmpty

List of usage examples for org.apache.commons.configuration Configuration isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Check if the configuration is empty.

Usage

From source file:nl.tudelft.graphalytics.configuration.GraphParser.java

private void parseEdgePropertiesConfiguration() throws InvalidConfigurationException {
    Configuration epConfig = config.subset("edge-properties");
    if (epConfig.isEmpty()) {
        edgeProperties = new PropertyList();
    } else {//from   w  ww  .  j  a v  a  2 s.  co  m
        edgeProperties = parsePropertyList(epConfig, "edge", name);
    }
}

From source file:org.apache.qpid.server.configuration.plugins.AbstractConfiguration.java

/** Helper method to print out list of keys in a {@link Configuration}. */
public static final void showKeys(Configuration config) {
    if (config.isEmpty()) {
        _logger.info("Configuration is empty");
    } else {/*w ww. jav  a  2  s  .c  o  m*/
        Iterator<?> keys = config.getKeys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            _logger.info("Configuration key: " + key);
        }
    }
}

From source file:org.apache.qpid.server.configuration.VirtualHostConfiguration.java

private static Configuration loadConfiguration(String name, File configurationFile)
        throws ConfigurationException {
    Configuration configuration = null;
    if (configurationFile == null) {
        throw new IllegalConfigurationException("Virtualhost configuration file must be supplied!");
    } else {/*from www .j  av a2s  .  c om*/
        Configuration virtualHostConfig = XmlConfigurationUtilities.parseConfig(configurationFile);

        // check if it is an old virtual host configuration file which has an element of the same name as virtual host
        Configuration config = virtualHostConfig
                .subset("virtualhost." + XmlConfigurationUtilities.escapeTagName(name));
        if (config.isEmpty()) {
            // assume it is a new configuration which does not have an element of the same name as the virtual host
            configuration = virtualHostConfig;
        } else {
            configuration = config;
        }
    }
    return configuration;
}

From source file:org.apache.samoa.topology.impl.StormSamoaUtils.java

public static Configuration getPropertyConfig(String configPropertyPath) {
    Configuration config = null;
    try {/*www.j av  a 2s.c  o  m*/
        config = new PropertiesConfiguration(configPropertyPath);
        if (null == config || config.isEmpty()) {
            logger.error("Configuration is null or empty at file  = {}", configPropertyPath);
            throw new RuntimeException("Configuration is null or empty : " + configPropertyPath);
        }
    } catch (ConfigurationException configurationException) {
        logger.error("ConfigurationException while reading property file = {}", configurationException);
        throw new RuntimeException(
                "ConfigurationException while reading property file : " + configPropertyPath);
    }
    return config;
}

From source file:org.apache.torque.dsfactory.AbstractDataSourceFactory.java

/**
 * Encapsulates setting configuration properties on
 * <code>DataSource</code> objects.
 *
 * @param property the property to read from the configuration
 * @param c the configuration to read the property from
 * @param ds the <code>DataSource</code> instance to write the property to
 * @throws Exception if anything goes wrong
 */// w  w w  .j  a va  2  s . co  m
protected void setProperty(String property, Configuration c, Object ds) throws Exception {
    if (c == null || c.isEmpty()) {
        return;
    }

    String key = property;
    Class<?> dsClass = ds.getClass();
    int dot = property.indexOf('.');
    try {
        if (dot > 0) {
            property = property.substring(0, dot);

            MappedPropertyDescriptor mappedPD = new MappedPropertyDescriptor(property, dsClass);
            Class<?> propertyType = mappedPD.getMappedPropertyType();
            Configuration subProps = c.subset(property);
            // use reflection to set properties
            Iterator<?> j = subProps.getKeys();
            while (j.hasNext()) {
                String subProp = (String) j.next();
                String propVal = subProps.getString(subProp);
                Object value = ConvertUtils.convert(propVal, propertyType);
                PropertyUtils.setMappedProperty(ds, property, subProp, value);

                if (log.isDebugEnabled()) {
                    log.debug(
                            "setMappedProperty(" + ds + ", " + property + ", " + subProp + ", " + value + ")");
                }
            }
        } else {
            if ("password".equals(key)) {
                // do not log value of password
                // for this, ConvertUtils.convert cannot be used
                // as it also logs the value of the converted property
                // so it is assumed here that the password is a String
                String value = c.getString(property);
                PropertyUtils.setSimpleProperty(ds, property, value);
                if (log.isDebugEnabled()) {
                    log.debug("setSimpleProperty(" + ds + ", " + property + ", " + " (value not logged)" + ")");
                }
            } else {
                Class<?> propertyType = PropertyUtils.getPropertyType(ds, property);
                Object value = ConvertUtils.convert(c.getString(property), propertyType);
                PropertyUtils.setSimpleProperty(ds, property, value);

                if (log.isDebugEnabled()) {
                    log.debug("setSimpleProperty(" + ds + ", " + property + ", " + value + ")");
                }
            }
        }
    } catch (RuntimeException e) {
        throw new TorqueRuntimeException("Runtime error setting property " + property, e);
    } catch (Exception e) {
        log.error("Property: " + property + " value: " + c.getString(key) + " is not supported by DataSource: "
                + ds.getClass().getName());
    }
}

From source file:org.apache.torque.dsfactory.AbstractDataSourceFactory.java

/**
 * Initializes the ConnectionPoolDataSource.
 *
 * @param configuration where to read the settings from
 * @throws TorqueException if a property set fails
 * @return a configured <code>ConnectionPoolDataSource</code>
 *//*  w w w  . j a v a2  s  .  c o  m*/
protected ConnectionPoolDataSource initCPDS(Configuration configuration) throws TorqueException {
    log.debug("Starting initCPDS");
    ConnectionPoolDataSource cpds = new DriverAdapterCPDS();
    Configuration c = Torque.getConfiguration();

    if (c == null || c.isEmpty()) {
        log.warn("Global Configuration not set," + " no Default connection pool data source configured!");
    } else {
        Configuration conf = c.subset(DEFAULT_CONNECTION_KEY);
        applyConfiguration(conf, cpds);
    }

    Configuration conf = configuration.subset(CONNECTION_KEY);
    applyConfiguration(conf, cpds);

    return cpds;
}

From source file:org.apache.torque.dsfactory.JndiDataSourceFactory.java

/**
 * Initializes JNDI./*  w w  w. j a v  a2s  .  co  m*/
 *
 * @param configuration where to read the settings from
 * @throws TorqueException if a property set fails
 */
private void initJNDI(Configuration configuration) throws TorqueException {
    log.debug("Starting initJNDI");

    Configuration c = configuration.subset(JNDI_KEY);
    if (c == null || c.isEmpty()) {
        throw new TorqueException(
                "JndiDataSourceFactory requires a jndi " + "path property to lookup the DataSource in JNDI.");
    }

    try {
        Hashtable<String, Object> env = new Hashtable<String, Object>();
        for (Iterator<?> i = c.getKeys(); i.hasNext();) {
            String key = (String) i.next();
            if (key.equals(PATH_KEY)) {
                path = c.getString(key);
                if (log.isDebugEnabled()) {
                    log.debug("JNDI path: " + path);
                }
            } else if (key.equals(TIME_BETWEEN_LOOKUPS_KEY)) {
                ttl = c.getLong(key, ttl);
                if (log.isDebugEnabled()) {
                    log.debug("Time between context lookups: " + ttl);
                }
            } else {
                String value = c.getString(key);
                env.put(key, value);
                if (log.isDebugEnabled()) {
                    log.debug("Set jndi property: " + key + "=" + value);
                }
            }
        }

        ctx = new InitialContext(env);
        log.debug("Created new InitialContext");
        debugCtx(ctx);
    } catch (Exception e) {
        log.error("", e);
        throw new TorqueException(e);
    }
}

From source file:org.apache.torque.dsfactory.PerUserPoolDataSourceFactory.java

/**
 * Initializes the Jdbc2PoolDataSource.//  w w w .  j  a  v  a2s . c om
 *
 * @param configuration where to read the settings from
 * @throws TorqueException if a property set fails
 * @return a configured <code>Jdbc2PoolDataSource</code>
 */
private PerUserPoolDataSource initJdbc2Pool(Configuration configuration) throws TorqueException {
    log.debug("Starting initJdbc2Pool");
    PerUserPoolDataSource dataSource = new PerUserPoolDataSource();
    Configuration c = Torque.getConfiguration();

    if (c == null || c.isEmpty()) {
        log.warn("Global Configuration not set," + " no Default pool data source configured!");
    } else {
        Configuration conf = c.subset(DEFAULT_POOL_KEY);
        applyConfiguration(conf, dataSource);
    }

    Configuration conf = configuration.subset(POOL_KEY);
    applyConfiguration(conf, dataSource);
    return dataSource;
}

From source file:org.apache.torque.dsfactory.SharedPoolDataSourceFactory.java

/**
 * Initializes the Jdbc2PoolDataSource./*from   w  w  w .ja v  a  2  s .  c  o m*/
 *
 * @param configuration where to read the settings from
 * @throws TorqueException if a property set fails
 * @return a configured <code>Jdbc2PoolDataSource</code>
 */
private SharedPoolDataSource initJdbc2Pool(Configuration configuration) throws TorqueException {
    log.debug("Starting initJdbc2Pool");
    SharedPoolDataSource dataSource = new SharedPoolDataSource();
    Configuration c = Torque.getConfiguration();

    if (c == null || c.isEmpty()) {
        log.warn("Global Configuration not set," + " no Default pool data source configured!");
    } else {
        Configuration conf = c.subset(DEFAULT_POOL_KEY);
        applyConfiguration(conf, dataSource);
    }

    Configuration conf = configuration.subset(POOL_KEY);
    applyConfiguration(conf, dataSource);
    return dataSource;
}

From source file:org.apache.torque.TorqueInstance.java

/**
 * Reads the adapter settings from the configuration and
 * assigns the appropriate database adapters and Id Generators
 * to the databases.// w  w w .ja va  2 s.  c  o  m
 *
 * @param conf the Configuration representing the torque section of the
 *        properties file.
 *
 * @throws TorqueException Any exceptions caught during processing will be
 *         rethrown wrapped into a TorqueException.
 */
private void initAdapters(Configuration conf) throws TorqueException {
    log.debug("initAdapters(" + conf + ")");

    Configuration c = conf.subset(Torque.DATABASE_KEY);
    if (c == null || c.isEmpty()) {
        String error = "Invalid configuration : " + "No keys starting with " + Torque.TORQUE_KEY + "."
                + Torque.DATABASE_KEY + " found in configuration";
        log.error(error);
        throw new TorqueException(error);
    }

    try {
        for (Iterator<?> it = c.getKeys(); it.hasNext();) {
            String key = (String) it.next();
            if (key.endsWith(Adapter.ADAPTER_KEY) || key.endsWith(Adapter.DRIVER_KEY)) {
                String adapterKey = c.getString(key);
                String handle = key.substring(0, key.indexOf('.'));

                Database database = getOrCreateDatabase(handle);
                Adapter adapter = null;

                if (StringUtils.equals(Adapter.AUTODETECT_ADAPTER, adapterKey)) {
                    Connection con = null;
                    try {
                        con = database.getDataSourceFactory().getDataSource().getConnection();
                        adapter = AdapterFactory.autoDetectAdapter(con);
                    } catch (SQLException e) {
                        log.error("Could not get product information from JDBC", e);
                    } finally {
                        closeConnection(con);
                    }
                } else {
                    adapter = AdapterFactory.create(adapterKey);
                }

                // Not supported, try manually defined adapter class
                if (adapter == null) {
                    String adapterClassName = c.getString(key + "." + adapterKey + ".className", null);
                    adapter = AdapterFactory.create(adapterKey, adapterClassName);
                }

                // register the adapter for this name
                database.setAdapter(adapter);
                log.debug("Adding " + adapterKey + " -> " + handle + " as Adapter");

                // add Id generators
                for (IDMethod idMethod : IDGeneratorFactory.ID_GENERATOR_METHODS) {
                    database.addIdGenerator(idMethod, IDGeneratorFactory.create(adapter, handle));
                }
            }
        }
    } catch (InstantiationException e) {
        log.error("Error creating a database adapter instance", e);
        throw new TorqueException(e);
    }

    // check that at least the default database has got an adapter.
    Database defaultDatabase = databases.get(getDefaultDB());
    if (defaultDatabase == null || defaultDatabase.getAdapter() == null) {
        String error = "Invalid configuration : " + "No adapter definition found for default DB "
                + "An adapter must be defined under " + Torque.TORQUE_KEY + "." + Torque.DATABASE_KEY + "."
                + getDefaultDB() + "." + Adapter.ADAPTER_KEY;
        log.error(error);
        throw new TorqueException(error);
    }
}