• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConfigResolver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.deltaspike.core.api.config.ConfigResolver的典型用法代码示例。如果您正苦于以下问题:Java ConfigResolver类的具体用法?Java ConfigResolver怎么用?Java ConfigResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConfigResolver类属于org.apache.deltaspike.core.api.config包,在下文中一共展示了ConfigResolver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: hola

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@GET
@Path("/hola")
@Produces("text/plain")
@ApiOperation("Returns the greeting in Spanish")
public String hola() {
    String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
    String translation = ConfigResolver
        .resolve("hello")
        .withDefault("Hola de %s")
        .logChanges(true)
        // 5 Seconds cache only for demo purpose
        .cacheFor(TimeUnit.SECONDS, 5)
        .getValue();
    return String.format(translation, hostname);

}
 
开发者ID:redhat-helloworld-msa,项目名称:hola,代码行数:17,代码来源:HolaResource.java


示例2: setServletConfig

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private void setServletConfig(ServletConfigSource configSource, ServletContextEvent sce)
{
    ServletContext servletContext = sce.getServletContext();
    String servletContextName = servletContext.getServletContextName();
    if (servletContextName != null && servletContextName.length() > 0)
    {
        String oldAppName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG);

        // we first need to unregister the old MBean
        // as we don't know whether the CDI Extension or the Servlet Listener comes first.
        // It's simply not defined by the spec :/
        ConfigurationExtension.unRegisterConfigMBean(oldAppName);

        configSource.setPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG, servletContextName);

        // and as we now did set the new name -> register again:
        ConfigurationExtension.registerConfigMBean();
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:ServletConfigListener.java


