Example usage for org.apache.commons.configuration2 Configuration getClass

List of usage examples for org.apache.commons.configuration2 Configuration getClass

Introduction

In this page you can find the example usage for org.apache.commons.configuration2 Configuration getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.dspace.app.rest.utils.DSpaceConfigurationInitializer.java

@Override
public void initialize(final ConfigurableApplicationContext applicationContext) {
    // Load DSpace Configuration service (requires kernel already initialized)
    ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
    Configuration configuration = configurationService.getConfiguration();

    // Create an Apache Commons Configuration Property Source from our configuration
    ConfigurationPropertySource apacheCommonsConfigPropertySource = new ConfigurationPropertySource(
            configuration.getClass().getName(), configuration);

    // Append it to the Environment's list of PropertySources
    applicationContext.getEnvironment().getPropertySources().addLast(apacheCommonsConfigPropertySource);
}

From source file:org.dspace.servicemanager.config.DSpaceConfigurationPlaceholderConfigurer.java

public DSpaceConfigurationPlaceholderConfigurer(Configuration configuration) {
    ConfigurationPropertySource apacheCommonsConfigPropertySource = new ConfigurationPropertySource(
            configuration.getClass().getName(), configuration);
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(apacheCommonsConfigPropertySource);
    setPropertySources(propertySources);
}

From source file:org.powertac.common.config.Configurator.java

private Object extractConfigValue(Configuration conf, String key, String type, Object defaultValue)
        throws ClassNotFoundException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
        InvocationTargetException {
    if (type.equals("List")) {
        // the list type does not always work for some reason,
        // and type-checking is getting really annoying here
        List<String> def = new ArrayList<String>();
        if (null != defaultValue)
            for (Object thing : (List<?>) defaultValue)
                def.add((String) thing);
        return conf.getList(key, def);
    } else {//  www .  j av a  2s  . co  m
        // do it by reflection
        Class<?> clazz = findNamedClass(type);
        String extractorName = "get" + type;
        Method extractor = conf.getClass().getMethod(extractorName, String.class, clazz);
        //log.info("Extract " + conf.getClass().getName() + "." + extractorName
        //         + "(" + clazz.getName() + ")");
        return extractor.invoke(conf, key, defaultValue);
    }
}