Search in sources :

Example 1 with PropertyFileConfig

use of org.apache.deltaspike.core.api.config.PropertyFileConfig in project crnk-framework by crnk-project.

the class GeneratorConfigSourceProvider method registerPropertyFileConfigs.

/**
 * Load all {@link PropertyFileConfig}s which are registered via
 * {@code java.util.ServiceLoader}.
 */
private void registerPropertyFileConfigs() {
    List<? extends PropertyFileConfig> propertyFileConfigs = ServiceUtils.loadServiceImplementations(PropertyFileConfig.class);
    for (PropertyFileConfig propertyFileConfig : propertyFileConfigs) {
        EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName(), propertyFileConfig.isOptional());
        configSources.addAll(environmentPropertyConfigSourceProvider.getConfigSources());
    }
}
Also used : PropertyFileConfig(org.apache.deltaspike.core.api.config.PropertyFileConfig)

Example 2 with PropertyFileConfig

use of org.apache.deltaspike.core.api.config.PropertyFileConfig in project deltaspike by apache.

the class ConfigurationExtension method createPropertyConfigSource.

/**
 * @return create an instance of the given {@link PropertyFileConfig} and return all it's ConfigSources.
 */
private List<ConfigSource> createPropertyConfigSource(Class<? extends PropertyFileConfig> propertyFileConfigClass) {
    String fileName = "";
    try {
        PropertyFileConfig propertyFileConfig = propertyFileConfigClass.newInstance();
        fileName = propertyFileConfig.getPropertyFileName();
        EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(fileName, propertyFileConfig.isOptional());
        return environmentPropertyConfigSourceProvider.getConfigSources();
    } catch (InstantiationException e) {
        throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(CANNOT_CREATE_CONFIG_SOURCE_FOR_CUSTOM_PROPERTY_FILE_CONFIG + propertyFileConfigClass.getName(), e);
    } catch (IllegalStateException e) {
        throw new IllegalStateException(propertyFileConfigClass.getName() + " points to an invalid file: '" + fileName + "'", e);
    }
}
Also used : PropertyFileConfig(org.apache.deltaspike.core.api.config.PropertyFileConfig)

Example 3 with PropertyFileConfig

use of org.apache.deltaspike.core.api.config.PropertyFileConfig in project deltaspike by apache.

the class DefaultConfigSourceProvider method registerPropertyFileConfigs.

/**
 * Load all {@link PropertyFileConfig}s which are registered via
 * {@code java.util.ServiceLoader}.
 */
private void registerPropertyFileConfigs() {
    List<? extends PropertyFileConfig> propertyFileConfigs = ServiceUtils.loadServiceImplementations(PropertyFileConfig.class);
    for (PropertyFileConfig propertyFileConfig : propertyFileConfigs) {
        EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName(), propertyFileConfig.isOptional());
        configSources.addAll(environmentPropertyConfigSourceProvider.getConfigSources());
    }
}
Also used : PropertyFileConfig(org.apache.deltaspike.core.api.config.PropertyFileConfig)

Example 4 with PropertyFileConfig

use of org.apache.deltaspike.core.api.config.PropertyFileConfig in project deltaspike by apache.

the class ConfigurationExtension method registerUserConfigSources.

@SuppressWarnings("UnusedDeclaration")
public void registerUserConfigSources(@Observes AfterDeploymentValidation adv) {
    if (!isActivated) {
        return;
    }
    // create a local copy with all the collected PropertyFileConfig
    Set<Class<? extends PropertyFileConfig>> allPropertyFileConfigClasses = new HashSet<Class<? extends PropertyFileConfig>>(this.propertyFileConfigClasses);
    // now add any PropertyFileConfigs from a 'parent BeanManager'
    // we start with the current TCCL
    ClassLoader currentClassLoader = ClassUtils.getClassLoader(null);
    addParentPropertyFileConfigs(currentClassLoader, allPropertyFileConfigClasses);
    // because maybe WE are a parent BeanManager ourselves!
    if (!this.propertyFileConfigClasses.isEmpty()) {
        detectedParentPropertyFileConfigs.put(currentClassLoader, this.propertyFileConfigClasses);
    }
    // collect all the ConfigSources from our PropertyFileConfigs
    List<ConfigSource> configSources = new ArrayList<ConfigSource>();
    for (Class<? extends PropertyFileConfig> propertyFileConfigClass : allPropertyFileConfigClasses) {
        configSources.addAll(createPropertyConfigSource(propertyFileConfigClass));
    }
    for (final Bean bean : cdiSources) {
        configSources.add(BeanProvider.getContextualReference(ConfigSource.class, bean));
    }
    // finally add all
    ConfigResolver.addConfigSources(configSources);
    for (final Bean bean : cdiFilters) {
        ConfigResolver.addConfigFilter(BeanProvider.getContextualReference(ConfigFilter.class, bean));
    }
    processConfigurationValidation(adv);
    registerConfigMBean();
    logConfiguration();
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) ArrayList(java.util.ArrayList) PropertyFileConfig(org.apache.deltaspike.core.api.config.PropertyFileConfig) HashSet(java.util.HashSet) ProcessBean(javax.enterprise.inject.spi.ProcessBean) Bean(javax.enterprise.inject.spi.Bean) ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Aggregations

PropertyFileConfig (org.apache.deltaspike.core.api.config.PropertyFileConfig)4 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Bean (javax.enterprise.inject.spi.Bean)1 ProcessBean (javax.enterprise.inject.spi.ProcessBean)1 ConfigFilter (org.apache.deltaspike.core.spi.config.ConfigFilter)1 ConfigSource (org.apache.deltaspike.core.spi.config.ConfigSource)1