示例3: getEntityManagerFactoryConfiguration

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Override
public Properties getEntityManagerFactoryConfiguration(String persistenceUnitName)
{
    Properties unitProperties = PropertyLoader.getProperties("persistence-" + persistenceUnitName);

    if (unitProperties == null)
    {
        unitProperties = new Properties();
    }

    // apply ConfigFilters to the configured values.
    for (Map.Entry entry : unitProperties.entrySet())
    {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        entry.setValue(ConfigResolver.filterConfigValue(key, value));
    }

    unitProperties = addConfigProperties(unitProperties, persistenceUnitName);

    // add spec expected attributes
    unitProperties.put("javax.persistence.bean.manager", BeanManagerProvider.getInstance().getBeanManager());

    return unitProperties;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:27,代码来源:PersistenceConfigurationProviderImpl.java


示例4: addConfigProperties

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
/**
 * Load additional configuration from the Configuration system
 * and overload the basic settings with that info.
 *
 * The key is deltaspike.persistence.config.${persistenceUnitName}.${originalKey}
 *
 * @see #CONFIG_PREFIX
 * @since 1.8.0
 */
protected Properties addConfigProperties(Properties unitProperties, String persistenceUnitName)
{
    // we start with a copy of the original properties
    Properties mergedConfig = new Properties();
    mergedConfig.putAll(unitProperties);

    Set<String> allConfigKeys = ConfigResolver.getAllProperties().keySet();
    String unitPrefix = CONFIG_PREFIX + persistenceUnitName + ".";
    for (String configKey : allConfigKeys)
    {
        if (configKey.startsWith(unitPrefix))
        {
            mergedConfig.put(configKey.substring(unitPrefix.length()),
                    ConfigResolver.getProjectStageAwarePropertyValue(configKey));
        }
    }

    return mergedConfig;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:29,代码来源:PersistenceConfigurationProviderImpl.java


示例5: evaluateExpression

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private String evaluateExpression(Scheduled scheduled)
{
    String expression = scheduled.cronExpression();

    if (expression.startsWith("{") && expression.endsWith("}"))
    {
        String configKey = expression.substring(1, expression.length() - 1);
        expression = ConfigResolver.getProjectStageAwarePropertyValue(configKey, null);

        if (expression == null)
        {
            throw new IllegalStateException("No config-value found for config-key: " + configKey);
        }
    }
    return expression;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:AbstractQuartzScheduler.java


示例6: asResolver

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
public <T> ConfigResolver.TypedResolver<T> asResolver(final String key, final String stringDefault,
                                                      final Type ipCls,
                                                      final Class<? extends ConfigResolver.Converter> converterType,
                                                      final String parameterizedBy,
                                                      final boolean projectStageAware, final boolean evaluate)
{
    final ConfigResolver.UntypedResolver<String> untypedResolver = ConfigResolver.resolve(key);
    final ConfigResolver.TypedResolver<T> resolver =
            (ConfigResolver.Converter.class == converterType ?
                    untypedResolver.as(Class.class.cast(ipCls)) :
                    untypedResolver.as(ipCls, BeanProvider.getContextualReference(converterType)))
                    .withCurrentProjectStage(projectStageAware);
    if (!ConfigProperty.NULL.equals(stringDefault))
    {
        resolver.withStringDefault(stringDefault);
    }
    if (!ConfigProperty.NULL.equals(parameterizedBy))
    {
        resolver.parameterizedBy(parameterizedBy);
    }
    return resolver.evaluateVariables(evaluate);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:23,代码来源:BaseConfigPropertyProducer.java


示例7: resolveProjectStage

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
/**
 * Resolves the project-stage configured for DeltaSpike
 * @return the resolved {@link ProjectStage} or <code>null</code> if none defined.
 */
protected ProjectStage resolveProjectStage()
{
    for (String configLocation : CONFIG_SETTING_KEYS)
    {
        String stageName = ConfigResolver.getPropertyValue(configLocation);

        if (stageName != null && !stageName.isEmpty())
        {
            return ProjectStage.valueOf(stageName);
        }

    }

    return null;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:ProjectStageProducer.java


示例8: testValidTypes

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testValidTypes()
{
    Assert.assertEquals("configured", ConfigResolver.resolve("deltaspike.test.string-value").getValue());

    Assert.assertEquals(Boolean.FALSE, ConfigResolver.resolve("deltaspike.test.boolean-value").as(Boolean.class)
            .getValue());

    Assert.assertEquals(TestConfigSource.class, ConfigResolver.resolve("deltaspike.test.class-value").as(Class
            .class).getValue());

    Assert.assertEquals(5l, (int) ConfigResolver.resolve("deltaspike.test.integer-value").as(Integer.class)
            .getValue());

    Assert.assertEquals(8589934592l, (long) ConfigResolver.resolve("deltaspike.test.long-value").as(Long.class)
            .getValue());

    Assert.assertEquals(-1.1f, (float) ConfigResolver.resolve("deltaspike.test.float-value").as(Float.class)
            .getValue(), 0);

    Assert.assertEquals(4e40d, (double) ConfigResolver.resolve("deltaspike.test.double-value").as(Double.class)
            .getValue(), 0);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:24,代码来源:TypedResolverTest.java


示例9: testProjectStageAware

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testProjectStageAware()
{
    Assert.assertEquals("unittestvalue",
            ConfigResolver.resolve("testkey")
                    .withCurrentProjectStage(true)
                    .getValue());

    Assert.assertEquals("testvalue",
            ConfigResolver.resolve("testkey")
                    .withCurrentProjectStage(false)
                    .getValue());

    // property without PS, with PS-aware
    Assert.assertEquals("testvalue",
            ConfigResolver.resolve("testkey2")
                    .withCurrentProjectStage(true)
                    .getValue());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:TypedResolverTest.java


示例10: testStrict

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testStrict()
{
    Assert.assertEquals("TestDataSource",
            ConfigResolver.resolve("dataSource")
                    .withCurrentProjectStage(true)
                    .parameterizedBy("dbvendor")
                    .strictly(true)
                    .getValue());

    // no base.param, no value for base.param.ps
    Assert.assertEquals(null,
            ConfigResolver.resolve("dataSource")
                    .withCurrentProjectStage(true)
                    .parameterizedBy("dbvendor3")
                    .strictly(true)
                    .getValue());

    // valid base.param, but no base.param.ps
    Assert.assertEquals(null,
            ConfigResolver.resolve("dataSource")
                    .withCurrentProjectStage(true)
                    .parameterizedBy("dbvendor2")
                    .strictly(true)
                    .getValue());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:27,代码来源:TypedResolverTest.java


示例11: testGets

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testGets()
{
    ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve("dataSource")
            .withCurrentProjectStage(true)
            .parameterizedBy("dbvendor")
            .withDefault("TESTDEFAULT");

    Assert.assertEquals("TestDataSource", resolver.getValue());
    Assert.assertEquals("dataSource", resolver.getKey());
    Assert.assertEquals("TESTDEFAULT", resolver.getDefaultValue());
    Assert.assertEquals("dataSource.mysql.UnitTest", resolver.getResolvedKey());


    ConfigResolver.TypedResolver<String> resolver2 = ConfigResolver.resolve("testkey2")
            .withCurrentProjectStage(true)
            .parameterizedBy("INVALIDPARAMETER");


    Assert.assertEquals("testvalue", resolver2.getValue());
    Assert.assertEquals("testkey2", resolver2.getResolvedKey());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:23,代码来源:TypedResolverTest.java


示例12: testWithCacheTime

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testWithCacheTime() throws Exception
{
    ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve("dataSource")
        .withCurrentProjectStage(true)
        .parameterizedBy("dbvendor")
        .cacheFor(TimeUnit.MILLISECONDS, 5)
        .withDefault("TESTDEFAULT");

    Assert.assertEquals("TestDataSource", resolver.getValue());
    Assert.assertEquals("TestDataSource", resolver.getValue());
    Assert.assertEquals("dataSource", resolver.getKey());
    Assert.assertEquals("TESTDEFAULT", resolver.getDefaultValue());
    Assert.assertEquals("dataSource.mysql.UnitTest", resolver.getResolvedKey());

    // because the clock steps in certain OS is only 16ms
    Thread.sleep(35L);
    Assert.assertEquals("TestDataSource", resolver.getValue());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:TypedResolverTest.java


示例13: testGetProjectStageAwarePropertyValue

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testGetProjectStageAwarePropertyValue()
{
    ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
    Assert.assertNull(ConfigResolver.getProjectStageAwarePropertyValue("notexisting", null));

    Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey"));
    Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey"));
    Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey", null));

    Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey2"));
    Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2"));
    Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2", null));

    Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3"));
    Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3"));
    Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("testkey3", DEFAULT_VALUE));

    Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback", DEFAULT_VALUE));
    Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback"));

    Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withDefault(DEFAULT_VALUE).withCurrentProjectStage(true).getValue());
    Assert.assertEquals("", ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withCurrentProjectStage(true).getValue());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:25,代码来源:ConfigResolverTest.java


示例14: testConfigFilter

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testConfigFilter()
{
    ConfigFilter configFilter = new TestConfigFilter();

    Assert.assertEquals("shouldGetDecrypted: value", configFilter.filterValue("somekey.encrypted", "value"));
    Assert.assertEquals("**********", configFilter.filterValueForLog("somekey.password", "value"));

    ConfigResolver.addConfigFilter(configFilter);

    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyValue("testkey4.encrypted"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted", null));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor"));
    Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor", null));

    List<String> allPropertyValues = ConfigResolver.getAllPropertyValues("testkey4.encrypted");
    Assert.assertNotNull(allPropertyValues);
    Assert.assertEquals(1, allPropertyValues.size());
    Assert.assertEquals("shouldGetDecrypted: value", allPropertyValues.get(0));

}
 
开发者ID:apache,项目名称:deltaspike,代码行数:23,代码来源:ConfigResolverTest.java


示例15: testTypedResolver_NonExistingValue

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testTypedResolver_NonExistingValue()
{
    final String key = "non.existing.key";

    ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve(key)
        .logChanges(true);

    Assert.assertNull(resolver.getValue());

    setTestConfigSourceValue(key, "somevalue");
    Assert.assertEquals("somevalue", resolver.getValue());

    setTestConfigSourceValue(key, null);
    Assert.assertNull(resolver.getValue());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:ConfigResolverTest.java


示例16: setTestConfigSourceValue

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private void setTestConfigSourceValue(String key, String value)
{
    ConfigSource[] configSources = ConfigResolver.getConfigSources();
    for (ConfigSource configSource : configSources)
    {
        if (configSource instanceof TestConfigSource)
        {
            if (value == null)
            {
                configSource.getProperties().remove(key);
            }
            else
            {
                configSource.getProperties().put(key, value);
            }

            break;
        }
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:21,代码来源:ConfigResolverTest.java


示例17: isActivated

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Override
public Boolean isActivated(Class<? extends Deactivatable> targetClass)
{
    final String key = KEY_PREFIX + targetClass.getName();
    final String value = ConfigResolver.getPropertyValue(key);
    if (value == null)
    {
        return null;
    }
    else
    {
        if (LOG.isLoggable(Level.FINE))
        {
            LOG.log(Level.FINE, "Deactivation setting for {0} found to be {1} based on configuration.",
                    new Object[]{key, value});
        }
        return !Boolean.valueOf(value);
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:DefaultClassDeactivator.java


示例18: getDescription

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private String getDescription(final String description, String defaultDescription)
{
    if (description.isEmpty())
    {
        return defaultDescription;
    }

    String descriptionValue = description.trim();

    if (descriptionValue.startsWith("{") && descriptionValue.endsWith("}"))
    {
        return ConfigResolver.getPropertyValue(
            descriptionValue.substring(1, descriptionValue.length() - 1), defaultDescription);
    }
    return description;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:DynamicMBeanWrapper.java


示例19: getConfigSourcesAsString

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Override
public String[] getConfigSourcesAsString()
{
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try
    {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);

        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        List<String> configSourceInfo = new ArrayList<String>();
        for (ConfigSource configSource : configSources)
        {
            configSourceInfo.add(Integer.toString(configSource.getOrdinal())
                + " - " + configSource.getConfigName());
        }

        return configSourceInfo.toArray(new String[configSourceInfo.size()]);
    }
    finally
    {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }

}
 
开发者ID:apache,项目名称:deltaspike,代码行数:26,代码来源:DeltaSpikeConfigInfo.java


示例20: calculateConfigEntries

import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private List<ConfigEntry> calculateConfigEntries()
{
    Map<String, String> allProperties = ConfigResolver.getAllProperties();
    List<ConfigEntry> configEntries = new ArrayList<ConfigEntry>(allProperties.size());
    ConfigSource[] configSources = ConfigResolver.getConfigSources();

    for (Map.Entry<String, String> configEntry : allProperties.entrySet())
    {
        String key = configEntry.getKey();
        String value = ConfigResolver.filterConfigValueForLog(key,
                                ConfigResolver.getProjectStageAwarePropertyValue(key));

        String fromConfigSource = getFromConfigSource(configSources, key);
        configEntries.add(new ConfigEntry(key, value, fromConfigSource));
    }

    return configEntries;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:19,代码来源:DeltaSpikeConfigInfo.java



注:本文中的org.apache.deltaspike.core.api.config.ConfigResolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Smeltery类代码示例发布时间:2022-05-22
下一篇:
Java NotFoundException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap